Skip to content

Commit

Permalink
Merge pull request #76 from issue-ops/push-tags
Browse files Browse the repository at this point in the history
Add push-tags option
  • Loading branch information
ncalteen authored Aug 20, 2024
2 parents d1d42cc + f48e095 commit a5b978f
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 35 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ jobs:
| | If not set, `use-version` must be set. |
| `overwrite` | Set to `'true'` to overwrite existing tags. |
| | Default: `'false'` |
| `push-tags` | Set to `'true'` to push tags to the repository. |
| | Default: `'true'` |
| `ref` | The Git ref to tag. |
| | Defaults to the base ref of a pull request trigger. |
| `use-version` | The version you want to explicitly use. |
Expand Down
20 changes: 14 additions & 6 deletions __tests__/version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ describe('version.ts', () => {
)

const version = new Version('1.2.3-alpha.4+build.5')
await version.tag('main', `${__dirname}/fixtures/valid`)
await version.tag('main', `${__dirname}/fixtures/valid`, true)

expect(exec.exec).toHaveBeenCalledWith(
'git tag -d "v1.2.3-alpha.4+build.5"',
Expand Down Expand Up @@ -378,7 +378,9 @@ describe('version.ts', () => {

const version = new Version('1.2.3-alpha.4')
try {
expect(await version.tag('main', `${__dirname}/fixtures/valid`)).toThrow()
expect(
await version.tag('main', `${__dirname}/fixtures/valid`, true)
).toThrow()
} catch (error) {
// Do nothing
}
Expand Down Expand Up @@ -410,7 +412,9 @@ describe('version.ts', () => {

const version = new Version('1.2.3-alpha.4')
try {
expect(await version.tag('main', `${__dirname}/fixtures/valid`)).toThrow()
expect(
await version.tag('main', `${__dirname}/fixtures/valid`, true)
).toThrow()
} catch (error) {
// Do nothing
}
Expand Down Expand Up @@ -450,7 +454,9 @@ describe('version.ts', () => {

const version = new Version('1.2.3-alpha.4')
try {
expect(await version.tag('main', `${__dirname}/fixtures/valid`)).toThrow()
expect(
await version.tag('main', `${__dirname}/fixtures/valid`, true)
).toThrow()
} catch (error) {
// Do nothing
}
Expand Down Expand Up @@ -494,7 +500,9 @@ describe('version.ts', () => {

const version = new Version('1.2.3-alpha.4')
try {
expect(await version.tag('main', `${__dirname}/fixtures/valid`)).toThrow()
expect(
await version.tag('main', `${__dirname}/fixtures/valid`, true)
).toThrow()
} catch (error) {
// Do nothing
}
Expand Down Expand Up @@ -612,7 +620,7 @@ describe('version.ts', () => {
)

const version = new Version('1.2.3+build.5')
await version.tag('main', `${__dirname}/fixtures/valid`)
await version.tag('main', `${__dirname}/fixtures/valid`, true)

expect(exec.exec).toHaveBeenCalledWith(
'git tag -d "v1.2.3+build.5"',
Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ inputs:
If tags already exist for the specified or inferred version, setting this
to 'true' will overwrite them. Defaults to 'false'.
required: false
push-tags:
default: 'true'
description:
If set to 'true', the action will push the tag to the repository. Defaults
to 'true'.
required: false
ref:
default: ${{ github.base_ref }}
description:
Expand Down
28 changes: 16 additions & 12 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion dist/version.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "issue-ops-semver",
"description": "Semantically version GitHub repository tags",
"version": "2.0.0",
"version": "2.1.0",
"type": "module",
"author": "Nick Alteen <[email protected]>",
"homepage": "https://github.com/issue-ops/semver#readme",
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export async function run() {
const ref: string = core.getInput('ref')
const useVersion: string = core.getInput('use-version')
const workspace: string = core.getInput('workspace')
const push: boolean = core.getInput('push') === 'true'

if (
(manifestPath === '' && useVersion === '') ||
Expand Down Expand Up @@ -47,7 +48,7 @@ export async function run() {
// If not running in checkOnly mode, tag and push the version in the
// workspace. Otherwise, just output the version information.
/* istanbul ignore next */
if (!checkOnly) await version.tag(ref, workspace)
if (!checkOnly) await version.tag(ref, workspace, push)
else core.info("Version does not exist and 'check-only' is true")

// Output the various version formats
Expand Down
25 changes: 14 additions & 11 deletions src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,9 @@ export class Version {
*
* @param ref The ref to tag
* @param workspace The project workspace
* @param push Whether or not to push the tags to the remote
*/
async tag(ref: string, workspace: string): Promise<void> {
async tag(ref: string, workspace: string, push: boolean): Promise<void> {
const tagOptions: TagOptions = new TagOptions(workspace)
const tags: string[] = []

Expand Down Expand Up @@ -251,19 +252,21 @@ export class Version {
if (tagOptions.stderr !== '') throw new Error(tagOptions.stderr)
}

// Push the tag(s)
core.info(`Pushing tag(s): ${JSON.stringify(tags)}`)
tagOptions.reset()
if (push) {
// Push the tag(s)
core.info(`Pushing tag(s): ${JSON.stringify(tags)}`)
tagOptions.reset()

await exec('git push origin --tags', [], tagOptions.options)
await exec('git push origin --tags', [], tagOptions.options)

core.debug(`STDOUT: ${tagOptions.stdout}`)
core.debug(`STDERR: ${tagOptions.stderr}`)
core.debug(`STDOUT: ${tagOptions.stdout}`)
core.debug(`STDERR: ${tagOptions.stderr}`)

// Git writes to stderr when tags are pushed successfully
// Ignore stderr if the tag was pushed
if (tagOptions.stderr.includes('[new tag]') === false)
throw new Error(tagOptions.stderr)
// Git writes to stderr when tags are pushed successfully
// Ignore stderr if the tag was pushed
if (tagOptions.stderr.includes('[new tag]') === false)
throw new Error(tagOptions.stderr)
}

core.info('Tagging complete')
}
Expand Down

0 comments on commit a5b978f

Please sign in to comment.