From 33b2b26e4cd9854fb721a0afe069951d47bc3b67 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Thu, 12 Sep 2019 17:43:51 -0500 Subject: [PATCH 01/18] Update main.js --- lib/main.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index f7ca378..6a33c9e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -45,7 +45,9 @@ async function run() { per_page: 100 }) } catch (e) { - tags = {} + tags = { + data: [] + } } // Check for existance of tag and abort (short circuit) if it already exists. From 96dacb6ce3be393557d67af86af1bc3d90513e53 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 18 Sep 2019 17:48:16 -0500 Subject: [PATCH 02/18] Update main.js --- lib/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 6a33c9e..a9cae47 100644 --- a/lib/main.js +++ b/lib/main.js @@ -80,8 +80,8 @@ async function run() { tagMsg = changelog.data.commits.map(commit => `**1) ${commit.commit.message}**${commit.hasOwnProperty('author') ? (commit.author.hasOwnProperty('login') ? ' (' + commit.author.login + ')' : '') : ''}\n(SHA: ${commit.sha})\n`).join('\n') } catch (e) { - core.setFailed(e.message) - return + core.warning('Failed to generate changelog from commits: ' + e.message) + tagMsg = `${tagPrefix}${tagName}${tagSuffix}` } } From d8d7a1a53dd41415f15deded164d37e5e411b670 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Thu, 19 Sep 2019 12:49:09 -0500 Subject: [PATCH 03/18] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6026da9..275045d 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@master - - uses: butlerlogic/action-autotag@1.0.0 + - uses: butlerlogic/action-autotag@stable with: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" ``` From c8129b91ae75496d6e3bb7ece6a39ba9ceda3ebd Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Thu, 19 Sep 2019 12:53:54 -0500 Subject: [PATCH 04/18] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 275045d..3bd43f5 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ There are several options to customize how the tag is created. 1. `package_root` - By default, autotag will look for the `package.json` file in the project root. If the file is located in a subdirectory, this option an be used to point to the correct file. + By default, autotag will look for the `package.json` file in the project root. If the file is located in a subdirectory, this option can be used to point to the correct file. ```yaml - uses: butlerlogic/action-autotag@1.0.0 @@ -87,7 +87,7 @@ There are several options to customize how the tag is created. 1. `tag_message` This is the annotated commit message associated with the tag. By default, a - changelog will be generated from the commits between the latest tag and the new tag (HEAD). This will override that with a hard-coded message. + changelog will be generated from the commits between the latest tag and the new tag (HEAD). Setting this option will override it witha custom message. ```yaml - uses: butlerlogic/action-autotag@1.0.0 From 38fe2a342899c2d038f9cae81b1625c52162ce8b Mon Sep 17 00:00:00 2001 From: Mathias Beugnon Date: Tue, 22 Oct 2019 13:40:28 +0100 Subject: [PATCH 05/18] Fix owner --- action.yml | 4 +-- lib/main.js | 92 +++++++++++++++++++++++++++++------------------------ 2 files changed, 52 insertions(+), 44 deletions(-) diff --git a/action.yml b/action.yml index 1e02d11..384c88e 100644 --- a/action.yml +++ b/action.yml @@ -2,14 +2,14 @@ name: 'Autotagger' description: 'Automatically generate new tags when the package.json version changes.' author: 'ButlerLogic' branding: - icon: 'tag' + icon: 'tag' color: 'black' inputs: package_root: description: Autotag will look for the package.json file in in this location. required: false default: './' - tag_prefx: + tag_prefix: description: By default, package.json uses semantic versioning, such as "1.0.0". A prefix can be used to add text before the tag name. For example, if tag_prefx is set to "v", then the tag would be labeled as "v1.0.0". required: false tag_suffix: diff --git a/lib/main.js b/lib/main.js index a9cae47..69da26f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -1,4 +1,3 @@ -// import * as core from '@actions/core'; const github = require('@actions/github') const core = require('@actions/core') const fs = require('fs') @@ -6,24 +5,31 @@ const path = require('path') async function run() { try { - core.debug(` Available environment variables:\n -> ${Object.keys(process.env).map(i => i + ' :: ' + process.env[i]).join('\n -> ')}`) + const { repo } = github.context - let dir = fs.readdirSync(path.resolve(process.env.GITHUB_WORKSPACE), { withFileTypes: true }).map(entry => { - return `${entry.isDirectory() ? '> ' : ' - '}${entry.name}` - }).join('\n') + core.debug( + ` Available environment variables:\n -> ${Object.keys(process.env) + .map(i => i + ' :: ' + process.env[i]) + .join('\n -> ')}` + ) + + const dir = fs + .readdirSync(path.resolve(process.env.GITHUB_WORKSPACE), { withFileTypes: true }) + .map(entry => { + return `${entry.isDirectory() ? '> ' : ' - '}${entry.name}` + }) + .join('\n') core.debug(` Working Directory: ${process.env.GITHUB_WORKSPACE}:\n${dir}`) - - const pkg_root = core.getInput('package_root', { required: false }) - let pkgfile = path.join(process.env.GITHUB_WORKSPACE, pkg_root, 'package.json') + const pkg_root = core.getInput('package_root', { required: false }) + const pkgfile = path.join(process.env.GITHUB_WORKSPACE, pkg_root, 'package.json') if (!fs.existsSync(pkgfile)) { core.setFailed('package.json does not exist.') return } - let pkg = require(pkgfile) - + const pkg = require(pkgfile) core.setOutput('version', pkg.version) core.debug(` Detected version ${pkg.version}`) @@ -34,25 +40,28 @@ async function run() { // Check for existing tag const git = new github.GitHub(process.env.INPUT_GITHUB_TOKEN) - const owner = process.env.GITHUB_ACTOR - const repo = process.env.GITHUB_REPOSITORY.split('/').pop() let tags try { tags = await git.repos.listTags({ - owner, - repo, - per_page: 100 + ...repo, + per_page: 100, }) } catch (e) { tags = { - data: [] + data: [], } } + const getTagName = version => { + const tagPrefix = core.getInput('tag_prefix', { required: false }) + const tagSuffix = core.getInput('tag_suffix', { required: false }) + return `${tagPrefix}${version}${tagSuffix}` + } + // Check for existance of tag and abort (short circuit) if it already exists. for (let tag of tags.data) { - if (tag.name.trim().toLowerCase() === pkg.version.trim().toLowerCase()) { + if (tag.name === getTagName(pkg.version)) { core.warning(`"${tag.name.trim()}" tag already exists.`) core.setOutput('tagname', '') return @@ -60,45 +69,47 @@ async function run() { } // Create the new tag name - let tagName = pkg.version - const tagPrefix = core.getInput('tag_prefix', { required: false }) - const tagSuffix = core.getInput('tag_suffix', { required: false }) + const tagName = getTagName(pkg.version) + let tagMsg = core.getInput('tag_message', { required: false }).trim() - - tagName = `${tagPrefix}${tagName}${tagSuffix}` - if (tagMsg.length === 0 && tags.data.length > 0) { try { latestTag = tags.data.shift() let changelog = await git.repos.compareCommits({ - owner, - repo, + ...repo, base: latestTag.name, - head: 'master' + head: 'master', }) - tagMsg = changelog.data.commits.map(commit => `**1) ${commit.commit.message}**${commit.hasOwnProperty('author') ? (commit.author.hasOwnProperty('login') ? ' (' + commit.author.login + ')' : '') : ''}\n(SHA: ${commit.sha})\n`).join('\n') + tagMsg = changelog.data.commits + .map( + commit => + `**1) ${commit.commit.message}**${ + commit.hasOwnProperty('author') + ? commit.author.hasOwnProperty('login') + ? ' (' + commit.author.login + ')' + : '' + : '' + }\n(SHA: ${commit.sha})\n` + ) + .join('\n') } catch (e) { core.warning('Failed to generate changelog from commits: ' + e.message) - tagMsg = `${tagPrefix}${tagName}${tagSuffix}` + tagMsg = tagName } } let newTag - try { - tagMsg = tagMsg.trim().length > 0 - ? tagMsg - : `Version ${pkg.version}` + tagMsg = tagMsg.trim().length > 0 ? tagMsg : `Version ${pkg.version}` newTag = await git.git.createTag({ - owner, - repo, + ...repo, tag: tagName, message: tagMsg, object: process.env.GITHUB_SHA, - type: 'commit' + type: 'commit', }) core.warning(`Created new tag: ${newTag.data.tag}`) @@ -108,22 +119,19 @@ async function run() { } let newReference - try { newReference = await git.git.createRef({ - owner, - repo, + ...repo, ref: `refs/tags/${newTag.data.tag}`, - sha: newTag.data.sha + sha: newTag.data.sha, }) core.warning(`Reference ${newReference.data.ref} available at ${newReference.data.url}`) } catch (e) { core.warning({ - owner, - repo, + ...repo, ref: `refs/tags/${newTag.data.tag}`, - sha: newTag.data.sha + sha: newTag.data.sha, }) core.setFailed(e.message) From a3e489cd85ba008090c851fb79da74a81e5080e9 Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Wed, 18 Dec 2019 14:28:33 +0000 Subject: [PATCH 06/18] Enable configuration of version to bypass autodetection --- README.md | 38 +++++++++++++++++++++++++------------- action.yml | 21 ++++++++++++--------- lib/main.js | 41 ++++++++++++++++++++++++----------------- 3 files changed, 61 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 3bd43f5..2635d18 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,12 @@ This action will read a `package.json` file and compare the `version` attribute ## Usage -The following is an example `.github/main.workflow` that will execute when a `push` to the `master` branch occurs. +The following is an example `.github/main.workflow` that will execute when a `push` to the `master` branch occurs. ```yaml name: My Workflow -on: +on: push: branches: - master @@ -52,43 +52,43 @@ The action will automatically extract the token at runtime. **DO NOT MANUALLY EN There are several options to customize how the tag is created. 1. `package_root` - + By default, autotag will look for the `package.json` file in the project root. If the file is located in a subdirectory, this option can be used to point to the correct file. - + ```yaml - uses: butlerlogic/action-autotag@1.0.0 with: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" package_root: "/path/to/subdirectory" ``` - + 1. `tag_prefx` - + By default, `package.json` uses [semantic versioning](https://semver.org/), such as `1.0.0`. A prefix can be used to add text before the tag name. For example, if `tag_prefx` is set to `v`, then the tag would be labeled as `v1.0.0`. - + ```yaml - uses: butlerlogic/action-autotag@1.0.0 with: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" tag_prefx: "v" ``` - + 1. `tag_suffix` - + Text can also be applied to the end of the tag by setting `tag_suffix`. For example, if `tag_suffix` is ` (beta)`, the tag would be `1.0.0 (beta)`. Please note this example violates semantic versioning and is merely here to illustrate how to add text to the end of a tag name if you _really_ want to. - + ```yaml - uses: butlerlogic/action-autotag@1.0.0 with: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" tag_suffix: " (beta)" ``` - + 1. `tag_message` - + This is the annotated commit message associated with the tag. By default, a changelog will be generated from the commits between the latest tag and the new tag (HEAD). Setting this option will override it witha custom message. - + ```yaml - uses: butlerlogic/action-autotag@1.0.0 with: @@ -96,6 +96,18 @@ There are several options to customize how the tag is created. tag_message: "Custom message goes here." ``` +1. `version` + + Explicitly set the version instead of automatically detecting from `package.json`. + Useful for non-JavaScript projects where version may be output by a previous action. + + ```yaml + - uses: butlerlogic/action-autotag@1.0.0 + with: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + version: "${{ steps.previous_step.outputs.version }}" + ``` + ## Developer Notes If you are building an action that runs after this one, be aware this action produces several [outputs](https://help.github.com/en/articles/metadata-syntax-for-github-actions#outputs): diff --git a/action.yml b/action.yml index 1e02d11..e3d707b 100644 --- a/action.yml +++ b/action.yml @@ -1,14 +1,14 @@ -name: 'Autotagger' -description: 'Automatically generate new tags when the package.json version changes.' -author: 'ButlerLogic' +name: "Autotagger" +description: "Automatically generate new tags when the package.json version changes." +author: "ButlerLogic" branding: - icon: 'tag' - color: 'black' + icon: "tag" + color: "black" inputs: package_root: description: Autotag will look for the package.json file in in this location. required: false - default: './' + default: "./" tag_prefx: description: By default, package.json uses semantic versioning, such as "1.0.0". A prefix can be used to add text before the tag name. For example, if tag_prefx is set to "v", then the tag would be labeled as "v1.0.0". required: false @@ -18,6 +18,9 @@ inputs: tag_message: description: This is the annotated commit message associated with the tag. By default, a changelog will be generated from the commits between the latest tag and the new tag (HEAD). This will override that with a hard-coded message. required: false + version: + description: Explicitly set the version here instead of automatically detecting from `package.json`. Useful for non-JavaScript projects where version may be output by a previous action. + required: false outputs: tagname: description: Returns the new tag value. Empty if a tag is not created. @@ -28,7 +31,7 @@ outputs: tagmessage: description: The messge applied to the tag reference (this is what shows up on the tag screen on Github). version: - description: The version, as defined in package.json. + description: The version, as defined in package.json or explicitly set in the input. runs: - using: 'node12' - main: 'lib/main.js' + using: "node12" + main: "lib/main.js" diff --git a/lib/main.js b/lib/main.js index a9cae47..b75afa0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -8,24 +8,31 @@ async function run() { try { core.debug(` Available environment variables:\n -> ${Object.keys(process.env).map(i => i + ' :: ' + process.env[i]).join('\n -> ')}`) - let dir = fs.readdirSync(path.resolve(process.env.GITHUB_WORKSPACE), { withFileTypes: true }).map(entry => { - return `${entry.isDirectory() ? '> ' : ' - '}${entry.name}` - }).join('\n') + let version = "" - core.debug(` Working Directory: ${process.env.GITHUB_WORKSPACE}:\n${dir}`) - - const pkg_root = core.getInput('package_root', { required: false }) - let pkgfile = path.join(process.env.GITHUB_WORKSPACE, pkg_root, 'package.json') + if (!process.env.hasOwnProperty('INPUT_VERSION') || process.env.INPUT_VERSION.trim().length === 0) { + let dir = fs.readdirSync(path.resolve(process.env.GITHUB_WORKSPACE), { withFileTypes: true }).map(entry => { + return `${entry.isDirectory() ? '> ' : ' - '}${entry.name}` + }).join('\n') - if (!fs.existsSync(pkgfile)) { - core.setFailed('package.json does not exist.') - return + core.debug(` Working Directory: ${process.env.GITHUB_WORKSPACE}:\n${dir}`) + + const pkg_root = core.getInput('package_root', { required: false }) + let pkgfile = path.join(process.env.GITHUB_WORKSPACE, pkg_root, 'package.json') + + if (!fs.existsSync(pkgfile)) { + core.setFailed('package.json does not exist.') + return + } + + let pkg = require(pkgfile) + version = pkg.version + } else { + version = process.env.INPUT_VERSION.trim() } - let pkg = require(pkgfile) - - core.setOutput('version', pkg.version) - core.debug(` Detected version ${pkg.version}`) + core.setOutput('version', version) + core.debug(` Detected version ${version}`) if (!process.env.hasOwnProperty('INPUT_GITHUB_TOKEN') || process.env.INPUT_GITHUB_TOKEN.trim().length === 0) { core.setFailed('Invalid or missing GITHUB_TOKEN.') @@ -52,7 +59,7 @@ async function run() { // Check for existance of tag and abort (short circuit) if it already exists. for (let tag of tags.data) { - if (tag.name.trim().toLowerCase() === pkg.version.trim().toLowerCase()) { + if (tag.name.trim().toLowerCase() === version.trim().toLowerCase()) { core.warning(`"${tag.name.trim()}" tag already exists.`) core.setOutput('tagname', '') return @@ -60,7 +67,7 @@ async function run() { } // Create the new tag name - let tagName = pkg.version + let tagName = version const tagPrefix = core.getInput('tag_prefix', { required: false }) const tagSuffix = core.getInput('tag_suffix', { required: false }) let tagMsg = core.getInput('tag_message', { required: false }).trim() @@ -90,7 +97,7 @@ async function run() { try { tagMsg = tagMsg.trim().length > 0 ? tagMsg - : `Version ${pkg.version}` + : `Version ${version}` newTag = await git.git.createTag({ owner, From e9225a4301903fb87e1282830a90f545428918f8 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 18 Dec 2019 10:08:53 -0600 Subject: [PATCH 07/18] Update FUNDING.yml --- .github/FUNDING.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index d313453..0b47495 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,6 +1,6 @@ # These are supported funding model platforms -github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +github: coreybutler patreon: coreybutler open_collective: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username From b3973d98d16ec8312fbd7b15c93ebb4c737bd695 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Sun, 29 Dec 2019 13:05:52 -0600 Subject: [PATCH 08/18] Update package.json Removed unnecessary type declaration. --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 65e7f44..bd5c798 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,6 @@ "node", "setup" ], - "type": "module", "author": "ButlerLogic", "license": "MIT", "dependencies": { From 49c80f981f0cf2d12bef50bcba02c2c47c112f8f Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Fri, 24 Jan 2020 09:37:17 -0600 Subject: [PATCH 09/18] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2635d18..1bf4edd 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ The `GITHUB_TOKEN` must be passed in. Without this, it is not possible to create GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" ``` -The action will automatically extract the token at runtime. **DO NOT MANUALLY ENTER YOUR TOKEN.** If you put the actual token in your workflow file, you're make it accessible in plaintext to anyone who ever views the repository (it wil be in your git history). +The action will automatically extract the token at runtime. **DO NOT MANUALLY ENTER YOUR TOKEN.** If you put the actual token in your workflow file, you'll make it accessible (in plaintext) to anyone who ever views the repository (it will be in your git history). ### Optional Configurations From 3b1615aba7cb48a7a179b2217dd86e291a1bda55 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Fri, 24 Jan 2020 09:38:54 -0600 Subject: [PATCH 10/18] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1bf4edd..3b454c0 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ There are several options to customize how the tag is created. package_root: "/path/to/subdirectory" ``` -1. `tag_prefx` +1. `tag_prefix` By default, `package.json` uses [semantic versioning](https://semver.org/), such as `1.0.0`. A prefix can be used to add text before the tag name. For example, if `tag_prefx` is set to `v`, then the tag would be labeled as `v1.0.0`. @@ -70,7 +70,7 @@ There are several options to customize how the tag is created. - uses: butlerlogic/action-autotag@1.0.0 with: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - tag_prefx: "v" + tag_prefix: "v" ``` 1. `tag_suffix` From 39667b74efc6a36c4f32e831fa05dbc8ecf794d5 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Sun, 26 Jan 2020 21:02:56 -0600 Subject: [PATCH 11/18] Update main.js --- lib/main.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index c3d3902..6848a7b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -91,7 +91,7 @@ async function run() { // Check for existance of tag and abort (short circuit) if it already exists. for (let tag of tags.data) { if (tag.name === getTagName(pkg.version)) { - core.warning(`"${tag.name.trim()}" tag already exists.`) + core.info(`"${tag.name.trim()}" tag already exists.`) core.setOutput('tagname', '') return } @@ -124,7 +124,7 @@ async function run() { ) .join('\n') } catch (e) { - core.warning('Failed to generate changelog from commits: ' + e.message) + core.info('Failed to generate changelog from commits: ' + e.message) tagMsg = tagName } } @@ -141,7 +141,7 @@ async function run() { type: 'commit', }) - core.warning(`Created new tag: ${newTag.data.tag}`) + core.info(`Created new tag: ${newTag.data.tag}`) } catch (e) { core.setFailed(e.message) return @@ -155,7 +155,7 @@ async function run() { sha: newTag.data.sha, }) - core.warning(`Reference ${newReference.data.ref} available at ${newReference.data.url}`) + core.info(`Reference ${newReference.data.ref} available at ${newReference.data.url}`) } catch (e) { core.warning({ ...repo, From b2abc3fde0b9fe842ea0be6dbc5f5c894b5351f6 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Mon, 27 Jan 2020 16:49:28 -0600 Subject: [PATCH 12/18] Update package.json --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index bd5c798..93159b1 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "author": "ButlerLogic", "license": "MIT", "dependencies": { - "@actions/core": "^1.0.0", - "@actions/github": "^1.0.0" + "@actions/core": "^1.2.2", + "@actions/github": "^2.1.0" } } From 5fa65bf3badf759c9b52325420024cb2ffb012e1 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Mon, 27 Jan 2020 16:54:41 -0600 Subject: [PATCH 13/18] Removed core.info Despite the [existance of core.info](https://github.com/actions/toolkit/blob/master/packages/core/src/core.ts#L133), the action was throwing an error about this method. Reverted to `console.log` --- lib/main.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 6848a7b..5036452 100644 --- a/lib/main.js +++ b/lib/main.js @@ -2,6 +2,7 @@ const github = require('@actions/github') const core = require('@actions/core') const fs = require('fs') const path = require('path') +const os = require('os') async function run() { try { @@ -91,7 +92,7 @@ async function run() { // Check for existance of tag and abort (short circuit) if it already exists. for (let tag of tags.data) { if (tag.name === getTagName(pkg.version)) { - core.info(`"${tag.name.trim()}" tag already exists.`) + console.log(`"${tag.name.trim()}" tag already exists.` + os.EOL) core.setOutput('tagname', '') return } @@ -124,7 +125,7 @@ async function run() { ) .join('\n') } catch (e) { - core.info('Failed to generate changelog from commits: ' + e.message) + console.log('Failed to generate changelog from commits: ' + e.message + os.EOL) tagMsg = tagName } } @@ -141,7 +142,7 @@ async function run() { type: 'commit', }) - core.info(`Created new tag: ${newTag.data.tag}`) + console.log(`Created new tag: ${newTag.data.tag}` + os.EOL) } catch (e) { core.setFailed(e.message) return @@ -155,7 +156,7 @@ async function run() { sha: newTag.data.sha, }) - core.info(`Reference ${newReference.data.ref} available at ${newReference.data.url}`) + console.log(`Reference ${newReference.data.ref} available at ${newReference.data.url}` + os.EOL) } catch (e) { core.warning({ ...repo, From 6ab639fa5a9b4720bfafb09fbc081d72229772af Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Mon, 27 Jan 2020 16:58:59 -0600 Subject: [PATCH 14/18] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3b454c0..f122034 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@master + - uses: actions/checkout@v2 - uses: butlerlogic/action-autotag@stable with: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" From 010bb4a48a3f47060731b51ae04f7b0dc2545795 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Mon, 27 Jan 2020 17:01:06 -0600 Subject: [PATCH 15/18] Update README.md --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f122034..2dde34d 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,15 @@ This action will read a `package.json` file and compare the `version` attribute ## Usage -The following is an example `.github/main.workflow` that will execute when a `push` to the `master` branch occurs. +The following is an example `.github/workflows/main.yml` that will execute when a `push` to the `master` branch occurs. ```yaml -name: My Workflow +name: Create Tag on: push: branches: - - master + - master jobs: build: @@ -29,8 +29,8 @@ To make this work, the workflow must have the checkout action _before_ the autot This **order** is important! ```yaml -- uses: actions/checkout@master -- uses: butlerlogic/action-autotag@1.0.0 +- uses: actions/checkout@v2 +- uses: butlerlogic/action-autotag@stable ``` > If the repository is not checked out first, the autotagger cannot find the package.json file. @@ -40,7 +40,7 @@ This **order** is important! The `GITHUB_TOKEN` must be passed in. Without this, it is not possible to create a new tag. Make sure the autotag action looks like the following example: ```yaml -- uses: butlerlogic/action-autotag@1.0.0 +- uses: butlerlogic/action-autotag@stable with: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" ``` From 81eb23ba3c0db2a231d417644ed43b0886ddf6fe Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Mon, 27 Jan 2020 18:14:23 -0600 Subject: [PATCH 16/18] Added tagref output --- lib/main.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/main.js b/lib/main.js index 5036452..04f036e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -174,6 +174,7 @@ async function run() { core.setOutput('tagsha', newTag.data.sha) core.setOutput('taguri', newReference.data.url) core.setOutput('tagmessage', tagMsg.trim()) + core.setOutput('tagref', newReference.data.ref) } } catch (error) { core.warning(error.message) @@ -181,6 +182,7 @@ async function run() { core.setOutput('tagsha', '') core.setOutput('taguri', '') core.setOutput('tagmessage', '') + core.setOutput('tagref', '') } } From f4d418098f9c5d007f6f0a4288c8bb51d90c47ef Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 29 Jan 2020 16:55:04 -0600 Subject: [PATCH 17/18] Update README.md --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 2dde34d..3353508 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,13 @@ This action will read a `package.json` file and compare the `version` attribute to the project's known tags. If a corresponding tag does not exist, it will be created. +This tag works well in combination with: + +- [actions/create-release](https://github.com/actions/create-release) (Auto-release) +- [author/action-publish](https://github.com/author/action-publish) (Auto-publish JavaScript/Node modules) +- [author/action-rollback](https://github.com/author/action-rollback) (Auto-rollback releases on failures) +- [author/template-cross-runtime](https://github.com/author/template-cross-runtime) (a cross-runtime JavaScript repo template) + ## Usage The following is an example `.github/workflows/main.yml` that will execute when a `push` to the `master` branch occurs. From eef8306cea877a1e1a1e66c09d9a7164f2f92af3 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 29 Jan 2020 22:25:24 -0600 Subject: [PATCH 18/18] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3353508..8cdae73 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ There are several options to customize how the tag is created. 1. `tag_prefix` - By default, `package.json` uses [semantic versioning](https://semver.org/), such as `1.0.0`. A prefix can be used to add text before the tag name. For example, if `tag_prefx` is set to `v`, then the tag would be labeled as `v1.0.0`. + By default, `package.json` uses [semantic versioning](https://semver.org/), such as `1.0.0`. A prefix can be used to add text before the tag name. For example, if `tag_prefix` is set to `v`, then the tag would be labeled as `v1.0.0`. ```yaml - uses: butlerlogic/action-autotag@1.0.0