From d1f68225dd03b735c83c70c1bd09ec8f1328947f Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 12:27:19 -0500 Subject: [PATCH 01/56] Updated to use new strategies with controlled Docker environment. --- .github/workflows/test.yml | 30 ++++ .gitignore | 13 +- Dockerfile | 5 + LICENSE | 2 +- README.md | 127 +++++++++------ action.yml | 22 ++- app/lib/docker.js | 15 ++ app/lib/package.js | 23 +++ app/lib/regex.js | 34 ++++ app/lib/setup.js | 33 ++++ app/lib/tag.js | 135 ++++++++++++++++ app/main.js | 72 +++++++++ package-lock.json => app/package-lock.json | 0 package.json => app/package.json | 3 - lib/main.js | 174 --------------------- 15 files changed, 447 insertions(+), 241 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 Dockerfile create mode 100644 app/lib/docker.js create mode 100644 app/lib/package.js create mode 100644 app/lib/regex.js create mode 100644 app/lib/setup.js create mode 100644 app/lib/tag.js create mode 100644 app/main.js rename package-lock.json => app/package-lock.json (100%) rename package.json => app/package.json (92%) delete mode 100644 lib/main.js diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..687e1fb --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,30 @@ +name: Test + +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + steps: + # Checkout updated source code + - uses: actions/checkout@v2 + + # If the version has changed, create a new git tag for it. + - name: Tag + id: autotagger + uses: butlerlogic/action-autotag@master + with: + tag_prefix: 'test_' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Rollback Release + if: failure() && steps.create_release.outputs.id != '' + uses: author/action-rollback@stable + with: + tag: ${{ steps.autotagger.outputs.tagname }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7c0c456..35aa180 100644 --- a/.gitignore +++ b/.gitignore @@ -1,16 +1,9 @@ -# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore -# Logs logs *.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* - -# Diagnostic reports (https://nodejs.org/api/report.html) -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json - +*.log* .* !.gitignore !.github +!.dockerignore _* +node_modules diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..25f4ba1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM node:13-alpine +ADD ./app /app +WORKDIR /app +RUN npm i +CMD ["node", "main.js"] \ No newline at end of file diff --git a/LICENSE b/LICENSE index 7775d4e..7a4dee7 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,7 @@ The MIT License (MIT) -Copyright (c) 2019 Corey Butler and contributors +Copyright (c) 2020 Corey Butler and contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 8cdae73..ea5f8ca 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,14 @@ # Autotag -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 action will auto-generate a Github tag whenever a new version is detected. The following "detection strategies" are available: -This tag works well in combination with: +1. **package**: Monitor a `package.json` for new versions. +1. **docker**: Monitor a `Dockerfile` for a `LABEL version=x.x.x` value. +1. **regex**: Use a JavaScript [regular expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) with any file for your own custom extraction. + +When a version is detected, it is compared to the current list of tags in the Github repository. If a tag does not exist, it will be created. + +This action 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) @@ -44,7 +50,7 @@ This **order** is important! ## Configuration -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: +The `GITHUB_TOKEN` **must** be provided. 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@stable @@ -58,62 +64,88 @@ 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` +#### strategy - 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. +This is the strategy used to identify the version number/tag from within the code base. - ```yaml - - uses: butlerlogic/action-autotag@1.0.0 - with: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - package_root: "/path/to/subdirectory" - ``` +1. _package_: Monitor a `package.json` for new versions. Use this for JavaScript projects based on Node modules (npm, yarn, etc). +1. _docker_: Monitor a `Dockerfile` for a `LABEL version=x.x.x` value. USe this for container projects. +1. _regex*_: Use a JavaScript [regular expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) with any file for your own custom extraction. -1. `tag_prefix` +*An example " - 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`. +#### root `(required)` +_Formerly `package_root`_ - ```yaml - - uses: butlerlogic/action-autotag@1.0.0 - with: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - tag_prefix: "v" - ``` +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. -1. `tag_suffix` +```yaml +- uses: butlerlogic/action-autotag@1.0.0 + with: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + root: "/path/to/subdirectory" +``` - 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. +> **EXCEPTION**: This property is not required if the regex_pattern property is defined. In that case, this property is assumed to be "regex". - ```yaml - - uses: butlerlogic/action-autotag@1.0.0 - with: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - tag_suffix: " (beta)" - ``` +#### tag_prefix -1. `tag_message` +By default, [semantic versioning](https://semver.org/) is used, 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`. - 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: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + tag_prefix: "v" +``` - ```yaml - - uses: butlerlogic/action-autotag@1.0.0 - with: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - tag_message: "Custom message goes here." - ``` +#### tag_suffix -1. `version` +Text can 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. - 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 }}" + tag_suffix: " (beta)" +``` - ```yaml - - uses: butlerlogic/action-autotag@1.0.0 - with: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - version: "${{ steps.previous_step.outputs.version }}" - ``` +#### 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 current reference (HEAD). Setting this option will override the message. + +```yaml +- uses: butlerlogic/action-autotag@1.0.0 + with: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + tag_message: "Custom message goes here." +``` + +#### version + +Explicitly set the version instead of using automatic detection. + +Useful for projects where the version number 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 }}" +``` + +#### regex_pattern + +An optional attribute containing the regular expression used to extract the version number. + +```yaml +- uses: butlerlogic/action-autotag@1.0.0 + with: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + regex_pattern: "version=([0-9\.]+)" +``` + +This attribute is used as the first argument of a [RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/RegExp) object. The first "group" (i.e. what's in parenthesis) will be used as the version number. For an example, see this [working example](regexr.com/51i6n). ## Developer Notes @@ -123,6 +155,7 @@ If you are building an action that runs after this one, be aware this action pro 1. `tagsha`: The SHA of the new tag. 1. `taguri`: The URI/URL of the new tag reference. 1. `tagmessage`: The messge applied to the tag reference (this is what shows up on the tag screen on Github). +1. `tagcreated`: `yes` or `no`. 1. `version` will be the version attribute found in the `package.json` file. --- @@ -135,10 +168,10 @@ This action was written and is primarily maintained by [Corey Butler](https://gi If you use this or find value in it, please consider contributing in one or more of the following ways: -1. Click the "Sponsor" button at the top of the page. +1. Click the "Sponsor" button at the top of the page and make a contribution. 1. Star it! 1. [Tweet about it!](https://twitter.com/intent/tweet?hashtags=github,actions&original_referer=http%3A%2F%2F127.0.0.1%3A91%2F&text=I%20am%20automating%20my%20workflow%20with%20the%20Autotagger%20Github%20action!&tw_p=tweetbutton&url=https%3A%2F%2Fgithub.com%2Fmarketplace%2Factions%2Fautotagger&via=goldglovecb) 1. Fix an issue. 1. Add a feature (post a proposal in an issue first!). -Copyright © 2019 ButlerLogic, Corey Butler, and Contributors. +Copyright © 2020 Butler Logic, Corey Butler, and Contributors. diff --git a/action.yml b/action.yml index 5b11a2c..a9bdf25 100644 --- a/action.yml +++ b/action.yml @@ -1,12 +1,20 @@ name: "Autotagger" -description: "Automatically generate new tags when the package.json version changes." -author: "ButlerLogic" +description: "Automatically generate new tags for new versions. Supports several tagging strategies, including package.json, Dockerfiles, and Regex." +author: "Butler Logic" branding: icon: "tag" - color: "black" + color: "blue" inputs: + root: + description: Autotag will look for the appropriate file in in this location (relative to project root). + required: false + default: './' + strategy: + description: Options include 'package' (for package.json), 'docker' (for Dockerfile), and 'regex' to extract from an arbitrary file. This does not need to be specified if the "regex_pattern" property is provided. + required: false + default: 'package' package_root: - description: Autotag will look for the package.json file in in this location. + description: (DEPRECATED. Use 'root' instead.) Autotag will look for the package.json file in in this location. required: false default: './' tag_prefix: @@ -32,6 +40,8 @@ outputs: 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 or explicitly set in the input. + tagcreated: + description: A "yes" or "no", indicating a new tag was created. runs: - using: "node12" - main: "lib/main.js" + using: 'docker' + image: 'Dockerfile' diff --git a/app/lib/docker.js b/app/lib/docker.js new file mode 100644 index 0000000..e2764d9 --- /dev/null +++ b/app/lib/docker.js @@ -0,0 +1,15 @@ +import Regex from './regex.js' +import path from 'path' +import fs from 'fs' + +export default class Dockerfile extends Regex { + constructor (root = null) { + root = path.join(process.env.GITHUB_WORKSPACE, root) + + if (fs.statSync(root).isDirectory()) { + root = path.join(root, 'Dockerfile') + } + + super(root, /LABEL[\s\t]+version=[\t\s+]?[\"\']?([0-9\.]+)[\"\']?/i) + } +} diff --git a/app/lib/package.js b/app/lib/package.js new file mode 100644 index 0000000..d54ac61 --- /dev/null +++ b/app/lib/package.js @@ -0,0 +1,23 @@ +import fs from 'fs' +import path from 'path' + +export default class Package { + constructor (root = './') { + root = path.join(process.env.GITHUB_WORKSPACE, root) + + if (fs.statSync(root).isDirectory()) { + root = path.join(root, 'package.json') + } + + if (!fs.existsSync(root)) { + throw new Error(`package.json does not exist at ${root}.`) + } + + this.root = root + this.data = JSON.parse(fs.readFileSync(root)) + } + + get version () { + return this.data.version + } +} diff --git a/app/lib/regex.js b/app/lib/regex.js new file mode 100644 index 0000000..c34ba90 --- /dev/null +++ b/app/lib/regex.js @@ -0,0 +1,34 @@ +import fs from 'fs' +import path from 'path' + +export default class Regex { + constructor (root = null, pattern) { + root = path.join(process.env.GITHUB_WORKSPACE, root) + + if (fs.statSync(root).isDirectory()) { + throw new Error(`${root} is a directory. The Regex tag identification strategy requires a file.`) + } + + if (!fs.existsSync(root)) { + throw new Error(`"${root}" does not exist.`) + } + + this.content = fs.readFileSync(root).toString() + + let content = pattern.exec(this.content) + if (!content) { + this._version = null + // throw new Error(`Could not find pattern matching "${pattern.toString()}" in "${root}".`) + } else { + this._version = content[1] + } + } + + get version () { + return this._version + } + + get versionFound () { + return this._version !== null + } +} diff --git a/app/lib/setup.js b/app/lib/setup.js new file mode 100644 index 0000000..4109c2b --- /dev/null +++ b/app/lib/setup.js @@ -0,0 +1,33 @@ +import core from '@actions/core' +import fs from 'fs' +import path from 'path' + +export default class Setup { + static debug () { + // Metadate for debugging + 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}`) + } + + static requireAnyEnv () { + for (const arg of arguments) { + if (!process.env.hasOwnProperty(arg)) { + return + } + } + + throw new Error('At least one of the following environment variables is required: ' + Array.slice(arguments).join(', ')) + } +} diff --git a/app/lib/tag.js b/app/lib/tag.js new file mode 100644 index 0000000..050b08e --- /dev/null +++ b/app/lib/tag.js @@ -0,0 +1,135 @@ +import core from '@actions/core' +import os from 'os' +import { GitHub, context } from '@actions/github' + +// Get authenticated GitHub client (Ocktokit): https://github.com/actions/toolkit/tree/master/packages/github#usage +const github = new GitHub(process.env.GITHUB_TOKEN || process.env.INPUT_GITHUB_TOKEN) +// Get owner and repo from context of payload that triggered the action +const { owner, repo } = context.repo + +export default class Tag { + constructor (prefix, version, postfix) { + this.prefix = prefix + this.version = version + this.postfix = postfix + this._tags = null + this._message = null + this._exists = null + } + + get name () { + return `${this.prefix.trim()}${this.version.trim()}${this.postfix.trim()}` + } + + set message (value) { + if (value && value.length > 0) { + this._message = value + } + } + + async getMessage () { + if (this._message !== null) { + return this._message + } + + try { + const changelog = await github.repos.compareCommits({ owner, repo, base: tags.data.shift().name, head: 'master' }) + + return changelog.data.commits + .map( + (commit, i) => + `${i + 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 + os.EOL) + return `Version ${this.version}` + } + } + + async getTags () { + if (this._tags !== null) { + return this._tags.data + } + + this._tags = await github.repos.listTags({ owner, repo, per_page: 100 }) + + return this._tags.data + } + + async exists () { + if (this._exists !== null) { + return this._exists + } + const currentTag = this.name + const tags = await this.getTags() + + for (const tag of tags) { + if (tag.name === currentTag) { + this._exists = true + return true + } + } + + this._exists = false + return false + } + + async push () { + let tagexists = await this.exists() + + if (!tagexists) { + // Create tag + const newTag = await github.git.createTag({ + owner, + repo, + tag: this.name, + message: this.message, + object: process.env.GITHUB_SHA, + type: 'commit' + }) + + core.warning(`Created new tag: ${newTag.data.tag}`) + + // Create reference + let newReference + try { + newReference = await github.git.createRef({ + owner, + repo, + ref: `refs/tags/${newTag.data.tag}`, + sha: newTag.data.sha + }) + } catch (e) { + core.warning({ + owner, + repo, + ref: `refs/tags/${newTag.data.tag}`, + sha: newTag.data.sha + }) + + throw e + } + + core.warning(`Reference ${newReference.data.ref} available at ${newReference.data.url}` + os.EOL) + + // Store values for other actions + if (typeof newTag === 'object' && typeof newReference === 'object') { + core.setOutput('tagname', this.name) + core.setOutput('tagsha', newTag.data.sha) + core.setOutput('taguri', newReference.data.url) + core.setOutput('tagmessage', this.message) + core.setOutput('tagref', newReference.data.ref) + core.setOutput('tagcreated', 'yes') + } + } else { + core.warning('Cannot push tag (it already exists).') + } + } +} diff --git a/app/main.js b/app/main.js new file mode 100644 index 0000000..2c957f4 --- /dev/null +++ b/app/main.js @@ -0,0 +1,72 @@ +import core from '@actions/core' +import os from 'os' +import Setup from './lib/setup.js' +import Package from './lib/package.js' +import Tag from './lib/tag.js' +import Regex from './lib/regex.js' + +async function run () { + try { + Setup.debug() + Setup.requireAnyEnv('GITHUB_TOKEN', 'INPUT_GITHUB_TOKEN') + + // Identify the tag parsing strategy + const root = core.getInput('root', { required: false }) || core.getInput('package_root', { required: false }) || './' + const strategy = (core.getInput('strategy', { required: false }) || '').trim().length > 0 ? 'regex' : ((core.getInput('strategy', { required: false }) || 'package').trim().toLowerCase()) + + // Extract the version number using the supplied strategy + let version = core.getInput('root', { required: false }) + version = version === null || version.trim().length === 0 ? null : version + + switch (strategy) { + case 'docker': + version = (new Dockerfile(root)).version + break + + case 'package': + // Extract using the package strategy (this is the default strategy) + version = (new Package(root)).version + break + + case 'regex': + version = (new Regex(root, new RegExp(pattern, 'i'))).version + break + + default: + core.setFailed(`"${strategy}" is not a recognized tagging strategy. Choose from: 'package' (package.json), 'docker' (uses Dockerfile), or 'regex' (JS-based RegExp).`) + return + } + + core.setOutput('version', version) + core.debug(` Detected version ${version}`) + + // Configure a tag using the identified version + const tag = new Tag( + core.getInput('tag_prefix', { required: false }), + version, + core.getInput('tag_suffix', { required: false }) + ) + + // Check for existance of tag and abort (short circuit) if it already exists. + if (await tag.exists()) { + core.warning(`"${tag.name}" tag already exists.` + os.EOL) + core.setOutput('tagname', '') + core.setOutput('tagcreated', 'no') + return + } + + // The tag setter will autocorrect the message if necessary. + tag.message = core.getInput('tag_message', { required: false }).trim() + await tag.push() + } catch (error) { + core.warning(error.message) + core.setOutput('tagname', '') + core.setOutput('tagsha', '') + core.setOutput('taguri', '') + core.setOutput('tagmessage', '') + core.setOutput('tagref', '') + core.setOutput('tagcreated', 'no') + } +} + +run() diff --git a/package-lock.json b/app/package-lock.json similarity index 100% rename from package-lock.json rename to app/package-lock.json diff --git a/package.json b/app/package.json similarity index 92% rename from package.json rename to app/package.json index 93159b1..8427cfe 100644 --- a/package.json +++ b/app/package.json @@ -4,9 +4,6 @@ "private": true, "description": "Automatically create a tag whenever the version changes in package.json", "main": "lib/main.js", - "scripts": { - "test": "jest" - }, "repository": { "type": "git", "url": "git+https://github.com/butlerlogic/action-autotag.git" diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 26bc899..0000000 --- a/lib/main.js +++ /dev/null @@ -1,174 +0,0 @@ -const core = require('@actions/core') -const { GitHub, context } = require('@actions/github') -const fs = require('fs') -const path = require('path') -const os = require('os') - -async function run() { - try { - 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}`) - - if (!process.env.hasOwnProperty('GITHUB_TOKEN')) { - if (!process.env.hasOwnProperty('INPUT_GITHUB_TOKEN')) { - core.setFailed('Invalid or missing GITHUB_TOKEN.') - return - } - } - - 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 - } - - const pkg = require(pkgfile) - core.setOutput('version', pkg.version) - core.debug(` Detected version ${pkg.version}`) - - // Get authenticated GitHub client (Ocktokit): https://github.com/actions/toolkit/tree/master/packages/github#usage - const github = new GitHub(process.env.GITHUB_TOKEN || process.env.INPUT_GITHUB_TOKEN) - - // Get owner and repo from context of payload that triggered the action - const { owner, repo } = context.repo - - // // Check for existing tag - // const git = new github.GitHub(process.env.INPUT_GITHUB_TOKEN || process.env.GITHUB_TOKEN) - // const owner = process.env.GITHUB_REPOSITORY.split('/').shift() - // const repo = process.env.GITHUB_REPOSITORY.split('/').pop() - - let tags - try { - tags = await github.repos.listTags({ - owner, - repo, - per_page: 100, - }) - } catch (e) { - tags = { - data: [], - } - } - - const tagPrefix = core.getInput('tag_prefix', { required: false }) - const tagSuffix = core.getInput('tag_suffix', { required: false }) - - const getTagName = version => { - 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 === getTagName(pkg.version)) { - core.warning(`"${tag.name.trim()}" tag already exists.` + os.EOL) - core.setOutput('tagname', '') - return - } - } - - // Create the new tag name - const tagName = getTagName(pkg.version) - - let tagMsg = core.getInput('tag_message', { required: false }).trim() - if (tagMsg.length === 0 && tags.data.length > 0) { - try { - latestTag = tags.data.shift() - - let changelog = await github.repos.compareCommits({ - owner, - repo, - base: latestTag.name, - 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') - } catch (e) { - core.warning('Failed to generate changelog from commits: ' + e.message + os.EOL) - tagMsg = tagName - } - } - - let newTag - try { - tagMsg = tagMsg.trim().length > 0 ? tagMsg : `Version ${pkg.version}` - - newTag = await github.git.createTag({ - owner, - repo, - tag: tagName, - message: tagMsg, - object: process.env.GITHUB_SHA, - type: 'commit' - }) - - core.warning(`Created new tag: ${newTag.data.tag}`) - } catch (e) { - core.setFailed(e.message) - return - } - - let newReference - try { - newReference = await github.git.createRef({ - owner, - repo, - ref: `refs/tags/${newTag.data.tag}`, - sha: newTag.data.sha, - }) - - core.warning(`Reference ${newReference.data.ref} available at ${newReference.data.url}` + os.EOL) - } catch (e) { - core.warning({ - owner, - repo, - ref: `refs/tags/${newTag.data.tag}`, - sha: newTag.data.sha, - }) - - core.setFailed(e.message) - return - } - - // Store values for other actions - if (typeof newTag === 'object' && typeof newReference === 'object') { - core.setOutput('tagname', tagName) - 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) - core.setOutput('tagname', '') - core.setOutput('tagsha', '') - core.setOutput('taguri', '') - core.setOutput('tagmessage', '') - core.setOutput('tagref', '') - } -} - -run() From 2d7ff4f878d1b158fac9cd7d395e696acbbecfd4 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 12:28:56 -0500 Subject: [PATCH 02/56] Updated test --- .github/workflows/test.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 687e1fb..9537963 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,8 @@ on: - master jobs: - build: + test: + name: Test Suite runs-on: ubuntu-latest steps: # Checkout updated source code @@ -22,7 +23,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Rollback Release - if: failure() && steps.create_release.outputs.id != '' + if: success() uses: author/action-rollback@stable with: tag: ${{ steps.autotagger.outputs.tagname }} From 4fa102341976f83b85ec45a8327ac4e7fb0e3e2b Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 12:32:38 -0500 Subject: [PATCH 03/56] Update script paths --- Dockerfile | 2 +- app/package.json | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 25f4ba1..9ab69e8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,4 +2,4 @@ FROM node:13-alpine ADD ./app /app WORKDIR /app RUN npm i -CMD ["node", "main.js"] \ No newline at end of file +CMD ["npm", "start"] \ No newline at end of file diff --git a/app/package.json b/app/package.json index 8427cfe..5438de3 100644 --- a/app/package.json +++ b/app/package.json @@ -4,6 +4,9 @@ "private": true, "description": "Automatically create a tag whenever the version changes in package.json", "main": "lib/main.js", + "scripts": { + "start": "node ./main.js" + }, "repository": { "type": "git", "url": "git+https://github.com/butlerlogic/action-autotag.git" From d156584cf400b9d2c0e7bc957222095987120f78 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 12:36:13 -0500 Subject: [PATCH 04/56] Use entrypoint instead of cmd in dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9ab69e8..c3803a0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,4 +2,4 @@ FROM node:13-alpine ADD ./app /app WORKDIR /app RUN npm i -CMD ["npm", "start"] \ No newline at end of file +ENTRYPOINT ["npm", "start"] \ No newline at end of file From 8bc86d7ea9ad053c35803a6425c32401076b07d4 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 12:43:11 -0500 Subject: [PATCH 05/56] Attempting to trigger operation with argument --- action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/action.yml b/action.yml index a9bdf25..5636ec5 100644 --- a/action.yml +++ b/action.yml @@ -45,3 +45,5 @@ outputs: runs: using: 'docker' image: 'Dockerfile' + args: + - "npm start" From fc90f6bd7ea8f879d5087799b74781e718e60f48 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 12:46:31 -0500 Subject: [PATCH 06/56] Add testable package.json file --- action.yml | 2 -- package.json | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 package.json diff --git a/action.yml b/action.yml index 5636ec5..a9bdf25 100644 --- a/action.yml +++ b/action.yml @@ -45,5 +45,3 @@ outputs: runs: using: 'docker' image: 'Dockerfile' - args: - - "npm start" diff --git a/package.json b/package.json new file mode 100644 index 0000000..4b61073 --- /dev/null +++ b/package.json @@ -0,0 +1,21 @@ +{ + "name": "action-autotag-test", + "version": "1.0.0", + "description": "This is a test file for the action.", + "main": "index.js", + "dependencies": {}, + "devDependencies": {}, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/ButlerLogic/action-autotag.git" + }, + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/ButlerLogic/action-autotag/issues" + }, + "homepage": "https://github.com/ButlerLogic/action-autotag#readme" +} From bf8c9fecbe3836139e14bbec56feb2e6ee116219 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 12:54:35 -0500 Subject: [PATCH 07/56] Updated launch command --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c3803a0..54e3a08 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,4 +2,4 @@ FROM node:13-alpine ADD ./app /app WORKDIR /app RUN npm i -ENTRYPOINT ["npm", "start"] \ No newline at end of file +ENTRYPOINT ["node", "/app/main.js"] \ No newline at end of file From 911fd23decda4f9081d3fa91ad7e5b5f7b966a4b Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 12:56:33 -0500 Subject: [PATCH 08/56] Update build --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 54e3a08..1320068 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM node:13-alpine ADD ./app /app WORKDIR /app -RUN npm i +RUN cd /app && npm i ENTRYPOINT ["node", "/app/main.js"] \ No newline at end of file From 6b88966b82062f0fac31d90b0408f681f57d00a9 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 13:04:53 -0500 Subject: [PATCH 09/56] Attempting to force a rebuild of the Docker container --- .github/workflows/test.yml | 2 +- Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9537963..38df30a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: Test +name: Action Test on: push: diff --git a/Dockerfile b/Dockerfile index 1320068..465b711 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,4 +2,4 @@ FROM node:13-alpine ADD ./app /app WORKDIR /app RUN cd /app && npm i -ENTRYPOINT ["node", "/app/main.js"] \ No newline at end of file +CMD ["node", "/app/main.js"] \ No newline at end of file From 04c17737dc6c471a644a66abde90c08947ca78ad Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 13:06:09 -0500 Subject: [PATCH 10/56] Added missing module declaration in package file. --- app/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/package.json b/app/package.json index 5438de3..5ba36c3 100644 --- a/app/package.json +++ b/app/package.json @@ -21,5 +21,6 @@ "dependencies": { "@actions/core": "^1.2.2", "@actions/github": "^2.1.0" - } + }, + "type": "module" } From 8b69b3574529113fdb9f52419d200e970572a0ba Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 13:26:50 -0500 Subject: [PATCH 11/56] Update imports --- app/lib/tag.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/lib/tag.js b/app/lib/tag.js index 050b08e..49130ce 100644 --- a/app/lib/tag.js +++ b/app/lib/tag.js @@ -1,9 +1,10 @@ import core from '@actions/core' import os from 'os' -import { GitHub, context } from '@actions/github' +import GitHub from '@actions/github' // Get authenticated GitHub client (Ocktokit): https://github.com/actions/toolkit/tree/master/packages/github#usage const github = new GitHub(process.env.GITHUB_TOKEN || process.env.INPUT_GITHUB_TOKEN) +const context = github.context // Get owner and repo from context of payload that triggered the action const { owner, repo } = context.repo From dcbf76b3cc067f04f3e98b4417d0d5ca73254f5e Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 13:32:03 -0500 Subject: [PATCH 12/56] Update imports --- app/lib/tag.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/lib/tag.js b/app/lib/tag.js index 49130ce..9151689 100644 --- a/app/lib/tag.js +++ b/app/lib/tag.js @@ -1,9 +1,9 @@ import core from '@actions/core' import os from 'os' -import GitHub from '@actions/github' +import gh from '@actions/github' // Get authenticated GitHub client (Ocktokit): https://github.com/actions/toolkit/tree/master/packages/github#usage -const github = new GitHub(process.env.GITHUB_TOKEN || process.env.INPUT_GITHUB_TOKEN) +const github = new gh.GitHub(process.env.GITHUB_TOKEN || process.env.INPUT_GITHUB_TOKEN) const context = github.context // Get owner and repo from context of payload that triggered the action const { owner, repo } = context.repo From dd7e2f72ba7654eecef7e6ebf599ae172f32dbc9 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 13:35:18 -0500 Subject: [PATCH 13/56] Update imports --- app/lib/tag.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/lib/tag.js b/app/lib/tag.js index 9151689..32528bc 100644 --- a/app/lib/tag.js +++ b/app/lib/tag.js @@ -4,9 +4,8 @@ import gh from '@actions/github' // Get authenticated GitHub client (Ocktokit): https://github.com/actions/toolkit/tree/master/packages/github#usage const github = new gh.GitHub(process.env.GITHUB_TOKEN || process.env.INPUT_GITHUB_TOKEN) -const context = github.context // Get owner and repo from context of payload that triggered the action -const { owner, repo } = context.repo +const { owner, repo } = gh.context export default class Tag { constructor (prefix, version, postfix) { From ad707fc62359498bb161cf6a42ce30ca183aaebb Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 13:41:56 -0500 Subject: [PATCH 14/56] WIP --- app/main.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/main.js b/app/main.js index 2c957f4..05b6b51 100644 --- a/app/main.js +++ b/app/main.js @@ -10,6 +10,9 @@ async function run () { Setup.debug() Setup.requireAnyEnv('GITHUB_TOKEN', 'INPUT_GITHUB_TOKEN') + // Configure the default output + core.setOutput('tagcreated', 'no') + // Identify the tag parsing strategy const root = core.getInput('root', { required: false }) || core.getInput('package_root', { required: false }) || './' const strategy = (core.getInput('strategy', { required: false }) || '').trim().length > 0 ? 'regex' : ((core.getInput('strategy', { required: false }) || 'package').trim().toLowerCase()) @@ -51,13 +54,14 @@ async function run () { if (await tag.exists()) { core.warning(`"${tag.name}" tag already exists.` + os.EOL) core.setOutput('tagname', '') - core.setOutput('tagcreated', 'no') return } // The tag setter will autocorrect the message if necessary. tag.message = core.getInput('tag_message', { required: false }).trim() await tag.push() + + core.setOutput('tagcreated', 'yes') } catch (error) { core.warning(error.message) core.setOutput('tagname', '') From 83ba51591f52a9cda53ef174df075d8c6779a734 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 13:43:23 -0500 Subject: [PATCH 15/56] WIP --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 38df30a..0779936 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,7 +23,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Rollback Release - if: success() + if: success() && ${{ steps.autotagger.outputs.tagcreated = "yes" }} uses: author/action-rollback@stable with: tag: ${{ steps.autotagger.outputs.tagname }} From 9272761fd8a6f569c5ea4b3e3da0469450d2ca9d Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 13:44:47 -0500 Subject: [PATCH 16/56] WIP --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0779936..39ad780 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,7 +23,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Rollback Release - if: success() && ${{ steps.autotagger.outputs.tagcreated = "yes" }} + if: success() && ${{ steps.autotagger.outputs.tagcreated }} = "yes" uses: author/action-rollback@stable with: tag: ${{ steps.autotagger.outputs.tagname }} From 8ef42b17aac9a246dcf31ccc8167ca81f7e6446b Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 13:48:54 -0500 Subject: [PATCH 17/56] WIP --- action.yml | 3 +++ app/main.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index a9bdf25..193472f 100644 --- a/action.yml +++ b/action.yml @@ -29,6 +29,9 @@ inputs: 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 + regex_pattern: + description: An optional attribute containing the regular expression used to extract the version number. + required: false outputs: tagname: description: Returns the new tag value. Empty if a tag is not created. diff --git a/app/main.js b/app/main.js index 05b6b51..a12a94c 100644 --- a/app/main.js +++ b/app/main.js @@ -32,7 +32,7 @@ async function run () { break case 'regex': - version = (new Regex(root, new RegExp(pattern, 'i'))).version + version = (new Regex(root, new RegExp(core.getInput('regex_pattern', { required: true }), 'i'))).version break default: From dfca4f8300775fa4f7f41af00a4f944415b8adc4 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 13:49:56 -0500 Subject: [PATCH 18/56] WIP --- app/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main.js b/app/main.js index a12a94c..2a7027b 100644 --- a/app/main.js +++ b/app/main.js @@ -32,7 +32,7 @@ async function run () { break case 'regex': - version = (new Regex(root, new RegExp(core.getInput('regex_pattern', { required: true }), 'i'))).version + version = (new Regex(root, new RegExp(core.getInput('regex_pattern', { required: false }), 'i'))).version break default: From cd056261ff380528b762a2d9cc08ae2e26b0643f Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 13:51:57 -0500 Subject: [PATCH 19/56] Added appropriate defualt strategy --- app/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main.js b/app/main.js index 2a7027b..3bee644 100644 --- a/app/main.js +++ b/app/main.js @@ -15,7 +15,7 @@ async function run () { // Identify the tag parsing strategy const root = core.getInput('root', { required: false }) || core.getInput('package_root', { required: false }) || './' - const strategy = (core.getInput('strategy', { required: false }) || '').trim().length > 0 ? 'regex' : ((core.getInput('strategy', { required: false }) || 'package').trim().toLowerCase()) + const strategy = (core.getInput('regex_pattern', { required: false }) || '').trim().length > 0 ? 'regex' : ((core.getInput('strategy', { required: false }) || 'package').trim().toLowerCase()) // Extract the version number using the supplied strategy let version = core.getInput('root', { required: false }) From 3bbae423ca8038d0cb757ec34f112fa5da60cf66 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 13:53:11 -0500 Subject: [PATCH 20/56] WIP --- app/lib/tag.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/lib/tag.js b/app/lib/tag.js index 32528bc..66597b5 100644 --- a/app/lib/tag.js +++ b/app/lib/tag.js @@ -6,7 +6,7 @@ import gh from '@actions/github' const github = new gh.GitHub(process.env.GITHUB_TOKEN || process.env.INPUT_GITHUB_TOKEN) // Get owner and repo from context of payload that triggered the action const { owner, repo } = gh.context - +console.log(owner, repo) export default class Tag { constructor (prefix, version, postfix) { this.prefix = prefix From 3e9d7a08c64f0ee64e05f7cc9de1ea1e0814be21 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 13:57:18 -0500 Subject: [PATCH 21/56] WIP --- app/lib/tag.js | 2 +- app/main.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/lib/tag.js b/app/lib/tag.js index 66597b5..32528bc 100644 --- a/app/lib/tag.js +++ b/app/lib/tag.js @@ -6,7 +6,7 @@ import gh from '@actions/github' const github = new gh.GitHub(process.env.GITHUB_TOKEN || process.env.INPUT_GITHUB_TOKEN) // Get owner and repo from context of payload that triggered the action const { owner, repo } = gh.context -console.log(owner, repo) + export default class Tag { constructor (prefix, version, postfix) { this.prefix = prefix diff --git a/app/main.js b/app/main.js index 3bee644..a93e5c0 100644 --- a/app/main.js +++ b/app/main.js @@ -16,6 +16,7 @@ async function run () { // Identify the tag parsing strategy const root = core.getInput('root', { required: false }) || core.getInput('package_root', { required: false }) || './' const strategy = (core.getInput('regex_pattern', { required: false }) || '').trim().length > 0 ? 'regex' : ((core.getInput('strategy', { required: false }) || 'package').trim().toLowerCase()) + core.swarning(`Attempting to use ${strategy} strategy.`) // Extract the version number using the supplied strategy let version = core.getInput('root', { required: false }) From e4e846a30dc409346dc4592e3609bf13faed370c Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 13:58:16 -0500 Subject: [PATCH 22/56] WIP --- app/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main.js b/app/main.js index a93e5c0..06add7b 100644 --- a/app/main.js +++ b/app/main.js @@ -16,7 +16,7 @@ async function run () { // Identify the tag parsing strategy const root = core.getInput('root', { required: false }) || core.getInput('package_root', { required: false }) || './' const strategy = (core.getInput('regex_pattern', { required: false }) || '').trim().length > 0 ? 'regex' : ((core.getInput('strategy', { required: false }) || 'package').trim().toLowerCase()) - core.swarning(`Attempting to use ${strategy} strategy.`) + core.warning(`Attempting to use ${strategy} strategy.`) // Extract the version number using the supplied strategy let version = core.getInput('root', { required: false }) From 7604c0a83e159e58d8dd5353445c8a1f02f456f0 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 14:00:01 -0500 Subject: [PATCH 23/56] WIP --- action.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/action.yml b/action.yml index 193472f..52f5a6a 100644 --- a/action.yml +++ b/action.yml @@ -16,7 +16,6 @@ inputs: package_root: description: (DEPRECATED. Use 'root' instead.) Autotag will look for the package.json file in in this location. required: false - default: './' 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 From f4ff848c8e7f45f2c5d166067999ed1a1e0c87ff Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 14:01:25 -0500 Subject: [PATCH 24/56] WIP --- app/lib/tag.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/lib/tag.js b/app/lib/tag.js index 32528bc..54cbf8e 100644 --- a/app/lib/tag.js +++ b/app/lib/tag.js @@ -6,7 +6,7 @@ import gh from '@actions/github' const github = new gh.GitHub(process.env.GITHUB_TOKEN || process.env.INPUT_GITHUB_TOKEN) // Get owner and repo from context of payload that triggered the action const { owner, repo } = gh.context - +core.warning(`Owner: ${owner}, Repository: ${repo}`) export default class Tag { constructor (prefix, version, postfix) { this.prefix = prefix From 3f4bae1fc4079e81a4807aef378c9c5c149c12a6 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 14:03:12 -0500 Subject: [PATCH 25/56] WIP --- app/lib/tag.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/lib/tag.js b/app/lib/tag.js index 54cbf8e..bdbb0d1 100644 --- a/app/lib/tag.js +++ b/app/lib/tag.js @@ -6,7 +6,7 @@ import gh from '@actions/github' const github = new gh.GitHub(process.env.GITHUB_TOKEN || process.env.INPUT_GITHUB_TOKEN) // Get owner and repo from context of payload that triggered the action const { owner, repo } = gh.context -core.warning(`Owner: ${owner}, Repository: ${repo}`) +core.warning(`Owner: ${owner}, Repository: ${JSON.stringify(repo)}`) export default class Tag { constructor (prefix, version, postfix) { this.prefix = prefix From e9081bf57f26fc1c9ce5a5c137ec737a49fb4d1e Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 14:04:11 -0500 Subject: [PATCH 26/56] WIP --- app/lib/tag.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/lib/tag.js b/app/lib/tag.js index bdbb0d1..cfb634f 100644 --- a/app/lib/tag.js +++ b/app/lib/tag.js @@ -5,8 +5,8 @@ import gh from '@actions/github' // Get authenticated GitHub client (Ocktokit): https://github.com/actions/toolkit/tree/master/packages/github#usage const github = new gh.GitHub(process.env.GITHUB_TOKEN || process.env.INPUT_GITHUB_TOKEN) // Get owner and repo from context of payload that triggered the action -const { owner, repo } = gh.context -core.warning(`Owner: ${owner}, Repository: ${JSON.stringify(repo)}`) +const { owner, repo } = gh.context.repo + export default class Tag { constructor (prefix, version, postfix) { this.prefix = prefix From 304401229a888f633cf36427891e7b23bddbe63c Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 14:05:59 -0500 Subject: [PATCH 27/56] WIP --- app/lib/tag.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/lib/tag.js b/app/lib/tag.js index cfb634f..16c22d0 100644 --- a/app/lib/tag.js +++ b/app/lib/tag.js @@ -90,7 +90,7 @@ export default class Tag { owner, repo, tag: this.name, - message: this.message, + message: await this.getMessage(), object: process.env.GITHUB_SHA, type: 'commit' }) From 2174768f11c08280bcb805b720d43f0315e008a2 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 14:09:24 -0500 Subject: [PATCH 28/56] WIP --- app/main.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/main.js b/app/main.js index 06add7b..5cf0cb4 100644 --- a/app/main.js +++ b/app/main.js @@ -16,7 +16,7 @@ async function run () { // Identify the tag parsing strategy const root = core.getInput('root', { required: false }) || core.getInput('package_root', { required: false }) || './' const strategy = (core.getInput('regex_pattern', { required: false }) || '').trim().length > 0 ? 'regex' : ((core.getInput('strategy', { required: false }) || 'package').trim().toLowerCase()) - core.warning(`Attempting to use ${strategy} strategy.`) + core.warning(`Attempting to use ${strategy} version extraction strategy.`) // Extract the version number using the supplied strategy let version = core.getInput('root', { required: false }) @@ -65,6 +65,7 @@ async function run () { core.setOutput('tagcreated', 'yes') } catch (error) { core.warning(error.message) + core.warning(error.stack) core.setOutput('tagname', '') core.setOutput('tagsha', '') core.setOutput('taguri', '') From db1da31a6b492158b6ae262088356a4842776f97 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 14:13:09 -0500 Subject: [PATCH 29/56] WIP --- app/lib/tag.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/lib/tag.js b/app/lib/tag.js index 16c22d0..d799032 100644 --- a/app/lib/tag.js +++ b/app/lib/tag.js @@ -33,7 +33,13 @@ export default class Tag { } try { - const changelog = await github.repos.compareCommits({ owner, repo, base: tags.data.shift().name, head: 'master' }) + let tags = await this.getTags() + + if (tags.length === 0) { + return `Version ${this.version}` + } + + const changelog = await github.repos.compareCommits({ owner, repo, base: tags.shift().name, head: 'master' }) return changelog.data.commits .map( From cc392c0d6707542c37823ccf5b5f3b2c7d51236f Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 14:24:38 -0500 Subject: [PATCH 30/56] WIP --- app/lib/tag.js | 30 ++++++++++++++++++++---------- app/main.js | 5 +++++ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/app/lib/tag.js b/app/lib/tag.js index d799032..84128e6 100644 --- a/app/lib/tag.js +++ b/app/lib/tag.js @@ -15,6 +15,9 @@ export default class Tag { this._tags = null this._message = null this._exists = null + this._sha = '' + this._uri = '' + this._ref = '' } get name () { @@ -27,6 +30,18 @@ export default class Tag { } } + get sha () { + return this._sha || '' + } + + get uri () { + return this._uri || '' + } + + get ref () { + return this._ref || '' + } + async getMessage () { if (this._message !== null) { return this._message @@ -105,6 +120,8 @@ export default class Tag { // Create reference let newReference + this._sha = newTag.data.sha + try { newReference = await github.git.createRef({ owner, @@ -123,17 +140,10 @@ export default class Tag { throw e } - core.warning(`Reference ${newReference.data.ref} available at ${newReference.data.url}` + os.EOL) + this._uri = newReference.data.url + this._ref = newReference.data.ref - // Store values for other actions - if (typeof newTag === 'object' && typeof newReference === 'object') { - core.setOutput('tagname', this.name) - core.setOutput('tagsha', newTag.data.sha) - core.setOutput('taguri', newReference.data.url) - core.setOutput('tagmessage', this.message) - core.setOutput('tagref', newReference.data.ref) - core.setOutput('tagcreated', 'yes') - } + core.warning(`Reference ${newReference.data.ref} available at ${newReference.data.url}` + os.EOL) } else { core.warning('Cannot push tag (it already exists).') } diff --git a/app/main.js b/app/main.js index 5cf0cb4..e9c1e92 100644 --- a/app/main.js +++ b/app/main.js @@ -62,6 +62,11 @@ async function run () { tag.message = core.getInput('tag_message', { required: false }).trim() await tag.push() + core.setOutput('tagname', tag.name) + core.setOutput('tagsha', tag.sha) + core.setOutput('taguri', tag.uri) + core.setOutput('tagmessage', tag.message) + core.setOutput('tagref', tag.ref) core.setOutput('tagcreated', 'yes') } catch (error) { core.warning(error.message) From 85976544cfeab395db45743527da9dc7fc236247 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 14:28:38 -0500 Subject: [PATCH 31/56] WIP --- app/lib/tag.js | 2 +- app/main.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/lib/tag.js b/app/lib/tag.js index 84128e6..f2bdf2a 100644 --- a/app/lib/tag.js +++ b/app/lib/tag.js @@ -116,11 +116,11 @@ export default class Tag { type: 'commit' }) + this._sha = newTag.data.sha core.warning(`Created new tag: ${newTag.data.tag}`) // Create reference let newReference - this._sha = newTag.data.sha try { newReference = await github.git.createRef({ diff --git a/app/main.js b/app/main.js index e9c1e92..88f349a 100644 --- a/app/main.js +++ b/app/main.js @@ -51,6 +51,8 @@ async function run () { core.getInput('tag_suffix', { required: false }) ) + core.warning(`Attempting to create ${tag.name} tag.`) + // Check for existance of tag and abort (short circuit) if it already exists. if (await tag.exists()) { core.warning(`"${tag.name}" tag already exists.` + os.EOL) From 4bb6d67f62807f230dd4a3273788cf7466456d8f Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 14:30:35 -0500 Subject: [PATCH 32/56] WIP --- app/lib/tag.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/lib/tag.js b/app/lib/tag.js index f2bdf2a..c4d69f3 100644 --- a/app/lib/tag.js +++ b/app/lib/tag.js @@ -59,7 +59,7 @@ export default class Tag { return changelog.data.commits .map( (commit, i) => - `${i + 1}) ${commit.commit.message}${ + `${i === 0 ? '\n' : ''}${i + 1}) ${commit.commit.message}${ commit.hasOwnProperty('author') ? commit.author.hasOwnProperty('login') ? ' (' + commit.author.login + ')' From c1107f97e57a3f36cd489ffa84a9bed1c3e07cfe Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 21:27:59 -0500 Subject: [PATCH 33/56] Add Docker test --- .github/workflows/test.yml | 34 ++++++++++++++++++++++++++++++---- Dockerfile | 1 + 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 39ad780..b843ef1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,8 +6,8 @@ on: - master jobs: - test: - name: Test Suite + package: + name: Test Suite - Package Strategy runs-on: ubuntu-latest steps: # Checkout updated source code @@ -18,7 +18,7 @@ jobs: id: autotagger uses: butlerlogic/action-autotag@master with: - tag_prefix: 'test_' + tag_prefix: 'test_package_' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -28,4 +28,30 @@ jobs: with: tag: ${{ steps.autotagger.outputs.tagname }} env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + docker: + name: Test Suite - Docker Strategy + runs-on: ubuntu-latest + steps: + # Checkout updated source code + - uses: actions/checkout@v2 + + # If the version has changed, create a new git tag for it. + - name: Tag + id: autotagger + uses: butlerlogic/action-autotag@master + with: + strategy: docker + tag_prefix: 'test_docker_' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Rollback Release + if: success() && ${{ steps.autotagger.outputs.tagcreated }} = "yes" + uses: author/action-rollback@stable + with: + tag: ${{ steps.autotagger.outputs.tagname }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 465b711..44a6dcd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ FROM node:13-alpine +LABEL version=1.1.0 ADD ./app /app WORKDIR /app RUN cd /app && npm i From 60bbb766e6d52d7b431abf3e55018d485343da73 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 21:46:06 -0500 Subject: [PATCH 34/56] Use the master branch of the rollback action --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b843ef1..78d2821 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,7 +24,7 @@ jobs: - name: Rollback Release if: success() && ${{ steps.autotagger.outputs.tagcreated }} = "yes" - uses: author/action-rollback@stable + uses: author/action-rollback@master with: tag: ${{ steps.autotagger.outputs.tagname }} env: @@ -49,7 +49,7 @@ jobs: - name: Rollback Release if: success() && ${{ steps.autotagger.outputs.tagcreated }} = "yes" - uses: author/action-rollback@stable + uses: author/action-rollback@master with: tag: ${{ steps.autotagger.outputs.tagname }} env: From 4acc6d3811133141755efd1c43094309103e0b58 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 21:50:37 -0500 Subject: [PATCH 35/56] Update config to remove orphan tags --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 78d2821..f8c4d27 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,6 +27,7 @@ jobs: uses: author/action-rollback@master with: tag: ${{ steps.autotagger.outputs.tagname }} + delete_orphan_tag: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -52,6 +53,7 @@ jobs: uses: author/action-rollback@master with: tag: ${{ steps.autotagger.outputs.tagname }} + delete_orphan_tag: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From 862d691cac16b6d7e5756b51d4282eb3743f18e8 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 21:52:41 -0500 Subject: [PATCH 36/56] Update workflow config --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f8c4d27..8e0e261 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,7 +18,7 @@ jobs: id: autotagger uses: butlerlogic/action-autotag@master with: - tag_prefix: 'test_package_' + tag_prefix: test_package_ env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -44,7 +44,7 @@ jobs: uses: butlerlogic/action-autotag@master with: strategy: docker - tag_prefix: 'test_docker_' + tag_prefix: test_docker_ env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 524efb95f2c44d94f07ad0153eda916929bd75ad Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 22:19:36 -0500 Subject: [PATCH 37/56] Added a tagrequested output for rollback purposes. --- .github/workflows/test.yml | 8 ++++---- README.md | 1 + action.yml | 6 ++++-- app/main.js | 1 + 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8e0e261..e30655e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,7 +26,7 @@ jobs: if: success() && ${{ steps.autotagger.outputs.tagcreated }} = "yes" uses: author/action-rollback@master with: - tag: ${{ steps.autotagger.outputs.tagname }} + tag: ${{ steps.autotagger.outputs.tagrequested }} delete_orphan_tag: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -40,7 +40,7 @@ jobs: # If the version has changed, create a new git tag for it. - name: Tag - id: autotagger + id: docker_autotagger uses: butlerlogic/action-autotag@master with: strategy: docker @@ -49,10 +49,10 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Rollback Release - if: success() && ${{ steps.autotagger.outputs.tagcreated }} = "yes" + if: success() && ${{ steps.docker_autotagger.outputs.tagcreated }} = "yes" uses: author/action-rollback@master with: - tag: ${{ steps.autotagger.outputs.tagname }} + tag: ${{ steps.docker_autotagger.outputs.tagrequested }} delete_orphan_tag: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index ea5f8ca..3394062 100644 --- a/README.md +++ b/README.md @@ -156,6 +156,7 @@ If you are building an action that runs after this one, be aware this action pro 1. `taguri`: The URI/URL of the new tag reference. 1. `tagmessage`: The messge applied to the tag reference (this is what shows up on the tag screen on Github). 1. `tagcreated`: `yes` or `no`. +1. `tagrequested`: The name of the requested tag. This will be populated even if the tag is not created. This will usually be the same as `tagname` and/or `version` for successful executions. 1. `version` will be the version attribute found in the `package.json` file. --- diff --git a/action.yml b/action.yml index 52f5a6a..8a912d5 100644 --- a/action.yml +++ b/action.yml @@ -40,10 +40,12 @@ outputs: description: The URI/URL of the new tag reference. 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 or explicitly set in the input. tagcreated: description: A "yes" or "no", indicating a new tag was created. + tagrequested: + description: The name of the requested tag. This will be populated even if the tag is not created. + version: + description: The version, as defined in package.json or explicitly set in the input. runs: using: 'docker' image: 'Dockerfile' diff --git a/app/main.js b/app/main.js index 88f349a..64cb3ae 100644 --- a/app/main.js +++ b/app/main.js @@ -52,6 +52,7 @@ async function run () { ) core.warning(`Attempting to create ${tag.name} tag.`) + core.setOutput('tagrequested', tag.name) // Check for existance of tag and abort (short circuit) if it already exists. if (await tag.exists()) { From a4c8b247d031851edc1ce10b29c1959e49598cfd Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 1 Apr 2020 22:26:00 -0500 Subject: [PATCH 38/56] Update test workflow --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e30655e..845858d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,7 +22,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Rollback Release + - name: Rollback Package Test Release if: success() && ${{ steps.autotagger.outputs.tagcreated }} = "yes" uses: author/action-rollback@master with: @@ -48,7 +48,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Rollback Release + - name: Rollback Docker Test Release if: success() && ${{ steps.docker_autotagger.outputs.tagcreated }} = "yes" uses: author/action-rollback@master with: From cabb57289c1a9c2220c41928dc790b4aaa666338 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Thu, 2 Apr 2020 13:45:21 -0500 Subject: [PATCH 39/56] Attempting to force a refresh of the action --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 845858d..cccbaa4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: Action Test +name: Autotag Action Test on: push: From f261e8be6d46f1142591055eee486b75d291f127 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Thu, 2 Apr 2020 13:58:51 -0500 Subject: [PATCH 40/56] Fix import for Docker strategy --- app/main.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/main.js b/app/main.js index 64cb3ae..cc61325 100644 --- a/app/main.js +++ b/app/main.js @@ -4,6 +4,7 @@ import Setup from './lib/setup.js' import Package from './lib/package.js' import Tag from './lib/tag.js' import Regex from './lib/regex.js' +import Dockerfile from './lib/docker.js' async function run () { try { From 160de0dcc163820669ea8af730f0edaa43b8a2ad Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Thu, 2 Apr 2020 14:06:17 -0500 Subject: [PATCH 41/56] Update tests --- .github/workflows/test.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cccbaa4..3294e82 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,7 @@ jobs: # If the version has changed, create a new git tag for it. - name: Tag - id: autotagger + id: package_autotagger uses: butlerlogic/action-autotag@master with: tag_prefix: test_package_ @@ -23,14 +23,14 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Rollback Package Test Release - if: success() && ${{ steps.autotagger.outputs.tagcreated }} = "yes" + id: package_rollback + if: success() && ${{ steps.package_autotagger.outputs.tagcreated }} = "yes" uses: author/action-rollback@master with: - tag: ${{ steps.autotagger.outputs.tagrequested }} + tag: ${{ steps.package_autotagger.outputs.tagrequested }} delete_orphan_tag: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - docker: name: Test Suite - Docker Strategy runs-on: ubuntu-latest @@ -49,6 +49,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Rollback Docker Test Release + id: docker_rollback if: success() && ${{ steps.docker_autotagger.outputs.tagcreated }} = "yes" uses: author/action-rollback@master with: From 887f931751eabb86d38576ceccf67a39d8a6a926 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Thu, 2 Apr 2020 16:49:51 -0500 Subject: [PATCH 42/56] Update Docker debugging. --- app/lib/docker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/lib/docker.js b/app/lib/docker.js index e2764d9..c08d333 100644 --- a/app/lib/docker.js +++ b/app/lib/docker.js @@ -5,7 +5,7 @@ import fs from 'fs' export default class Dockerfile extends Regex { constructor (root = null) { root = path.join(process.env.GITHUB_WORKSPACE, root) - + core.debug(fs.readdirSync(root)) if (fs.statSync(root).isDirectory()) { root = path.join(root, 'Dockerfile') } From f1b8052ccb7f8e2a52bebafa6ee80f3e94ce3282 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Thu, 2 Apr 2020 17:32:37 -0500 Subject: [PATCH 43/56] Combine test suites --- .github/workflows/test.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3294e82..b59a408 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,12 +31,12 @@ jobs: delete_orphan_tag: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - docker: - name: Test Suite - Docker Strategy - runs-on: ubuntu-latest - steps: - # Checkout updated source code - - uses: actions/checkout@v2 + # docker: + # name: Test Suite - Docker Strategy + # runs-on: ubuntu-latest + # steps: + # # Checkout updated source code + # - uses: actions/checkout@v2 # If the version has changed, create a new git tag for it. - name: Tag From 1c4e61b4be6821737baed7b73fb4ec02c17cbb8c Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Thu, 2 Apr 2020 17:34:29 -0500 Subject: [PATCH 44/56] Deconstruct test suites --- .github/workflows/test.yml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b59a408..4655604 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,12 +31,12 @@ jobs: delete_orphan_tag: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # docker: - # name: Test Suite - Docker Strategy - # runs-on: ubuntu-latest - # steps: - # # Checkout updated source code - # - uses: actions/checkout@v2 + docker: + name: Test Suite - Docker Strategy + runs-on: ubuntu-latest + steps: + # Checkout updated source code + - uses: actions/checkout@v2 # If the version has changed, create a new git tag for it. - name: Tag @@ -49,12 +49,13 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Rollback Docker Test Release - id: docker_rollback + id: docker_rolback if: success() && ${{ steps.docker_autotagger.outputs.tagcreated }} = "yes" uses: author/action-rollback@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: tag: ${{ steps.docker_autotagger.outputs.tagrequested }} delete_orphan_tag: true - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + \ No newline at end of file From 2e9f255e99dd3ba0de256b80bce406bc008cfb9a Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Thu, 2 Apr 2020 17:41:10 -0500 Subject: [PATCH 45/56] Attempting to rebuild action --- .github/workflows/{test.yml => tests.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{test.yml => tests.yml} (100%) diff --git a/.github/workflows/test.yml b/.github/workflows/tests.yml similarity index 100% rename from .github/workflows/test.yml rename to .github/workflows/tests.yml From f316daf728818abcf4e7063eb84c7538b0b15e31 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Thu, 2 Apr 2020 17:51:08 -0500 Subject: [PATCH 46/56] Rebuild action container --- .github/workflows/{tests.yml => test.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{tests.yml => test.yml} (100%) diff --git a/.github/workflows/tests.yml b/.github/workflows/test.yml similarity index 100% rename from .github/workflows/tests.yml rename to .github/workflows/test.yml From 95ec889024296f9bf5073d9a23d6319a98fca3f3 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Thu, 2 Apr 2020 21:19:07 -0500 Subject: [PATCH 47/56] Update test config --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4655604..549ddc7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,7 +14,7 @@ jobs: - uses: actions/checkout@v2 # If the version has changed, create a new git tag for it. - - name: Tag + - name: Tag Package id: package_autotagger uses: butlerlogic/action-autotag@master with: @@ -39,7 +39,7 @@ jobs: - uses: actions/checkout@v2 # If the version has changed, create a new git tag for it. - - name: Tag + - name: Tag Dockerfile id: docker_autotagger uses: butlerlogic/action-autotag@master with: From 31cd8a5211452684864e8c973ebfdc87b67469cb Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Thu, 2 Apr 2020 21:26:17 -0500 Subject: [PATCH 48/56] Use the alternative config for the rollback process. --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 549ddc7..dbba436 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -53,6 +53,7 @@ jobs: if: success() && ${{ steps.docker_autotagger.outputs.tagcreated }} = "yes" uses: author/action-rollback@master env: + TAG: ${{ steps.docker_autotagger.outputs.tagrequested }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: tag: ${{ steps.docker_autotagger.outputs.tagrequested }} From 474294ced56ea72a1d71153d3ab0ac3cc6291edb Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Thu, 2 Apr 2020 23:17:44 -0500 Subject: [PATCH 49/56] Update docker strategy --- app/lib/docker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/lib/docker.js b/app/lib/docker.js index c08d333..e2764d9 100644 --- a/app/lib/docker.js +++ b/app/lib/docker.js @@ -5,7 +5,7 @@ import fs from 'fs' export default class Dockerfile extends Regex { constructor (root = null) { root = path.join(process.env.GITHUB_WORKSPACE, root) - core.debug(fs.readdirSync(root)) + if (fs.statSync(root).isDirectory()) { root = path.join(root, 'Dockerfile') } From dec8dcd1af4084079c8a00ee9cb60b606c30e865 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Thu, 2 Apr 2020 23:19:41 -0500 Subject: [PATCH 50/56] WIP --- app/lib/docker.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/lib/docker.js b/app/lib/docker.js index e2764d9..b9c767b 100644 --- a/app/lib/docker.js +++ b/app/lib/docker.js @@ -1,11 +1,12 @@ import Regex from './regex.js' import path from 'path' import fs from 'fs' +import core from '@actions/core' export default class Dockerfile extends Regex { constructor (root = null) { root = path.join(process.env.GITHUB_WORKSPACE, root) - + core.debug(fs.readdirSync(root)) if (fs.statSync(root).isDirectory()) { root = path.join(root, 'Dockerfile') } From b30eee16868144e1b69a031a6ee5acccc145fee0 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Thu, 2 Apr 2020 23:38:10 -0500 Subject: [PATCH 51/56] Fixed path issues in regex strategy --- app/lib/docker.js | 2 +- app/lib/regex.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/lib/docker.js b/app/lib/docker.js index b9c767b..c177ded 100644 --- a/app/lib/docker.js +++ b/app/lib/docker.js @@ -6,7 +6,7 @@ import core from '@actions/core' export default class Dockerfile extends Regex { constructor (root = null) { root = path.join(process.env.GITHUB_WORKSPACE, root) - core.debug(fs.readdirSync(root)) + if (fs.statSync(root).isDirectory()) { root = path.join(root, 'Dockerfile') } diff --git a/app/lib/regex.js b/app/lib/regex.js index c34ba90..a86d1df 100644 --- a/app/lib/regex.js +++ b/app/lib/regex.js @@ -2,8 +2,8 @@ import fs from 'fs' import path from 'path' export default class Regex { - constructor (root = null, pattern) { - root = path.join(process.env.GITHUB_WORKSPACE, root) + constructor (root = './', pattern) { + root = path.resolve(root) if (fs.statSync(root).isDirectory()) { throw new Error(`${root} is a directory. The Regex tag identification strategy requires a file.`) From f0d209c27a35804118065c979592830fd1ab86ed Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Fri, 3 Apr 2020 00:22:43 -0500 Subject: [PATCH 52/56] Added simplistic commit message template --- README.md | 20 ++++++++++++++++++++ action.yml | 3 +++ app/lib/tag.js | 26 ++++++++++++++++++-------- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3394062..bef8938 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,26 @@ This is the annotated commit message associated with the tag. By default, a chan tag_message: "Custom message goes here." ``` +#### commit_message_template + +By default, a changelog is generated, containing the commit messages since the last release. The message is generated by applying a commit message template to each commit's data attributes. + +```yaml +- uses: butlerlogic/action-autotag@1.0.0 + with: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + commit_message_template: "({{sha}} by {{author}}) {{message}}" +``` + +Optional data points: + +1. `number` The commit number (relevant to the overall list) +1. `message` The commit message. +1. `author` The author of the commit. +1. `sha` The SHA value representing the commit. + +The default is `{{number}}) {{message}} ({{author}})\nSHA: {{sha}}\n`. + #### version Explicitly set the version instead of using automatic detection. diff --git a/action.yml b/action.yml index 8a912d5..01e0c90 100644 --- a/action.yml +++ b/action.yml @@ -25,6 +25,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 + commit_message_template: + description: "The commit message template (per commit). Default is `{{number}}) {{message}} ({{author}})\nSHA: {{sha}}\n`" + 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 diff --git a/app/lib/tag.js b/app/lib/tag.js index c4d69f3..857c45b 100644 --- a/app/lib/tag.js +++ b/app/lib/tag.js @@ -55,18 +55,28 @@ export default class Tag { } const changelog = await github.repos.compareCommits({ owner, repo, base: tags.shift().name, head: 'master' }) + const tpl = (core.getInput('commit_message_template', { required: false }) || '').trim() return changelog.data.commits .map( - (commit, i) => - `${i === 0 ? '\n' : ''}${i + 1}) ${commit.commit.message}${ - commit.hasOwnProperty('author') - ? commit.author.hasOwnProperty('login') - ? ' (' + commit.author.login + ')' + (commit, i) => { + if (tpl.length > 0) { + return tpl + .replace(/\{\{\s?(number)\s?\}\}/gi, i + 1) + .replace(/\{\{\s?(message)\s?\}\}/gi, commit.commit.message) + .replace(/\{\{\s?(author)\s?\}\}/gi, commit.hasOwnProperty('author') ? (commit.author.hasOwnProperty('login') ? commit.author.login : '') : '') + .replace(/\{\{\s?(sha)\s?\}\}/gi, commit.sha) + .trim() + '\n' + } else { + return `${i === 0 ? '\n' : ''}${i + 1}) ${commit.commit.message}${ + commit.hasOwnProperty('author') + ? commit.author.hasOwnProperty('login') + ? ' (' + commit.author.login + ')' + : '' : '' - : '' - }\n(SHA: ${commit.sha})\n` - ) + }\n(SHA: ${commit.sha})\n` + } + }) .join('\n') } catch (e) { core.warning('Failed to generate changelog from commits: ' + e.message + os.EOL) From 3dc92cf2ce002bb19bd7e8917e18d2ec5f572b44 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Fri, 3 Apr 2020 00:24:07 -0500 Subject: [PATCH 53/56] Added test commit template --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dbba436..1c786c7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,6 +19,7 @@ jobs: uses: butlerlogic/action-autotag@master with: tag_prefix: test_package_ + commit_message_template: "{{number}}) {{message}} ({{author}})\n" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 4421fbc5996af45cf09c601d0a0204c5c2719029 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Fri, 3 Apr 2020 00:25:07 -0500 Subject: [PATCH 54/56] Testing template --- .github/workflows/test.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1c786c7..8fb04a5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,15 +23,15 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Rollback Package Test Release - id: package_rollback - if: success() && ${{ steps.package_autotagger.outputs.tagcreated }} = "yes" - uses: author/action-rollback@master - with: - tag: ${{ steps.package_autotagger.outputs.tagrequested }} - delete_orphan_tag: true - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # - name: Rollback Package Test Release + # id: package_rollback + # if: success() && ${{ steps.package_autotagger.outputs.tagcreated }} = "yes" + # uses: author/action-rollback@master + # with: + # tag: ${{ steps.package_autotagger.outputs.tagrequested }} + # delete_orphan_tag: true + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} docker: name: Test Suite - Docker Strategy runs-on: ubuntu-latest From 6b4b577860dbabde8183cf55ac11421644be0fdc Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Fri, 3 Apr 2020 00:26:50 -0500 Subject: [PATCH 55/56] Reimplemented rollback of test tags --- .github/workflows/test.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8fb04a5..1c786c7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,15 +23,15 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # - name: Rollback Package Test Release - # id: package_rollback - # if: success() && ${{ steps.package_autotagger.outputs.tagcreated }} = "yes" - # uses: author/action-rollback@master - # with: - # tag: ${{ steps.package_autotagger.outputs.tagrequested }} - # delete_orphan_tag: true - # env: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Rollback Package Test Release + id: package_rollback + if: success() && ${{ steps.package_autotagger.outputs.tagcreated }} = "yes" + uses: author/action-rollback@master + with: + tag: ${{ steps.package_autotagger.outputs.tagrequested }} + delete_orphan_tag: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} docker: name: Test Suite - Docker Strategy runs-on: ubuntu-latest From c86980ec1b45b1c5b198287778a47b86e2a04c30 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Fri, 3 Apr 2020 00:29:42 -0500 Subject: [PATCH 56/56] Changed description to meet Github length guidelines. --- action.yml | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 01e0c90..a8e9048 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,5 @@ name: "Autotagger" -description: "Automatically generate new tags for new versions. Supports several tagging strategies, including package.json, Dockerfiles, and Regex." +description: "Automatically generate new tags for new versions. Supports several tagging strategies." author: "Butler Logic" branding: icon: "tag" diff --git a/package.json b/package.json index 4b61073..f622d30 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "action-autotag-test", - "version": "1.0.0", + "version": "1.1.0", "description": "This is a test file for the action.", "main": "index.js", "dependencies": {},