From b7231cf3fe89babd4f8729162c75625166378be3 Mon Sep 17 00:00:00 2001 From: German Date: Thu, 16 Jun 2022 08:21:16 +0200 Subject: [PATCH 1/8] Adding tag option to action --- src/constants.ts | 12 +++++++++++- src/git.ts | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/constants.ts b/src/constants.ts index 6505b7781..269c04ea6 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -58,6 +58,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. */ @@ -78,6 +84,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. */ @@ -138,7 +146,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. */ diff --git a/src/git.ts b/src/git.ts index 1bf788bd7..fd819dd27 100644 --- a/src/git.ts +++ b/src/git.ts @@ -316,6 +316,21 @@ export async function deploy(action: ActionInterface): Promise { info(`Changes committed to the ${action.branch} branch… 📦`) + if (action.add_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 remote.`) + await execute( + `git push origin ${action.tag}`, + `${action.workspace}/${temporaryDeploymentDirectory}`, + action.silent + ) + } + return Status.SUCCESS } catch (error) { throw new Error( From b2965541196e85bfcc3c99f309de6909ad0d74e8 Mon Sep 17 00:00:00 2001 From: German Date: Thu, 16 Jun 2022 08:38:21 +0200 Subject: [PATCH 2/8] Avoiding adding tag if the remote name is not used. --- src/constants.ts | 5 ++++- src/git.ts | 12 ++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 269c04ea6..ebc2cf42c 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -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. */ @@ -126,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 diff --git a/src/git.ts b/src/git.ts index fd819dd27..f5f4df17b 100644 --- a/src/git.ts +++ b/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 { @@ -316,7 +316,13 @@ export async function deploy(action: ActionInterface): Promise { info(`Changes committed to the ${action.branch} branch… 📦`) - if (action.add_tag) { + 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}`, @@ -329,6 +335,8 @@ export async function deploy(action: ActionInterface): Promise { `${action.workspace}/${temporaryDeploymentDirectory}`, action.silent ) + + info(`Tag '${action.tag}' created and pushed to the ${action.branch} branch… 📦`) } return Status.SUCCESS From 5cf773f0010adc13c31cc8bb76177310f718f5dc Mon Sep 17 00:00:00 2001 From: German Date: Thu, 16 Jun 2022 08:56:15 +0200 Subject: [PATCH 3/8] Adding unit tests --- __tests__/git.test.ts | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/__tests__/git.test.ts b/__tests__/git.test.ts index 8d566b06b..172d1f150 100644 --- a/__tests__/git.test.ts +++ b/__tests__/git.test.ts @@ -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) + }) }) }) From f75be293bacc4f6090d2039d9da0eb387ee44d03 Mon Sep 17 00:00:00 2001 From: German Date: Thu, 16 Jun 2022 09:00:47 +0200 Subject: [PATCH 4/8] Update readme. --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 33cc9215c..9bd25611d 100644 --- a/README.md +++ b/README.md @@ -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' }) ``` @@ -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. |`with` | **No** | With the action correctly configured you should see the workflow trigger the deployment under the configured conditions. From ddb15a553417cf6b188af41f8803c8ad6c2a9d1d Mon Sep 17 00:00:00 2001 From: German Date: Thu, 16 Jun 2022 09:02:12 +0200 Subject: [PATCH 5/8] Update readme part 2 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9bd25611d..44e68fe2e 100644 --- a/README.md +++ b/README.md @@ -173,7 +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. |`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. From dd249b748c82d2ad44e73aa0338da1d8a3035e0c Mon Sep 17 00:00:00 2001 From: German Date: Wed, 29 Jun 2022 12:35:51 +0200 Subject: [PATCH 6/8] Adding changes from the code review --- README.md | 2 +- __tests__/git.test.ts | 19 ------------------- src/constants.ts | 2 -- src/git.ts | 10 ++-------- 4 files changed, 3 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 44e68fe2e..40db07072 100644 --- a/README.md +++ b/README.md @@ -173,7 +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** | +| `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. diff --git a/__tests__/git.test.ts b/__tests__/git.test.ts index 172d1f150..5b64456a7 100644 --- a/__tests__/git.test.ts +++ b/__tests__/git.test.ts @@ -471,24 +471,5 @@ describe('git', () => { 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) - }) }) }) diff --git a/src/constants.ts b/src/constants.ts index ebc2cf42c..d6684ffb7 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -129,7 +129,6 @@ export const action: ActionInterface = { : process.env.GITHUB_ACTOR ? process.env.GITHUB_ACTOR : 'GitHub Pages Deploy Action', - externalRepositoryTarget: !isNullOrUndefined(getInput('repository-name')), repositoryName: !isNullOrUndefined(getInput('repository-name')) ? getInput('repository-name') : repository && repository.full_name @@ -150,7 +149,6 @@ export const action: ActionInterface = { : getInput('ssh-key'), targetFolder: getInput('target-folder'), workspace: process.env.GITHUB_WORKSPACE || '', - add_tag: !isNullOrUndefined(getInput('tag')), tag: getInput('tag') } diff --git a/src/git.ts b/src/git.ts index f5f4df17b..3d23ff3ca 100644 --- a/src/git.ts +++ b/src/git.ts @@ -316,20 +316,14 @@ export async function deploy(action: ActionInterface): Promise { 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) { + 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 remote.`) + info(`Pushing tag '${action.tag}' to repository.`) await execute( `git push origin ${action.tag}`, `${action.workspace}/${temporaryDeploymentDirectory}`, From 15bdc1645b563879e7bffb50bbbb7437218783a9 Mon Sep 17 00:00:00 2001 From: German Date: Wed, 29 Jun 2022 12:37:44 +0200 Subject: [PATCH 7/8] removing references to deleted parameters --- src/constants.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index d6684ffb7..47c2c078d 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -44,8 +44,6 @@ 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. */ @@ -60,10 +58,6 @@ 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 } @@ -86,8 +80,6 @@ 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. */ From 4771e730ec98649370cd2e33b0badbea5290dd9d Mon Sep 17 00:00:00 2001 From: German Date: Wed, 29 Jun 2022 12:38:56 +0200 Subject: [PATCH 8/8] removing space --- src/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constants.ts b/src/constants.ts index 47c2c078d..a6984735a 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -120,7 +120,7 @@ export const action: ActionInterface = { ? pusher.name : process.env.GITHUB_ACTOR ? process.env.GITHUB_ACTOR - : 'GitHub Pages Deploy Action', + : 'GitHub Pages Deploy Action', repositoryName: !isNullOrUndefined(getInput('repository-name')) ? getInput('repository-name') : repository && repository.full_name