Skip to content

Commit

Permalink
feat: add update-tags action
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Jun 2, 2022
1 parent 4a3a747 commit 1acc215
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 41 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ jobs:
with:
token: ${{ secrets.GH_REPO_TOKEN }}

- run: |
version=$(git describe --abbrev=0 --tags)
node publish.js "$version"
git push --tags
- uses: myparcelnl/actions/update-tags@main
with:
minor: true
env:
GITHUB_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Will use every patch update within `v2.1.x`.
- [semantic-release](#semantic-release)
- [Git](#git)
- [setup-git-credentials](#setup-git-credentials)
- [rebase](#rebase)
- [update-tags](#update-tags)

## Node

Expand Down Expand Up @@ -248,6 +250,43 @@ Rebase two branches and push.
target: develop
```

### update-tags

[Source](update-tags/action.yml)

Update git tags to keep major and minor version in sync. Good for releasing
GitHub actions.

#### Inputs

| required | name | description | Example | Default |
|----------|---------|---------------------------|---------|---------|
| No | `minor` | Update the major version. | `true` | `true` |
| No | `major` | Update the minor version. | `true` | `false` |

#### Example

```yaml
- uses: myparcelnl/actions/update-tags@v2
with:
minor: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```

This takes the tag on the current commit, for example `v2.3.1` after
running [semantic-release], and parses it to determine which tags should be
updated.

If run with `minor: true`:

- Will add `v2` to the current commit
- Will add `v2.3` to the current commit

If run without `minor: true`, or with `minor: false`:

- Will add `v2` to the current commit.

[Codecov]: https://codecov.io
[actions/setup-node]: https://github.com/actions/setup-node
[build-docker-image]: #build-docker-image
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"license": "MIT",
"author": "Edie Lemoine <edie@myparcel.nl>",
"devDependencies": {
"@actions/core": "^1.8.2",
"@actions/github": "^5.0.3",
"@myparcel/semantic-release-config": "^3.0.0",
"semver": "^7.3.7"
}
Expand Down
28 changes: 0 additions & 28 deletions publish.js

This file was deleted.

3 changes: 0 additions & 3 deletions release.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ module.exports = {
...baseConfig,
plugins: [
...baseConfig.plugins,
addExecPlugin({
'publishCmd': 'node ./publish.js ${nextRelease.version}',
}),
addGitPlugin(),
addGitHubPlugin(),
],
Expand Down
17 changes: 17 additions & 0 deletions update-tags/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: 'Update tags'
description: 'Update major and (optionally) minor tags.'

inputs:
major:
required: false
description: 'Update the major version.'
default: 'true'

minor:
required: false
default: 'false'
description: 'Update the minor version.'

runs:
using: 'node16'
main: 'index.js'
48 changes: 48 additions & 0 deletions update-tags/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const core = require('@actions/core');

const { major, minor, prerelease } = require('semver');
const { spawnSync } = require('child_process');

const updateTags = () => {
const lastTagRef = spawnSync('git', ['rev-list', '--tags', '--max-count=1']).stdout.toString().trim();
const version = spawnSync('git', ['describe', '--tags', lastTagRef]).stdout.toString().trim();

const updateMajor = core.getBooleanInput('major');
const updateMinor = core.getBooleanInput('minor');

if (prerelease(version)) {
core.info('Prerelease version detected; will not add a major version update-tags.');
return;
}

const versionTags = [];

if (updateMajor) {
versionTags.push(major(version));
}

if (updateMinor) {
versionTags.push(`${major(version)}.${minor(version)}`);
}

const ref = spawnSync('git', ['show-ref', '-s', version]).stdout.toString();

versionTags.forEach(tag => {
const tagName = `v${tag}`;

core.info(`Deleting tag "${tagName}"`);
spawnSync('git', ['push', 'origin', `:refs/tags/v${tagName}`], { stdio: 'inherit' });

core.info(`Creating new tag "${tagName}" on ${ref}`);
spawnSync('git', ['tag', '--force', `v${tagName}`, ref], { stdio: 'inherit' });
});

core.info('Pushing tags');
spawnSync('git', ['push', '--tags'])
};

try {
updateTags();
} catch (e) {
core.setFailed(e.message);
}
41 changes: 35 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@
# yarn lockfile v1


"@actions/core@^1.8.2":
version "1.8.2"
resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.8.2.tgz#67539d669ae9b751430469e9ae4d83e0525973ac"
integrity sha512-FXcBL7nyik8K5ODeCKlxi+vts7torOkoDAKfeh61EAkAy1HAvwn9uVzZBY0f15YcQTcZZ2/iSGBFHEuioZWfDA==
dependencies:
"@actions/http-client" "^2.0.1"

"@actions/github@^5.0.3":
version "5.0.3"
resolved "https://registry.yarnpkg.com/@actions/github/-/github-5.0.3.tgz#b305765d6173962d113451ea324ff675aa674f35"
integrity sha512-myjA/pdLQfhUGLtRZC/J4L1RXOG4o6aYdiEq+zr5wVVKljzbFld+xv10k1FX6IkIJtNxbAq44BdwSNpQ015P0A==
dependencies:
"@actions/http-client" "^2.0.1"
"@octokit/core" "^3.6.0"
"@octokit/plugin-paginate-rest" "^2.17.0"
"@octokit/plugin-rest-endpoint-methods" "^5.13.0"

"@actions/http-client@^2.0.1":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@actions/http-client/-/http-client-2.0.1.tgz#873f4ca98fe32f6839462a6f046332677322f99c"
integrity sha512-PIXiMVtz6VvyaRsGY268qvj57hXQEpsYogYOu2nrQhlf+XCGmZstmuZBbAybUl1nQGnvS1k1eEsQ69ZoD7xlSw==
dependencies:
tunnel "^0.0.6"

"@babel/code-frame@^7.0.0":
version "7.16.7"
resolved "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.16.7.tgz"
Expand Down Expand Up @@ -248,9 +272,9 @@
dependencies:
"@octokit/types" "^6.0.3"

"@octokit/core@^3.5.1":
"@octokit/core@^3.5.1", "@octokit/core@^3.6.0":
version "3.6.0"
resolved "https://registry.npmjs.org/@octokit/core/-/core-3.6.0.tgz"
resolved "https://registry.yarnpkg.com/@octokit/core/-/core-3.6.0.tgz#3376cb9f3008d9b3d110370d90e0a1fcd5fe6085"
integrity sha512-7RKRKuA4xTjMhY+eG3jthb3hlZCsOwg3rztWh75Xc+ShDWOfDDATWbeZpAHBNRpm4Tv9WgBMOy1zEJYXG6NJ7Q==
dependencies:
"@octokit/auth-token" "^2.4.4"
Expand Down Expand Up @@ -284,9 +308,9 @@
resolved "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-11.2.0.tgz"
integrity sha512-PBsVO+15KSlGmiI8QAzaqvsNlZlrDlyAJYcrXBCvVUxCp7VnXjkwPoFHgjEJXx3WF9BAwkA6nfCUA7i9sODzKA==

"@octokit/plugin-paginate-rest@^2.16.8":
"@octokit/plugin-paginate-rest@^2.16.8", "@octokit/plugin-paginate-rest@^2.17.0":
version "2.17.0"
resolved "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-2.17.0.tgz"
resolved "https://registry.yarnpkg.com/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-2.17.0.tgz#32e9c7cab2a374421d3d0de239102287d791bce7"
integrity sha512-tzMbrbnam2Mt4AhuyCHvpRkS0oZ5MvwwcQPYGtMv4tUa5kkzG58SVB0fcsLulOZQeRnOgdkZWkRUiyBlh0Bkyw==
dependencies:
"@octokit/types" "^6.34.0"
Expand All @@ -296,9 +320,9 @@
resolved "https://registry.npmjs.org/@octokit/plugin-request-log/-/plugin-request-log-1.0.4.tgz"
integrity sha512-mLUsMkgP7K/cnFEw07kWqXGF5LKrOkD+lhCrKvPHXWDywAwuDUeDwWBpc69XK3pNX0uKiVt8g5z96PJ6z9xCFA==

"@octokit/plugin-rest-endpoint-methods@^5.12.0":
"@octokit/plugin-rest-endpoint-methods@^5.12.0", "@octokit/plugin-rest-endpoint-methods@^5.13.0":
version "5.13.0"
resolved "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-5.13.0.tgz"
resolved "https://registry.yarnpkg.com/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-5.13.0.tgz#8c46109021a3412233f6f50d28786f8e552427ba"
integrity sha512-uJjMTkN1KaOIgNtUPMtIXDOjx6dGYysdIFhgA52x4xSadQCz3b/zJexvITDVpANnfKPW/+E0xkOvLntqMYpviA==
dependencies:
"@octokit/types" "^6.34.0"
Expand Down Expand Up @@ -3145,6 +3169,11 @@ trim-newlines@^3.0.0:
resolved "https://registry.npmjs.org/trim-newlines/-/trim-newlines-3.0.1.tgz"
integrity sha512-c1PTsA3tYrIsLGkJkzHF+w9F2EyxfXGo4UyJc4pFL++FMjnq0HJS69T3M7d//gKrFKwy429bouPescbjecU+Zw==

tunnel@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/tunnel/-/tunnel-0.0.6.tgz#72f1314b34a5b192db012324df2cc587ca47f92c"
integrity sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==

type-fest@^0.16.0:
version "0.16.0"
resolved "https://registry.npmjs.org/type-fest/-/type-fest-0.16.0.tgz"
Expand Down

0 comments on commit 1acc215

Please sign in to comment.