mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
Adding tag option to action (#1142)
* 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
This commit is contained in:
parent
e8f5095e8b
commit
079ec0e130
@ -128,7 +128,8 @@ run({
|
|||||||
folder: 'build',
|
folder: 'build',
|
||||||
repositoryName: 'JamesIves/github-pages-deploy-action',
|
repositoryName: 'JamesIves/github-pages-deploy-action',
|
||||||
silent: true,
|
silent: true,
|
||||||
workspace: 'src/project/location'
|
workspace: 'src/project/location',
|
||||||
|
tag: 'v0.1'
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -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** |
|
| `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** |
|
| `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** |
|
| `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.
|
With the action correctly configured you should see the workflow trigger the deployment under the configured conditions.
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -58,6 +58,8 @@ export interface ActionInterface {
|
|||||||
tokenType?: string
|
tokenType?: string
|
||||||
/** The folder where your deployment project lives. */
|
/** The folder where your deployment project lives. */
|
||||||
workspace: string
|
workspace: string
|
||||||
|
/** GitHub tag name */
|
||||||
|
tag?: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The minimum required values to run the action as a node module. */
|
/** The minimum required values to run the action as a node module. */
|
||||||
@ -138,7 +140,8 @@ export const action: ActionInterface = {
|
|||||||
? true
|
? true
|
||||||
: getInput('ssh-key'),
|
: getInput('ssh-key'),
|
||||||
targetFolder: getInput('target-folder'),
|
targetFolder: getInput('target-folder'),
|
||||||
workspace: process.env.GITHUB_WORKSPACE || ''
|
workspace: process.env.GITHUB_WORKSPACE || '',
|
||||||
|
tag: getInput('tag')
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Types for the required action parameters. */
|
/** Types for the required action parameters. */
|
||||||
|
19
src/git.ts
19
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 {mkdirP, rmRF} from '@actions/io'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import {
|
import {
|
||||||
@ -316,6 +316,23 @@ export async function deploy(action: ActionInterface): Promise<Status> {
|
|||||||
|
|
||||||
info(`Changes committed to the ${action.branch} branch… 📦`)
|
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
|
return Status.SUCCESS
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
Loading…
Reference in New Issue
Block a user