Skip to content

Commit

Permalink
Adding tag option to action (#1142)
Browse files Browse the repository at this point in the history
* Adding tag option to action

* Avoiding adding tag if the remote name is not used.

* Adding unit tests

* Update readme.

* Update readme part 2

* Adding changes from the code review

* removing references to deleted parameters

* removing space
  • Loading branch information
germa89 committed Jul 17, 2022
1 parent e8f5095 commit 079ec0e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -128,7 +128,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 @@ -170,6 +171,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

0 comments on commit 079ec0e

Please sign in to comment.