Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding tag option to action #1142

Merged
merged 8 commits into from Jul 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
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 `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
22 changes: 22 additions & 0 deletions __tests__/git.test.ts
Expand Up @@ -449,5 +449,27 @@ 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)
})

})
})
5 changes: 4 additions & 1 deletion src/constants.ts
Expand Up @@ -58,6 +58,8 @@ export interface ActionInterface {
tokenType?: string
/** The folder where your deployment project lives. */
workspace: string
/** GitHub tag name */
tag?: string | null
}

/** The minimum required values to run the action as a node module. */
Expand Down Expand Up @@ -138,7 +140,8 @@ export const action: ActionInterface = {
? true
: getInput('ssh-key'),
targetFolder: getInput('target-folder'),
workspace: process.env.GITHUB_WORKSPACE || ''
workspace: process.env.GITHUB_WORKSPACE || '',
tag: getInput('tag')
}

/** Types for the required action parameters. */
Expand Down
19 changes: 18 additions & 1 deletion src/git.ts
@@ -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,23 @@ export async function deploy(action: ActionInterface): Promise<Status> {

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

if (action.tag) {
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 repository.`)
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