diff --git a/.prettierignore b/.prettierignore index 1b07c39e..084c93c9 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,3 +1,4 @@ # Ignore artifacts: build -coverage \ No newline at end of file +coverage +lib \ No newline at end of file diff --git a/README.md b/README.md index d5b19ce9..129fed9b 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@

-Chooksta69  robjtede  hadley  kevinchalet  Yousazoe   +Chooksta69  robjtede  hadley  kevinchalet  

## Getting Started :airplane: @@ -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' }) ``` @@ -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. diff --git a/__tests__/git.test.ts b/__tests__/git.test.ts index 8d566b06..3905cc94 100644 --- a/__tests__/git.test.ts +++ b/__tests__/git.test.ts @@ -449,5 +449,26 @@ 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.HAS_CHANGED_FILES + }) + + const response = await deploy(action) + expect(execute).toBeCalledTimes(16) + expect(response).toBe(Status.SUCCESS) + }) }) }) diff --git a/action.yml b/action.yml index f508021d..5b1cc054 100644 --- a/action.yml +++ b/action.yml @@ -82,6 +82,10 @@ inputs: description: "This should point to where your project lives on the virtual machine. The GitHub Actions environment will set this for you. It is only neccersary to set this variable if you're using the node module." required: false + tag: + description: "Add a tag to the commit, this can be used like so: 'v0.1'. Only works when 'dry-run' is not used." + required: false + single-commit: description: "This option can be used if you'd prefer to have a single commit on the deployment branch instead of maintaining the full history." required: false diff --git a/package.json b/package.json index ad5e4114..11e42a0a 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@jamesives/github-pages-deploy-action", "description": "GitHub action for building a project and deploying it to GitHub pages.", "author": "James Ives (https://jamesiv.es)", - "version": "4.3.3", + "version": "4.3.4", "license": "MIT", "main": "lib/lib.js", "types": "lib/lib.d.ts", @@ -42,13 +42,13 @@ }, "devDependencies": { "@types/jest": "27.5.0", - "@types/node": "18.0.0", + "@types/node": "18.0.6", "@typescript-eslint/eslint-plugin": "4.33.0", "@typescript-eslint/parser": "4.33.0", "eslint": "7.32.0", "eslint-config-prettier": "8.5.0", "eslint-plugin-jest": "26.5.3", - "eslint-plugin-prettier": "4.0.0", + "eslint-plugin-prettier": "4.2.1", "jest": "26.6.3", "jest-circus": "27.5.1", "prettier": "2.7.1", diff --git a/src/constants.ts b/src/constants.ts index e0ce8075..85c83122 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -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. */ @@ -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. */ diff --git a/src/git.ts b/src/git.ts index 1bf788bd..52ba6ed8 100644 --- a/src/git.ts +++ b/src/git.ts @@ -308,14 +308,34 @@ export async function deploy(action: ActionInterface): Promise { if (rejected) info('Updates were rejected') - // If the push failed for any reason other than being rejected, + // If the push failed for any fatal reason other than being rejected, // there is a problem - if (!rejected && pushResult.stderr) throw new Error(pushResult.stderr) + if (!rejected && pushResult.stderr.trim().startsWith('fatal:')) + throw new Error(pushResult.stderr) } while (rejected) } info(`Changes committed to the ${action.branch} branch… 📦`) + if (action.tag) { + info(`Adding '${action.tag}' tag to the commit…`) + await execute( + `git tag ${action.tag}`, + `${action.workspace}/${temporaryDeploymentDirectory}`, + action.silent + ) + info(`Pushing '${action.tag}' 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( diff --git a/yarn.lock b/yarn.lock index 524e799d..77e8c980 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1276,10 +1276,10 @@ resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.9.tgz#97edc9037ea0c38585320b28964dde3b39e4660d" integrity sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ== -"@types/node@*", "@types/node@18.0.0", "@types/node@>= 8": - version "18.0.0" - resolved "https://registry.yarnpkg.com/@types/node/-/node-18.0.0.tgz#67c7b724e1bcdd7a8821ce0d5ee184d3b4dd525a" - integrity sha512-cHlGmko4gWLVI27cGJntjs/Sj8th9aYwplmZFwmmgYQQvL5NUsgVJG7OddLvNfLqYS31KFN0s3qlaD9qCaxACA== +"@types/node@*", "@types/node@18.0.6", "@types/node@>= 8": + version "18.0.6" + resolved "https://registry.yarnpkg.com/@types/node/-/node-18.0.6.tgz#0ba49ac517ad69abe7a1508bc9b3a5483df9d5d7" + integrity sha512-/xUq6H2aQm261exT6iZTMifUySEt4GR5KX8eYyY+C4MSNPqSh9oNIP7tz2GLKTlFaiBbgZNxffoR3CVRG+cljw== "@types/normalize-package-data@^2.4.0": version "2.4.0" @@ -2152,10 +2152,10 @@ eslint-plugin-jest@26.5.3: dependencies: "@typescript-eslint/utils" "^5.10.0" -eslint-plugin-prettier@4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-4.0.0.tgz#8b99d1e4b8b24a762472b4567992023619cb98e0" - integrity sha512-98MqmCJ7vJodoQK359bqQWaxOE0CS8paAz/GgjaZLyex4TTk3g9HugoO89EqWCrFiOqn9EVvcoo7gZzONCWVwQ== +eslint-plugin-prettier@4.2.1: + version "4.2.1" + resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-4.2.1.tgz#651cbb88b1dab98bfd42f017a12fa6b2d993f94b" + integrity sha512-f/0rXLXUt0oFYs8ra4w49wYZBG5GKZpAYsJSm6rnYL5uVDjd+zowwMwVZHnAjf4edNrKpCDYfXDgmRE/Ak7QyQ== dependencies: prettier-linter-helpers "^1.0.0"