Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ run({
folder: 'build',
repositoryName: 'JamesIves/github-pages-deploy-action',
silent: true,
workspace: 'src/project/location'
workspace: 'src/project/location',
tag: 'v0.1'
})
```

Expand Down Expand Up @@ -172,6 +173,7 @@ By default, the action does not need any token configuration and uses the provid
| `force` | Force-push new deployments to overwrite the previous version; otherwise, attempt to rebase new deployments onto any existing ones. This option is turned on by default and can be toggled off by setting it to `false`, which may be useful if there are multiple deployments in a single branch. | `with` | **No** |
| `silent` | Silences the action output preventing it from displaying git messages. | `with` | **No** |
| `workspace` | This should point to where your project lives on the virtual machine. The GitHub Actions environment will set this for you. It is only necessary to set this variable if you're using the node module. | `with` | **No** |
| `tag` | Add a tag to the commit. Only works when `repository-name` is specified and `dry-run` is not used. | `with` | **No** |

With the action correctly configured you should see the workflow trigger the deployment under the configured conditions.

Expand Down
41 changes: 41 additions & 0 deletions __tests__/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,5 +449,46 @@ describe('git', () => {
)
}
})

it('should add a tag to the commit', async () => {
Object.assign(action, {
hostname: 'github.com',
silent: false,
folder: 'assets',
branch: 'branch',
token: '123',
repositoryName: 'JamesIves/montezuma',
tag: 'v0.1',
pusher: {
name: 'asd',
email: 'as@cat'
},
isTest: TestFlag.NONE
})

const response = await deploy(action)
expect(execute).toBeCalledTimes(13) // normally 11 runs, +2 of the tag
expect(response).toBe(Status.SUCCESS)
})

it('should do nothing because repository name is not specified.', async () => {
Object.assign(action, {
hostname: 'github.com',
silent: false,
folder: 'assets',
branch: 'branch',
token: '123',
tag: 'v0.1',
pusher: {
name: 'asd',
email: 'as@cat'
},
isTest: TestFlag.NONE
})

const response = await deploy(action)
expect(execute).toBeCalledTimes(11)
expect(response).toBe(Status.SUCCESS)
})
})
})
17 changes: 15 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export interface ActionInterface {
repositoryName?: string
/** The fully qualified repositpory path, this gets auto generated if repositoryName is provided. */
repositoryPath?: string
/** External repository boolean */
externalRepositoryTarget?:boolean | null
/** Wipes the commit history from the deployment branch in favor of a single commit. */
singleCommit?: boolean | null
/** Determines if the action should run in silent mode or not. */
Expand All @@ -58,6 +60,12 @@ export interface ActionInterface {
tokenType?: string
/** The folder where your deployment project lives. */
workspace: string
/** Github tag boolean
* This value is not directly an input, and it is obtained from checking that 'tag' is not null or undefined.
*/
add_tag: boolean
/** GitHub tag name */
tag?: string | null
}

/** The minimum required values to run the action as a node module. */
Expand All @@ -78,6 +86,8 @@ export interface NodeActionInterface {
workspace: string
/** Determines test scenarios the action is running in. */
isTest: TestFlag
/** Defines if a tag is added or not. */
add_tag: boolean
}

/* Required action data that gets initialized when running within the GitHub Actions environment. */
Expand Down Expand Up @@ -118,7 +128,8 @@ export const action: ActionInterface = {
? pusher.name
: process.env.GITHUB_ACTOR
? process.env.GITHUB_ACTOR
: 'GitHub Pages Deploy Action',
: 'GitHub Pages Deploy Action',
externalRepositoryTarget: !isNullOrUndefined(getInput('repository-name')),
repositoryName: !isNullOrUndefined(getInput('repository-name'))
? getInput('repository-name')
: repository && repository.full_name
Expand All @@ -138,7 +149,9 @@ export const action: ActionInterface = {
? true
: getInput('ssh-key'),
targetFolder: getInput('target-folder'),
workspace: process.env.GITHUB_WORKSPACE || ''
workspace: process.env.GITHUB_WORKSPACE || '',
add_tag: !isNullOrUndefined(getInput('tag')),
tag: getInput('tag')
}

/** Types for the required action parameters. */
Expand Down
25 changes: 24 additions & 1 deletion src/git.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {info} from '@actions/core'
import { info, warning } from '@actions/core'
import {mkdirP, rmRF} from '@actions/io'
import fs from 'fs'
import {
Expand Down Expand Up @@ -316,6 +316,29 @@ export async function deploy(action: ActionInterface): Promise<Status> {

info(`Changes committed to the ${action.branch} branch… 📦`)

if (action.add_tag && !action.externalRepositoryTarget) {
warning(
`Using 'tag' when the target repository is not external (no 'repositoryName' variable) makes no effect❗`
)
}

if (action.add_tag && action.externalRepositoryTarget) {
info(`Adding a tag '${action.tag}' to the commit`)
await execute(
`git tag ${action.tag}`,
`${action.workspace}/${temporaryDeploymentDirectory}`,
action.silent
)
info(`Pushing tag '${action.tag}' to remote.`)
await execute(
`git push origin ${action.tag}`,
`${action.workspace}/${temporaryDeploymentDirectory}`,
action.silent
)

info(`Tag '${action.tag}' created and pushed to the ${action.branch} branch… 📦`)
}

return Status.SUCCESS
} catch (error) {
throw new Error(
Expand Down