mirror of
https://github.com/jimeh/update-tags-action.git
synced 2026-02-19 09:36:41 +00:00
Compare commits
74 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f709bf4521 | ||
|
|
713ef57d6a | ||
|
|
9faf3c9e39 | ||
|
|
2a6efacda6 | ||
|
|
00f9f5b105 | ||
|
|
b159afa635 | ||
|
|
e9e6aa35a8 | ||
| d92b2d6009 | |||
|
|
9debb9deac | ||
|
|
36243fb9d3 | ||
|
|
98d6d448de | ||
| fee5cc2ff2 | |||
| facf303096 | |||
| 5dc277d712 | |||
| 32e66b04be | |||
| 1d171e9f3c | |||
| 6adab3a060 | |||
| ef41989077 | |||
| bb3e44be2f | |||
|
|
46ebed28cc | ||
|
|
04e502b026 | ||
|
|
fa63dca88c | ||
|
|
6593b10eb9 | ||
| daa038fd7f | |||
| 5580fd8611 | |||
| aa16a0ff75 | |||
| 741ed40bb7 | |||
| a25f37f9e6 | |||
|
|
82dc01ff9e | ||
|
|
1d0890efd6 | ||
|
|
fcb6d5925b | ||
|
|
ecd1432d26 | ||
|
|
73adb32d6a | ||
|
|
0b1a9ea25d | ||
|
|
88c489d592 | ||
|
|
4e16af70e2 | ||
|
|
88edfaa38b | ||
|
|
838b7bd8a1 | ||
|
|
2df44e1d6e | ||
|
|
e33b26678f | ||
| ce60e958b3 | |||
|
|
441aa939fd | ||
| af088380e8 | |||
|
|
d2bac049db | ||
| b18dece8b1 | |||
| 5f14685d44 | |||
| 605c1cfa34 | |||
| bd3bacec30 | |||
| 389bd20c41 | |||
| 38ccbb6879 | |||
| 9016fb217e | |||
|
|
ca138ceed8 | ||
|
|
eecd8caae9 | ||
| 6723e4d4ac | |||
| 92bdad7a4a | |||
| 1576a544fe | |||
| 2b1c01b3ed | |||
| 73e6309596 | |||
|
|
08138ee77f | ||
| c2d45bd3ef | |||
|
|
f44ca97378 | ||
| 1041193aa6 | |||
| 4db4cf0ae7 | |||
| 78da350f05 | |||
| c0954ab20f | |||
| f690607ffe | |||
| 20206210a0 | |||
| c1b031da4b | |||
| 40c0c24c34 | |||
| 2cb31b2a0a | |||
| 5a403d344e | |||
| 99a7d3ae1f | |||
| bdda9e7570 | |||
| ba01e004ad |
2
.github/.release-please-manifest.json
vendored
2
.github/.release-please-manifest.json
vendored
@@ -1,3 +1,3 @@
|
||||
{
|
||||
".": "2.0.0"
|
||||
".": "2.3.0"
|
||||
}
|
||||
|
||||
6
.github/dependabot.yml
vendored
6
.github/dependabot.yml
vendored
@@ -6,8 +6,9 @@ updates:
|
||||
schedule:
|
||||
interval: weekly
|
||||
groups:
|
||||
actions-minor:
|
||||
actions:
|
||||
update-types:
|
||||
- major
|
||||
- minor
|
||||
- patch
|
||||
- package-ecosystem: npm
|
||||
@@ -18,9 +19,12 @@ updates:
|
||||
npm-development:
|
||||
dependency-type: development
|
||||
update-types:
|
||||
- major
|
||||
- minor
|
||||
- patch
|
||||
npm-production:
|
||||
dependency-type: production
|
||||
update-types:
|
||||
- major
|
||||
- minor
|
||||
- patch
|
||||
|
||||
19
.github/release-please-config.json
vendored
19
.github/release-please-config.json
vendored
@@ -1,15 +1,30 @@
|
||||
{
|
||||
"always-update": true,
|
||||
"packages": {
|
||||
".": {
|
||||
"release-type": "simple",
|
||||
"release-type": "node",
|
||||
"changelog-path": "CHANGELOG.md",
|
||||
"extra-files": ["README.md"],
|
||||
"bump-minor-pre-major": true,
|
||||
"bump-patch-for-minor-pre-major": true,
|
||||
"draft": false,
|
||||
"prerelease": false,
|
||||
"initial-version": "0.0.1"
|
||||
"include-component-in-tag": false
|
||||
}
|
||||
},
|
||||
"changelog-sections": [
|
||||
{ "type": "feat", "section": "Features" },
|
||||
{ "type": "feature", "section": "Features" },
|
||||
{ "type": "fix", "section": "Bug Fixes" },
|
||||
{ "type": "perf", "section": "Performance Improvements" },
|
||||
{ "type": "revert", "section": "Reverts" },
|
||||
{ "type": "docs", "section": "Documentation", "hidden": false },
|
||||
{ "type": "style", "section": "Styles", "hidden": true },
|
||||
{ "type": "chore", "section": "Miscellaneous Chores", "hidden": true },
|
||||
{ "type": "refactor", "section": "Code Refactoring", "hidden": true },
|
||||
{ "type": "test", "section": "Tests", "hidden": true },
|
||||
{ "type": "build", "section": "Build System", "hidden": true },
|
||||
{ "type": "ci", "section": "Continuous Integration", "hidden": true }
|
||||
],
|
||||
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json"
|
||||
}
|
||||
|
||||
30
.github/workflows/ci.yml
vendored
30
.github/workflows/ci.yml
vendored
@@ -16,8 +16,8 @@ jobs:
|
||||
check-dist:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
|
||||
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
|
||||
with:
|
||||
node-version-file: .node-version
|
||||
cache: npm
|
||||
@@ -39,7 +39,7 @@ jobs:
|
||||
fi
|
||||
- name: Upload Artifact
|
||||
if: ${{ failure() && steps.diff.outcome == 'failure' }}
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
|
||||
with:
|
||||
name: dist
|
||||
path: dist/
|
||||
@@ -51,10 +51,10 @@ jobs:
|
||||
packages: read
|
||||
statuses: write
|
||||
steps:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
|
||||
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
|
||||
with:
|
||||
node-version-file: .node-version
|
||||
cache: npm
|
||||
@@ -64,10 +64,10 @@ jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
|
||||
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
|
||||
with:
|
||||
node-version-file: .node-version
|
||||
cache: npm
|
||||
@@ -77,27 +77,23 @@ jobs:
|
||||
release-please:
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.ref == 'refs/heads/main' }}
|
||||
needs: [check-dist]
|
||||
outputs:
|
||||
release_created: ${{ steps.release-please.outputs.release_created }}
|
||||
major: ${{ steps.release-please.outputs.major }}
|
||||
minor: ${{ steps.release-please.outputs.minor }}
|
||||
tag_name: ${{ steps.release-please.outputs.tag_name }}
|
||||
steps:
|
||||
- uses: jimeh/release-please-manifest-action@84f33fd2828210488c36f3e0a7e3209252d2ae7d # v3.0.0
|
||||
id: release-please
|
||||
with:
|
||||
app-id: ${{ secrets.RELEASE_BOT_APP_ID }}
|
||||
private-key: ${{ secrets.RELEASE_BOT_PRIVATE_KEY }}
|
||||
app-id: ${{ secrets.BOT_APP_ID }}
|
||||
private-key: ${{ secrets.BOT_PRIVATE_KEY }}
|
||||
|
||||
release-tags:
|
||||
runs-on: ubuntu-latest
|
||||
needs: release-please
|
||||
needs: [release-please, check-dist, lint, test]
|
||||
if: ${{ needs.release-please.outputs.release_created }}
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- uses: jimeh/update-tags-action@e58fa0f2f874a12bf0eb90ef8ab4256808c0f373 # v1.0.1
|
||||
- uses: jimeh/update-tags-action@98d6d448de7488acb52bd8db115673541d019521 # v2.3.0
|
||||
with:
|
||||
tags: |
|
||||
v${{ needs.release-please.outputs.major }}
|
||||
v${{ needs.release-please.outputs.major }}.${{ needs.release-please.outputs.minor }}
|
||||
derive_from: ${{ needs.release-please.outputs.tag_name }}
|
||||
|
||||
27
.github/workflows/copilot-setup-steps.yml
vendored
Normal file
27
.github/workflows/copilot-setup-steps.yml
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
name: "Copilot Setup Steps"
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
paths:
|
||||
- .github/workflows/copilot-setup-steps.yml
|
||||
pull_request:
|
||||
paths:
|
||||
- .github/workflows/copilot-setup-steps.yml
|
||||
|
||||
jobs:
|
||||
copilot-setup-steps:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
steps:
|
||||
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
|
||||
with:
|
||||
node-version-file: .node-version
|
||||
cache: npm
|
||||
- run: npm ci
|
||||
- uses: ruby/setup-ruby@708024e6c902387ab41de36e1669e43b5ee7085e # v1.283.0
|
||||
with:
|
||||
ruby-version: ruby
|
||||
bundler-cache: true
|
||||
62
.github/workflows/dependabot-rebuild.yml
vendored
Normal file
62
.github/workflows/dependabot-rebuild.yml
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
---
|
||||
name: Dependabot Rebuild
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize]
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: read
|
||||
|
||||
jobs:
|
||||
rebuild:
|
||||
runs-on: ubuntu-latest
|
||||
if: |-
|
||||
${{ github.actor == 'dependabot[bot]' && github.event.sender.login == 'dependabot[bot]' }}
|
||||
steps:
|
||||
- name: Generate app token
|
||||
id: app-token
|
||||
uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
|
||||
with:
|
||||
app-id: ${{ secrets.BOT_APP_ID }}
|
||||
private-key: ${{ secrets.BOT_PRIVATE_KEY }}
|
||||
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
with:
|
||||
token: ${{ steps.app-token.outputs.token }}
|
||||
|
||||
# Update and push dist if changed.
|
||||
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
|
||||
with:
|
||||
node-version-file: .node-version
|
||||
cache: npm
|
||||
- run: npm ci
|
||||
- name: Rebuild dist
|
||||
run: npm run bundle
|
||||
- name: Commit and push if changed
|
||||
uses: ryancyq/github-signed-commit@e9f3b28c80da7be66d24b8f501a5abe82a6b855f # v1.2.0
|
||||
env:
|
||||
GH_TOKEN: ${{ steps.app-token.outputs.token }}
|
||||
with:
|
||||
files: |
|
||||
dist/
|
||||
commit-message: |-
|
||||
chore: rebuild dist
|
||||
|
||||
# Update and push .licenses if changed.
|
||||
- uses: ruby/setup-ruby@708024e6c902387ab41de36e1669e43b5ee7085e # v1.283.0
|
||||
with:
|
||||
ruby-version: ruby
|
||||
bundler-cache: true
|
||||
- name: Update Licenses
|
||||
id: update-licenses
|
||||
run: bin/licensed cache
|
||||
- name: Commit and push if changed
|
||||
uses: ryancyq/github-signed-commit@e9f3b28c80da7be66d24b8f501a5abe82a6b855f # v1.2.0
|
||||
env:
|
||||
GH_TOKEN: ${{ steps.app-token.outputs.token }}
|
||||
with:
|
||||
files: |
|
||||
.licenses/
|
||||
commit-message: |-
|
||||
chore(licensed): update license files
|
||||
36
.github/workflows/licensed.yml
vendored
36
.github/workflows/licensed.yml
vendored
@@ -20,13 +20,24 @@ jobs:
|
||||
check-licenses:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
|
||||
# Checkout code using app token.
|
||||
- name: Generate app token
|
||||
id: app-token
|
||||
uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
|
||||
with:
|
||||
app-id: ${{ secrets.BOT_APP_ID }}
|
||||
private-key: ${{ secrets.BOT_PRIVATE_KEY }}
|
||||
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
with:
|
||||
token: ${{ steps.app-token.outputs.token }}
|
||||
|
||||
# Setup Node and Ruby runtimes.
|
||||
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
|
||||
with:
|
||||
node-version-file: .node-version
|
||||
cache: npm
|
||||
- run: npm ci
|
||||
- uses: ruby/setup-ruby@d5126b9b3579e429dd52e51e68624dda2e05be25 # v1.267.0 # v1.266.0
|
||||
- uses: ruby/setup-ruby@708024e6c902387ab41de36e1669e43b5ee7085e # v1.283.0
|
||||
with:
|
||||
ruby-version: ruby
|
||||
bundler-cache: true
|
||||
@@ -36,17 +47,16 @@ jobs:
|
||||
name: Update Licenses
|
||||
id: update-licenses
|
||||
run: bin/licensed cache
|
||||
|
||||
# Then, commit the updated licenses to the repository.
|
||||
- if: ${{ github.event_name == 'workflow_dispatch' }}
|
||||
name: Commit Licenses
|
||||
id: commit-licenses
|
||||
run: |
|
||||
git config --local user.email "licensed-ci@users.noreply.github.com"
|
||||
git config --local user.name "licensed-ci"
|
||||
git add .
|
||||
git commit -m "Auto-update license files"
|
||||
git push
|
||||
name: Commit and push if changed
|
||||
uses: ryancyq/github-signed-commit@e9f3b28c80da7be66d24b8f501a5abe82a6b855f # v1.2.0
|
||||
env:
|
||||
GH_TOKEN: ${{ steps.app-token.outputs.token }}
|
||||
with:
|
||||
files: |
|
||||
.licenses/
|
||||
commit-message: |-
|
||||
chore(licensed): update license files
|
||||
|
||||
# Last, check the status of the cached licenses.
|
||||
- name: Check Licenses
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -98,7 +98,7 @@ typings/
|
||||
Thumbs.db
|
||||
|
||||
# Ignore built ts files
|
||||
__tests__/runner/*
|
||||
tests/runner/*
|
||||
|
||||
# IDE files
|
||||
.idea
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: "@actions/core"
|
||||
version: 1.11.1
|
||||
version: 2.0.2
|
||||
type: npm
|
||||
summary: Actions core lib
|
||||
homepage: https://github.com/actions/toolkit/tree/main/packages/core
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: "@actions/exec"
|
||||
version: 1.1.1
|
||||
version: 2.0.0
|
||||
type: npm
|
||||
summary: Actions exec lib
|
||||
homepage: https://github.com/actions/toolkit/tree/main/packages/exec
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: "@actions/github"
|
||||
version: 6.0.1
|
||||
version: 7.0.0
|
||||
type: npm
|
||||
summary: Actions github lib
|
||||
homepage: https://github.com/actions/toolkit/tree/main/packages/github
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: "@actions/http-client"
|
||||
version: 2.2.3
|
||||
version: 3.0.1
|
||||
type: npm
|
||||
summary: Actions Http Client
|
||||
homepage: https://github.com/actions/toolkit/tree/main/packages/http-client
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: "@actions/io"
|
||||
version: 1.1.3
|
||||
version: 2.0.0
|
||||
type: npm
|
||||
summary: Actions io lib
|
||||
homepage: https://github.com/actions/toolkit/tree/main/packages/io
|
||||
|
||||
36
.licenses/npm/handlebars.dep.yml
Normal file
36
.licenses/npm/handlebars.dep.yml
Normal file
@@ -0,0 +1,36 @@
|
||||
---
|
||||
name: handlebars
|
||||
version: 4.7.8
|
||||
type: npm
|
||||
summary: Handlebars provides the power necessary to let you build semantic templates
|
||||
effectively with no frustration
|
||||
homepage: https://www.handlebarsjs.com/
|
||||
license: mit
|
||||
licenses:
|
||||
- sources: LICENSE
|
||||
text: |
|
||||
Copyright (C) 2011-2019 by Yehuda Katz
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
- sources: README.markdown
|
||||
text: |-
|
||||
Handlebars.js is released under the MIT license.
|
||||
|
||||
[pull-request]: https://github.com/handlebars-lang/handlebars.js/pull/new/master
|
||||
notices: []
|
||||
44
.licenses/npm/minimist.dep.yml
Normal file
44
.licenses/npm/minimist.dep.yml
Normal file
@@ -0,0 +1,44 @@
|
||||
---
|
||||
name: minimist
|
||||
version: 1.2.8
|
||||
type: npm
|
||||
summary: parse argument options
|
||||
homepage: https://github.com/minimistjs/minimist
|
||||
license: other
|
||||
licenses:
|
||||
- sources: LICENSE
|
||||
text: |
|
||||
This software is released under the MIT license:
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
- sources: README.md
|
||||
text: |-
|
||||
MIT
|
||||
|
||||
[package-url]: https://npmjs.org/package/minimist
|
||||
[npm-version-svg]: https://versionbadg.es/minimistjs/minimist.svg
|
||||
[npm-badge-png]: https://nodei.co/npm/minimist.png?downloads=true&stars=true
|
||||
[license-image]: https://img.shields.io/npm/l/minimist.svg
|
||||
[license-url]: LICENSE
|
||||
[downloads-image]: https://img.shields.io/npm/dm/minimist.svg
|
||||
[downloads-url]: https://npm-stat.com/charts.html?package=minimist
|
||||
[codecov-image]: https://codecov.io/gh/minimistjs/minimist/branch/main/graphs/badge.svg
|
||||
[codecov-url]: https://app.codecov.io/gh/minimistjs/minimist/
|
||||
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/minimistjs/minimist
|
||||
[actions-url]: https://github.com/minimistjs/minimist/actions
|
||||
notices: []
|
||||
36
.licenses/npm/neo-async.dep.yml
Normal file
36
.licenses/npm/neo-async.dep.yml
Normal file
@@ -0,0 +1,36 @@
|
||||
---
|
||||
name: neo-async
|
||||
version: 2.6.2
|
||||
type: npm
|
||||
summary: 'Neo-Async is a drop-in replacement for Async, it almost fully covers its
|
||||
functionality and runs faster '
|
||||
homepage: https://github.com/suguru03/neo-async
|
||||
license: other
|
||||
licenses:
|
||||
- sources: LICENSE
|
||||
text: |
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2014-2018 Suguru Motegi
|
||||
Based on Async.js, Copyright Caolan McMahon
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
- sources: README.md
|
||||
text: "[](https://app.fossa.io/projects/git%2Bgithub.com%2Fsuguru03%2Fneo-async?ref=badge_large)"
|
||||
notices: []
|
||||
26
.licenses/npm/semver.dep.yml
Normal file
26
.licenses/npm/semver.dep.yml
Normal file
@@ -0,0 +1,26 @@
|
||||
---
|
||||
name: semver
|
||||
version: 7.7.3
|
||||
type: npm
|
||||
summary: The semantic version parser used by npm.
|
||||
homepage:
|
||||
license: isc
|
||||
licenses:
|
||||
- sources: LICENSE
|
||||
text: |
|
||||
The ISC License
|
||||
|
||||
Copyright (c) Isaac Z. Schlueter and Contributors
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
notices: []
|
||||
39
.licenses/npm/source-map.dep.yml
Normal file
39
.licenses/npm/source-map.dep.yml
Normal file
@@ -0,0 +1,39 @@
|
||||
---
|
||||
name: source-map
|
||||
version: 0.6.1
|
||||
type: npm
|
||||
summary: Generates and consumes source maps
|
||||
homepage: https://github.com/mozilla/source-map
|
||||
license: other
|
||||
licenses:
|
||||
- sources: LICENSE
|
||||
text: |2
|
||||
|
||||
Copyright (c) 2009-2011, Mozilla Foundation and contributors
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the names of the Mozilla Foundation nor the names of project
|
||||
contributors may be used to endorse or promote products derived from this
|
||||
software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
notices: []
|
||||
40
.licenses/npm/uglify-js.dep.yml
Normal file
40
.licenses/npm/uglify-js.dep.yml
Normal file
@@ -0,0 +1,40 @@
|
||||
---
|
||||
name: uglify-js
|
||||
version: 3.19.3
|
||||
type: npm
|
||||
summary: JavaScript parser, mangler/compressor and beautifier toolkit
|
||||
homepage:
|
||||
license: other
|
||||
licenses:
|
||||
- sources: LICENSE
|
||||
text: |
|
||||
UglifyJS is released under the BSD license:
|
||||
|
||||
Copyright 2012-2024 (c) Mihai Bazon <mihai.bazon@gmail.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
* Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials
|
||||
provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
notices: []
|
||||
29
.licenses/npm/wordwrap.dep.yml
Normal file
29
.licenses/npm/wordwrap.dep.yml
Normal file
@@ -0,0 +1,29 @@
|
||||
---
|
||||
name: wordwrap
|
||||
version: 1.0.0
|
||||
type: npm
|
||||
summary: Wrap those words. Show them at what columns to start and stop.
|
||||
homepage:
|
||||
license: other
|
||||
licenses:
|
||||
- sources: LICENSE
|
||||
text: |
|
||||
This software is released under the MIT license:
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
notices: []
|
||||
2
.mise.toml
Normal file
2
.mise.toml
Normal file
@@ -0,0 +1,2 @@
|
||||
[settings]
|
||||
idiomatic_version_file_enable_tools = ["ruby", "node"]
|
||||
@@ -1 +1 @@
|
||||
24.4.0
|
||||
24.12.0
|
||||
|
||||
@@ -3,3 +3,4 @@
|
||||
dist/
|
||||
node_modules/
|
||||
coverage/
|
||||
CHANGELOG.md
|
||||
|
||||
1
.ruby-version
Normal file
1
.ruby-version
Normal file
@@ -0,0 +1 @@
|
||||
3.4.8
|
||||
9
.vscode/settings.shared.json
vendored
9
.vscode/settings.shared.json
vendored
@@ -1,5 +1,14 @@
|
||||
{
|
||||
"[javascript]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
},
|
||||
"[typescript]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
},
|
||||
"[json]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
},
|
||||
"[jsonc]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
}
|
||||
}
|
||||
|
||||
97
AGENTS.md
97
AGENTS.md
@@ -19,9 +19,13 @@ tags.
|
||||
up-to-date. Always run `npm run package` (or `npm run bundle`) after modifying
|
||||
`src/` files.
|
||||
|
||||
**License Compliance**: After modifying NPM dependencies, check license status
|
||||
and re-cache if needed via `npm run licensed:status` and
|
||||
`npm run licensed:cache`.
|
||||
|
||||
## Development Commands
|
||||
|
||||
Package manager: npm (Node 24 via mise.toml)
|
||||
Package manager: npm
|
||||
|
||||
```bash
|
||||
# Install dependencies
|
||||
@@ -35,7 +39,7 @@ npm run package # Build src/index.ts -> dist/index.js via Rollup
|
||||
npm run bundle # Alias: format + package
|
||||
|
||||
# Run a single test file
|
||||
NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 npx jest __tests__/main.test.ts
|
||||
NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 jest tests/main.test.ts
|
||||
|
||||
# CI variants (suppress warnings)
|
||||
npm run ci-test # Run tests in CI mode
|
||||
@@ -48,6 +52,10 @@ npm run update-readme
|
||||
|
||||
# Watch mode
|
||||
npm run package:watch # Auto-rebuild on changes
|
||||
|
||||
# License compliance (after modifying dependencies)
|
||||
npm run licensed:status # Check license status of dependencies
|
||||
npm run licensed:cache # Re-cache licenses if needed
|
||||
```
|
||||
|
||||
## Code Architecture
|
||||
@@ -59,31 +67,62 @@ npm run package:watch # Auto-rebuild on changes
|
||||
function that coordinates input parsing, tag processing, and output setting
|
||||
- **[src/inputs.ts](src/inputs.ts)**: Input parsing and validation. Exports
|
||||
`getInputs()` that reads action inputs and `Inputs` interface
|
||||
- **[src/tags.ts](src/tags.ts)**: Tag parsing and processing logic:
|
||||
- `parseTagsInput()`: Parses CSV/newline input, handles `tag:ref` syntax,
|
||||
pre-resolves all unique refs to SHAs in parallel (optimization)
|
||||
- `processTag()`: Creates/updates individual tags based on `when_exists` mode
|
||||
- `resolveRefToSha()`: Converts git refs to commit SHAs (private helper)
|
||||
- **[src/derive.ts](src/derive.ts)**: Semver parsing and tag derivation:
|
||||
- `parseSemver()`: Parses version strings into components (prefix, major,
|
||||
minor, patch, prerelease, build)
|
||||
- `renderTemplate()`: Renders Handlebars templates with semver context
|
||||
- `deriveTags()`: Derives tags from a version string using a template
|
||||
- **[src/tags.ts](src/tags.ts)**: Tag planning and execution logic:
|
||||
- `planTagOperations()`: Parses tags, pre-resolves refs to SHAs in parallel,
|
||||
plans create/update/skip operations
|
||||
- `executeTagOperation()`: Executes a single planned operation (create,
|
||||
update, or skip with logging)
|
||||
- Private helpers for tag creation, updates, and annotation handling
|
||||
- **[action.yml](action.yml)**: GitHub Action metadata (inputs/outputs)
|
||||
- **[\_\_fixtures\_\_/](__fixtures__)**: Mock implementations of @actions/core,
|
||||
- **[tests/fixtures/](tests/fixtures)**: Mock implementations of @actions/core,
|
||||
@actions/github, and csv-parse for testing
|
||||
|
||||
### Tag Input Parsing
|
||||
|
||||
Uses `csv-parse/sync` to handle both CSV and newline-delimited formats. Supports
|
||||
per-tag ref overrides: `v1:main` tags `v1` to `main` branch.
|
||||
per-tag ref and annotation overrides using the format `tag:ref:annotation`:
|
||||
|
||||
- `tag` — Use default `ref` and `annotation` inputs
|
||||
- `tag:ref` — Override ref for this tag (e.g., `v1:main` tags `v1` to `main`)
|
||||
- `tag:ref:annotation` — Override both ref and annotation
|
||||
- `tag::annotation` — Override annotation only (empty ref uses default)
|
||||
|
||||
Annotations can contain colons; everything after the second colon is treated as
|
||||
the annotation text. Per-tag values override the global `ref` and `annotation`
|
||||
inputs.
|
||||
|
||||
### Tag Derivation
|
||||
|
||||
The `derive_from` input allows automatic generation of tags from a semver
|
||||
version string. Uses Handlebars templates with these placeholders:
|
||||
|
||||
- `{{prefix}}`: "v" or "V" if input had prefix, empty otherwise
|
||||
- `{{major}}`, `{{minor}}`, `{{patch}}`: Version numbers
|
||||
- `{{prerelease}}`, `{{build}}`: Optional semver components
|
||||
- `{{version}}`: Full version without prefix
|
||||
|
||||
Default template `{{prefix}}{{major}},{{prefix}}{{major}}.{{minor}}` generates
|
||||
major and minor tags (e.g., `v1.2.3` → `v1`, `v1.2`). Supports Handlebars
|
||||
conditionals like `{{#if prerelease}}...{{/if}}`.
|
||||
|
||||
### Tag Update Logic
|
||||
|
||||
1. Parse and validate inputs ([inputs.ts](src/inputs.ts))
|
||||
2. Parse tags and extract per-tag refs ([tags.ts](src/tags.ts):parseTagsInput)
|
||||
3. Pre-resolve all unique refs to SHAs in parallel (optimization)
|
||||
4. For each tag ([tags.ts](src/tags.ts):processTag):
|
||||
- If exists + update mode: Update if SHA differs
|
||||
- If exists + skip mode: Skip silently
|
||||
- If exists + fail mode: Fail action
|
||||
- If doesn't exist (404): Create it
|
||||
5. Set outputs with created/updated tag lists ([main.ts](src/main.ts))
|
||||
2. Plan all tag operations ([tags.ts](src/tags.ts):planTagOperations):
|
||||
- Parse `tag:ref:annotation` syntax and extract per-tag refs/annotations
|
||||
- Pre-resolve all unique refs to SHAs in parallel (optimization)
|
||||
- For each tag, check existence and determine operation:
|
||||
- If exists + fail mode: Fail action immediately
|
||||
- If exists + skip mode: Plan skip
|
||||
- If exists + update mode: Plan update if SHA or annotation differs
|
||||
- If doesn't exist (404): Plan create
|
||||
3. Execute each planned operation ([tags.ts](src/tags.ts):executeTagOperation)
|
||||
4. Set outputs with created/updated/skipped tag lists ([main.ts](src/main.ts))
|
||||
|
||||
### Testing Patterns
|
||||
|
||||
@@ -97,12 +136,12 @@ jest.unstable_mockModule('@actions/core', () => core)
|
||||
const { run } = await import('../src/main.ts')
|
||||
```
|
||||
|
||||
Mock fixtures live in `__fixtures__/` (e.g., `core.ts` mocks @actions/core).
|
||||
Mock fixtures live in `tests/fixtures/` (e.g., `core.ts` mocks @actions/core).
|
||||
|
||||
### Testing Best Practices
|
||||
|
||||
- Consider edge cases as well as the main success path
|
||||
- Tests live in `__tests__/` directory, fixtures in `__fixtures__/`
|
||||
- Tests live in `tests/` directory, fixtures in `tests/fixtures/`
|
||||
- Run tests after any refactoring to ensure coverage requirements are met
|
||||
- Use `@actions/core` package for logging (not `console`) for GitHub Actions
|
||||
compatibility
|
||||
@@ -119,9 +158,10 @@ Mock fixtures live in `__fixtures__/` (e.g., `core.ts` mocks @actions/core).
|
||||
`.github/workflows/ci.yml` runs:
|
||||
|
||||
1. **check-dist**: Verify bundled dist/ matches source
|
||||
2. **lint**: ESLint with GitHub formatter
|
||||
3. **release-please**: Semantic versioning releases
|
||||
4. **release-tags**: Self-referential tag updates after release
|
||||
2. **lint**: ESLint check
|
||||
3. **test**: Run Jest test suite
|
||||
4. **release-please**: Semantic versioning releases
|
||||
5. **release-tags**: Self-referential tag updates after release
|
||||
|
||||
## Release Process
|
||||
|
||||
@@ -184,16 +224,25 @@ chore(deps): bump @actions/core to v1.10.0
|
||||
|
||||
**Inputs:**
|
||||
|
||||
- `tags`: CSV/newline list, supports `tag:ref` syntax
|
||||
- `ref`: SHA/ref to tag (default: current commit)
|
||||
- `tags`: CSV/newline list, supports `tag:ref:annotation` syntax for per-tag
|
||||
overrides
|
||||
- `derive_from`: Semver version string to derive tags from (e.g., "v1.2.3")
|
||||
- `derive_from_template`: Handlebars template for tag derivation (default:
|
||||
`{{prefix}}{{major}},{{prefix}}{{major}}.{{minor}}`)
|
||||
- `ref`: Default SHA/ref to tag (default: current commit)
|
||||
- `when_exists`: update|skip|fail (default: update)
|
||||
- `annotation`: Default annotation message for tags (default: lightweight/none)
|
||||
- `dry_run`: Log planned operations without executing (default: false)
|
||||
- `github_token`: Auth token (default: github.token)
|
||||
|
||||
Either `tags` or `derive_from` (or both) must be provided.
|
||||
|
||||
**Outputs:**
|
||||
|
||||
- `tags`: All created/updated tags
|
||||
- `created`: Newly created tags
|
||||
- `updated`: Updated tags
|
||||
- `skipped`: Skipped tags (already matching or when_exists=skip)
|
||||
|
||||
## Code Style and Guidelines
|
||||
|
||||
|
||||
51
CHANGELOG.md
51
CHANGELOG.md
@@ -1,5 +1,47 @@
|
||||
# Changelog
|
||||
|
||||
## [2.3.0](https://github.com/jimeh/update-tags-action/compare/v2.2.1...v2.3.0) (2025-12-24)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **inputs/derive_from:** derive tags from provided semver string ([#79](https://github.com/jimeh/update-tags-action/issues/79)) ([1d171e9](https://github.com/jimeh/update-tags-action/commit/1d171e9f3c63639b8d0145a881a6df941200742d))
|
||||
* **inputs/dry_run:** add dry run support ([#76](https://github.com/jimeh/update-tags-action/issues/76)) ([ef41989](https://github.com/jimeh/update-tags-action/commit/ef4198907727f6ff9e5813deb5ab5a4307ab4691))
|
||||
* **inputs/tags:** support per-tag annotation overrides ([#81](https://github.com/jimeh/update-tags-action/issues/81)) ([32e66b0](https://github.com/jimeh/update-tags-action/commit/32e66b04be37383e2450d698007faa436c706ffd))
|
||||
|
||||
## [2.2.1](https://github.com/jimeh/update-tags-action/compare/v2.2.0...v2.2.1) (2025-12-22)
|
||||
|
||||
|
||||
### Documentation
|
||||
|
||||
* **AGENTS.md:** update to align with current state of project ([#71](https://github.com/jimeh/update-tags-action/issues/71)) ([a25f37f](https://github.com/jimeh/update-tags-action/commit/a25f37f9e6300ff3fcdf28424cdec9d99944522f))
|
||||
|
||||
## [2.2.0](https://github.com/jimeh/update-tags-action/compare/v2.1.1...v2.2.0) (2025-10-29)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **action:** add skipped tags output and tracking ([#33](https://github.com/jimeh/update-tags-action/issues/33)) ([6723e4d](https://github.com/jimeh/update-tags-action/commit/6723e4d4aceb3ba7314907830d8b1d5186f0a5d9))
|
||||
|
||||
## [2.1.1](https://github.com/jimeh/update-tags-action/compare/v2.1.0...v2.1.1) (2025-10-28)
|
||||
|
||||
|
||||
### Documentation
|
||||
|
||||
* **readme:** fix outdated action inputs/outputs ([#26](https://github.com/jimeh/update-tags-action/issues/26)) ([c2d45bd](https://github.com/jimeh/update-tags-action/commit/c2d45bd3eff96a93679cc5dbac166c5a14400751))
|
||||
|
||||
## [2.1.0](https://github.com/jimeh/update-tags-action/compare/v2.0.0...v2.1.0) (2025-10-28)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **tag:** add support for annotated tags and improved tag handling ([40c0c24](https://github.com/jimeh/update-tags-action/commit/40c0c24c3478fe96765282b3f82b7f72696f0e92)), closes [#7](https://github.com/jimeh/update-tags-action/issues/7)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **when_exists:** fail-fast if tags exist if `when_exists` is `fail` ([40c0c24](https://github.com/jimeh/update-tags-action/commit/40c0c24c3478fe96765282b3f82b7f72696f0e92))
|
||||
|
||||
## [2.0.0](https://github.com/jimeh/update-tags-action/compare/v1.0.1...v2.0.0) (2025-10-27)
|
||||
|
||||
|
||||
@@ -9,22 +51,25 @@
|
||||
|
||||
## [1.0.1](https://github.com/jimeh/update-tags-action/compare/v1.0.0...v1.0.1) (2023-05-18)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- **action:** tweak metadata for GitHub Marketplace
|
||||
* **action:** tweak metadata for GitHub Marketplace
|
||||
([#4](https://github.com/jimeh/update-tags-action/issues/4))
|
||||
([b74b3c7](https://github.com/jimeh/update-tags-action/commit/b74b3c77fc20bdfd61e29dbf680a9f84612e5fda))
|
||||
|
||||
## [1.0.0](https://github.com/jimeh/update-tags-action/compare/v0.0.1...v1.0.0) (2023-05-18)
|
||||
|
||||
|
||||
### Miscellaneous Chores
|
||||
|
||||
- **release:** bump version to 1.0.0
|
||||
* **release:** bump version to 1.0.0
|
||||
([d4f686e](https://github.com/jimeh/update-tags-action/commit/d4f686ef9ff51ff4426907f89983bd286903c23e))
|
||||
|
||||
## 0.0.1 (2023-05-18)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
- initial implementation
|
||||
* initial implementation
|
||||
([0185b10](https://github.com/jimeh/update-tags-action/commit/0185b100ff1752ce06ade4b147b6befb8c37e525))
|
||||
|
||||
213
README.md
213
README.md
@@ -22,8 +22,6 @@ to move its own major and minor tags.
|
||||
|
||||
### Basic
|
||||
|
||||
<!-- x-release-please-start-major -->
|
||||
|
||||
```yaml
|
||||
- uses: jimeh/update-tags-action@v2
|
||||
with:
|
||||
@@ -38,7 +36,36 @@ to move its own major and minor tags.
|
||||
v1.2
|
||||
```
|
||||
|
||||
<!-- x-release-please-end -->
|
||||
### Deriving Tags from Version
|
||||
|
||||
Automatically derive major and minor tags from a semver version string:
|
||||
|
||||
```yaml
|
||||
- uses: jimeh/update-tags-action@v2
|
||||
with:
|
||||
derive_from: v1.2.3
|
||||
# Creates tags: v1, v1.2
|
||||
```
|
||||
|
||||
With a custom template (major tag only):
|
||||
|
||||
```yaml
|
||||
- uses: jimeh/update-tags-action@v2
|
||||
with:
|
||||
derive_from: v1.2.3
|
||||
derive_from_template: '{{prefix}}{{major}}'
|
||||
# Creates tag: v1
|
||||
```
|
||||
|
||||
Combine derived tags with explicit tags:
|
||||
|
||||
```yaml
|
||||
- uses: jimeh/update-tags-action@v2
|
||||
with:
|
||||
derive_from: v1.2.3
|
||||
tags: latest
|
||||
# Creates tags: latest, v1, v1.2
|
||||
```
|
||||
|
||||
### With Release Please
|
||||
|
||||
@@ -65,8 +92,7 @@ jobs:
|
||||
if: ${{ github.ref == 'refs/heads/main' }}
|
||||
outputs:
|
||||
release_created: ${{ steps.release-please.outputs.release_created }}
|
||||
major: ${{ steps.release-please.outputs.major }}
|
||||
minor: ${{ steps.release-please.outputs.minor }}
|
||||
tag_name: ${{ steps.release-please.outputs.tag_name }}
|
||||
permissions:
|
||||
contents: write
|
||||
issues: write
|
||||
@@ -79,8 +105,6 @@ jobs:
|
||||
And finally a job to create MAJOR and MINOR release tags, which only runs when
|
||||
release-please reports having created a release:
|
||||
|
||||
<!-- x-release-please-start-major -->
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
# [...]
|
||||
@@ -93,37 +117,172 @@ jobs:
|
||||
steps:
|
||||
- uses: jimeh/update-tags-action@v2
|
||||
with:
|
||||
tags: |
|
||||
v${{ needs.release-please.outputs.major }}
|
||||
v${{ needs.release-please.outputs.major }}.${{ needs.release-please.outputs.minor }}
|
||||
derive_from: ${{ needs.release-please.outputs.tag_name }}
|
||||
# Creates tags: v1, v1.2 (for tag_name v1.2.3)
|
||||
```
|
||||
|
||||
<!-- x-release-please-end -->
|
||||
|
||||
<!-- action-docs-inputs -->
|
||||
<!-- action-docs-inputs source="action.yml" -->
|
||||
|
||||
## Inputs
|
||||
|
||||
| parameter | description | required | default |
|
||||
| ------------ | --------------------------------------------------------------------------------- | -------- | ------------------- |
|
||||
| tags | List/CSV of tags to create/update. | `true` | |
|
||||
| ref | The SHA or ref to tag. Defaults to SHA of current commit. | `false` | ${{ github.sha }} |
|
||||
| when_exists | What to do if the tag already exists. Must be one of 'update', 'skip', or 'fail'. | `false` | update |
|
||||
| github_token | The GitHub token to use for authentication. | `false` | ${{ github.token }} |
|
||||
| name | description | required | default |
|
||||
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------- | --------------------------------------------------- |
|
||||
| `tags` | <p>List/CSV of tags to create/update. Supports per-tag ref and annotation overrides using the format 'tag:ref:annotation'. Use 'tag::annotation' to specify an annotation with the default ref.</p> | `false` | `""` |
|
||||
| `derive_from` | <p>Semver version string to derive tags from (e.g., 'v1.2.3'). When provided, generates tags using <code>derive_from_template</code> input. Default template will produce major and minor tags. (e.g., 'v1', 'v1.2')</p> | `false` | `""` |
|
||||
| `derive_from_template` | <p>Handlebars template for deriving tags from the <code>derive_from</code> input. Uses the same format as the <code>tags</code> input, and supports the following handlebars placeholders: <code>{{prefix}}</code>, <code>{{major}}</code>, <code>{{minor}}</code>, <code>{{patch}}</code>, <code>{{prerelease}}</code>, <code>{{build}}</code>, <code>{{version}}</code>.</p> | `false` | `{{prefix}}{{major}},{{prefix}}{{major}}.{{minor}}` |
|
||||
| `ref` | <p>The SHA or ref to tag. Defaults to SHA of current commit.</p> | `false` | `${{ github.sha }}` |
|
||||
| `when_exists` | <p>What to do if the tag already exists. Must be one of 'update', 'skip', or 'fail'.</p> | `false` | `update` |
|
||||
| `annotation` | <p>Optional default annotation message for tags. If provided, creates annotated tags. If empty, creates lightweight tags. Can be overridden per-tag using the 'tag:ref:annotation' syntax in the tags input.</p> | `false` | `""` |
|
||||
| `dry_run` | <p>If true, logs planned operations without executing them.</p> | `false` | `false` |
|
||||
| `github_token` | <p>The GitHub token to use for authentication.</p> | `false` | `${{ github.token }}` |
|
||||
|
||||
<!-- action-docs-inputs -->
|
||||
<!-- action-docs-inputs source="action.yml" -->
|
||||
|
||||
<!-- action-docs-outputs -->
|
||||
### Tag Input Syntax
|
||||
|
||||
The `tags` input accepts a comma or newline-delimited list of tags. Each tag
|
||||
specification supports optional per-tag ref and annotation overrides using the
|
||||
format:
|
||||
|
||||
```
|
||||
tag[:ref[:annotation]]
|
||||
```
|
||||
|
||||
| Format | Description |
|
||||
| -------------------- | ----------------------------------------------- |
|
||||
| `tag` | Tag using default `ref` and `annotation` inputs |
|
||||
| `tag:ref` | Tag using specified ref, default annotation |
|
||||
| `tag:ref:annotation` | Tag using specified ref and annotation |
|
||||
| `tag::annotation` | Tag using default ref with specified annotation |
|
||||
|
||||
**Per-tag refs** allow different tags to point to different commits:
|
||||
|
||||
```yaml
|
||||
- uses: jimeh/update-tags-action@v2
|
||||
with:
|
||||
tags: |
|
||||
v1:main
|
||||
v2:develop
|
||||
```
|
||||
|
||||
**Per-tag annotations** allow different annotation messages for each tag:
|
||||
|
||||
```yaml
|
||||
- uses: jimeh/update-tags-action@v2
|
||||
with:
|
||||
tags: |
|
||||
v1:main:Latest v1.x release
|
||||
v1.2:main:Latest v1.2.x release
|
||||
```
|
||||
|
||||
Use `tag::annotation` to specify an annotation while using the default ref:
|
||||
|
||||
```yaml
|
||||
- uses: jimeh/update-tags-action@v2
|
||||
with:
|
||||
tags: |
|
||||
v1::This is the v1 tag annotation
|
||||
v1.2::This is the v1.2 tag annotation
|
||||
```
|
||||
|
||||
Per-tag values override the global `ref` and `annotation` inputs:
|
||||
|
||||
```yaml
|
||||
- uses: jimeh/update-tags-action@v2
|
||||
with:
|
||||
tags: |
|
||||
v1:main:Custom annotation for v1
|
||||
v2
|
||||
ref: develop
|
||||
annotation: Default annotation for tags without per-tag override
|
||||
# v1 -> main with "Custom annotation for v1"
|
||||
# v2 -> develop with "Default annotation..."
|
||||
```
|
||||
|
||||
Annotations can contain colons (everything after the second colon is the
|
||||
annotation):
|
||||
|
||||
```yaml
|
||||
- uses: jimeh/update-tags-action@v2
|
||||
with:
|
||||
tags: |
|
||||
v1:main:Release: version 1.0.0
|
||||
# Annotation will be "Release: version 1.0.0"
|
||||
```
|
||||
|
||||
### Derive Template Syntax
|
||||
|
||||
The `derive_from_template` input uses [Handlebars](https://handlebarsjs.com/)
|
||||
for template rendering. Splitting the template into separate tags by comma or
|
||||
newline is done after the template is rendered.
|
||||
|
||||
Available placeholders:
|
||||
|
||||
| Placeholder | Description |
|
||||
| ---------------- | ----------------------------------------------------- |
|
||||
| `{{prefix}}` | `v` or `V` if input had a prefix, empty otherwise |
|
||||
| `{{major}}` | Major version number |
|
||||
| `{{minor}}` | Minor version number |
|
||||
| `{{patch}}` | Patch version number |
|
||||
| `{{prerelease}}` | Prerelease identifier (e.g., `beta.1`), empty if none |
|
||||
| `{{build}}` | Build metadata (e.g., `build.123`), empty if none |
|
||||
| `{{version}}` | Full version string without prefix |
|
||||
|
||||
#### Conditional Sections
|
||||
|
||||
Use Handlebars `{{#if}}` blocks to include content only when a variable has a
|
||||
value. This is useful for optional components like prerelease or build metadata:
|
||||
|
||||
```yaml
|
||||
- uses: jimeh/update-tags-action@v2
|
||||
with:
|
||||
derive_from: v1.2.3-beta.1
|
||||
derive_from_template: |
|
||||
{{prefix}}{{major}}{{#if prerelease}}-{{prerelease}}{{/if}}
|
||||
# Creates tag: v1-beta.1
|
||||
```
|
||||
|
||||
For a stable release without prerelease:
|
||||
|
||||
```yaml
|
||||
- uses: jimeh/update-tags-action@v2
|
||||
with:
|
||||
derive_from: v1.2.3
|
||||
derive_from_template: |
|
||||
{{prefix}}{{major}}{{#if prerelease}}-{{prerelease}}{{/if}}
|
||||
# Creates tag: v1 (prerelease section omitted)
|
||||
```
|
||||
|
||||
You can also use `{{#unless}}` for inverse logic:
|
||||
|
||||
```yaml
|
||||
- uses: jimeh/update-tags-action@v2
|
||||
with:
|
||||
derive_from: v1.2.3
|
||||
derive_from_template: |
|
||||
{{prefix}}{{major}}{{#unless prerelease}}-stable{{/unless}}
|
||||
# Creates tag: v1-stable (only for non-prerelease versions)
|
||||
```
|
||||
|
||||
<!-- action-docs-outputs source="action.yml" -->
|
||||
|
||||
## Outputs
|
||||
|
||||
| parameter | description |
|
||||
| --------- | --------------------------------------- |
|
||||
| tags | List of tags that were created/updated. |
|
||||
| created | List of tags that were created. |
|
||||
| updated | List of tags that were updated. |
|
||||
| name | description |
|
||||
| --------- | ---------------------------------------------- |
|
||||
| `tags` | <p>List of tags that were created/updated.</p> |
|
||||
| `created` | <p>List of tags that were created.</p> |
|
||||
| `updated` | <p>List of tags that were updated.</p> |
|
||||
| `skipped` | <p>List of tags that were skipped.</p> |
|
||||
|
||||
<!-- action-docs-outputs -->
|
||||
<!-- action-docs-outputs source="action.yml" -->
|
||||
<!-- action-docs-runs source="action.yml" -->
|
||||
|
||||
## Runs
|
||||
|
||||
This action is a `node24` action.
|
||||
|
||||
<!-- action-docs-runs source="action.yml" -->
|
||||
|
||||
## License
|
||||
|
||||
|
||||
@@ -1,657 +0,0 @@
|
||||
/**
|
||||
* Unit tests for the action's main functionality, src/main.ts
|
||||
*/
|
||||
import { jest } from '@jest/globals'
|
||||
import * as core from '../__fixtures__/core.js'
|
||||
import * as github from '../__fixtures__/github.js'
|
||||
import * as csvParse from '../__fixtures__/csv-parse.js'
|
||||
|
||||
// Mocks should be declared before the module being tested is imported.
|
||||
jest.unstable_mockModule('@actions/core', () => core)
|
||||
jest.unstable_mockModule('@actions/github', () => github)
|
||||
jest.unstable_mockModule('csv-parse/sync', () => csvParse)
|
||||
|
||||
// The module being tested should be imported dynamically. This ensures that
|
||||
// the mocks are used in place of any actual dependencies.
|
||||
const { run } = await import('../src/main.js')
|
||||
|
||||
// Helper functions for cleaner test setup
|
||||
const setupInputs = (inputs: Record<string, string>): void => {
|
||||
core.getInput.mockImplementation((name: string) => {
|
||||
return inputs[name] || ''
|
||||
})
|
||||
}
|
||||
|
||||
const setupCommitResolver = (
|
||||
refToSha: Record<string, string> | string
|
||||
): void => {
|
||||
if (typeof refToSha === 'string') {
|
||||
github.mockOctokit.rest.repos.getCommit.mockResolvedValue({
|
||||
data: { sha: refToSha }
|
||||
})
|
||||
} else {
|
||||
github.mockOctokit.rest.repos.getCommit.mockImplementation(
|
||||
async (args: unknown) => {
|
||||
const { ref } = args as { ref: string }
|
||||
const sha = refToSha[ref]
|
||||
if (sha) return { data: { sha } }
|
||||
throw new Error(`Unknown ref: ${ref}`)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const setupTagDoesNotExist = (): void => {
|
||||
github.mockOctokit.rest.git.getRef.mockRejectedValue({
|
||||
status: 404
|
||||
})
|
||||
}
|
||||
|
||||
const setupTagExists = (tagName: string, sha: string): void => {
|
||||
github.mockOctokit.rest.git.getRef.mockImplementation(
|
||||
async (args: unknown) => {
|
||||
const { ref } = args as { ref: string }
|
||||
if (ref === `tags/${tagName}`) {
|
||||
return {
|
||||
data: { ref: `refs/tags/${tagName}`, object: { sha } }
|
||||
}
|
||||
}
|
||||
throw { status: 404 }
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
const setupTagExistsForAll = (sha: string): void => {
|
||||
github.mockOctokit.rest.git.getRef.mockResolvedValue({
|
||||
data: { ref: 'refs/tags/v1', object: { sha } }
|
||||
})
|
||||
}
|
||||
|
||||
describe('run', () => {
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks()
|
||||
// Re-setup mocks after reset
|
||||
github.getOctokit.mockReturnValue(github.mockOctokit)
|
||||
csvParse.resetToRealImplementation()
|
||||
})
|
||||
|
||||
it('creates new tags when they do not exist', async () => {
|
||||
setupInputs({
|
||||
tags: 'v1,v1.0',
|
||||
ref: 'abc123',
|
||||
github_token: 'test-token',
|
||||
when_exists: 'update'
|
||||
})
|
||||
setupCommitResolver('sha-abc123')
|
||||
setupTagDoesNotExist()
|
||||
|
||||
await run()
|
||||
|
||||
expect(github.mockOctokit.rest.git.createRef).toHaveBeenCalledTimes(2)
|
||||
expect(github.mockOctokit.rest.git.createRef).toHaveBeenCalledWith({
|
||||
owner: 'test-owner',
|
||||
repo: 'test-repo',
|
||||
ref: 'refs/tags/v1',
|
||||
sha: 'sha-abc123'
|
||||
})
|
||||
expect(github.mockOctokit.rest.git.createRef).toHaveBeenCalledWith({
|
||||
owner: 'test-owner',
|
||||
repo: 'test-repo',
|
||||
ref: 'refs/tags/v1.0',
|
||||
sha: 'sha-abc123'
|
||||
})
|
||||
|
||||
expect(core.info).toHaveBeenCalledWith(
|
||||
"Tag 'v1' does not exist, creating with SHA sha-abc123."
|
||||
)
|
||||
expect(core.setOutput).toHaveBeenCalledWith('created', ['v1', 'v1.0'])
|
||||
expect(core.setOutput).toHaveBeenCalledWith('updated', [])
|
||||
expect(core.setOutput).toHaveBeenCalledWith('tags', ['v1', 'v1.0'])
|
||||
})
|
||||
|
||||
it('updates existing tags when SHA differs', async () => {
|
||||
setupInputs({
|
||||
tags: 'v1',
|
||||
ref: 'def456',
|
||||
github_token: 'test-token',
|
||||
when_exists: 'update'
|
||||
})
|
||||
setupCommitResolver('sha-def456')
|
||||
setupTagExistsForAll('sha-old123')
|
||||
|
||||
await run()
|
||||
|
||||
expect(github.mockOctokit.rest.git.updateRef).toHaveBeenCalledTimes(1)
|
||||
expect(github.mockOctokit.rest.git.updateRef).toHaveBeenCalledWith({
|
||||
owner: 'test-owner',
|
||||
repo: 'test-repo',
|
||||
ref: 'tags/v1',
|
||||
sha: 'sha-def456',
|
||||
force: true
|
||||
})
|
||||
|
||||
expect(core.info).toHaveBeenCalledWith(
|
||||
"Tag 'v1' exists, updating to SHA sha-def456 (was sha-old123)."
|
||||
)
|
||||
expect(core.setOutput).toHaveBeenCalledWith('created', [])
|
||||
expect(core.setOutput).toHaveBeenCalledWith('updated', ['v1'])
|
||||
expect(core.setOutput).toHaveBeenCalledWith('tags', ['v1'])
|
||||
})
|
||||
|
||||
it('skips updating when tag exists with same SHA', async () => {
|
||||
setupInputs({
|
||||
tags: 'v1',
|
||||
ref: 'abc123',
|
||||
github_token: 'test-token',
|
||||
when_exists: 'update'
|
||||
})
|
||||
setupCommitResolver('sha-abc123')
|
||||
setupTagExistsForAll('sha-abc123')
|
||||
|
||||
await run()
|
||||
|
||||
expect(github.mockOctokit.rest.git.updateRef).not.toHaveBeenCalled()
|
||||
expect(github.mockOctokit.rest.git.createRef).not.toHaveBeenCalled()
|
||||
expect(core.info).toHaveBeenCalledWith(
|
||||
"Tag 'v1' already exists with desired SHA sha-abc123."
|
||||
)
|
||||
expect(core.setOutput).toHaveBeenCalledWith('created', [])
|
||||
expect(core.setOutput).toHaveBeenCalledWith('updated', [])
|
||||
expect(core.setOutput).toHaveBeenCalledWith('tags', [])
|
||||
})
|
||||
|
||||
it('skips tags when when_exists is skip', async () => {
|
||||
setupInputs({
|
||||
tags: 'v1',
|
||||
ref: 'abc123',
|
||||
github_token: 'test-token',
|
||||
when_exists: 'skip'
|
||||
})
|
||||
setupCommitResolver('sha-abc123')
|
||||
setupTagExistsForAll('sha-old123')
|
||||
|
||||
await run()
|
||||
|
||||
expect(github.mockOctokit.rest.git.updateRef).not.toHaveBeenCalled()
|
||||
expect(github.mockOctokit.rest.git.createRef).not.toHaveBeenCalled()
|
||||
expect(core.info).toHaveBeenCalledWith("Tag 'v1' exists, skipping.")
|
||||
expect(core.setOutput).toHaveBeenCalledWith('created', [])
|
||||
expect(core.setOutput).toHaveBeenCalledWith('updated', [])
|
||||
expect(core.setOutput).toHaveBeenCalledWith('tags', [])
|
||||
})
|
||||
|
||||
it('handles per-tag ref overrides', async () => {
|
||||
setupInputs({
|
||||
tags: 'v1:main,v2:develop',
|
||||
ref: '',
|
||||
github_token: 'test-token',
|
||||
when_exists: 'update'
|
||||
})
|
||||
setupCommitResolver({
|
||||
main: 'sha-main',
|
||||
develop: 'sha-develop'
|
||||
})
|
||||
setupTagDoesNotExist()
|
||||
|
||||
await run()
|
||||
|
||||
expect(github.mockOctokit.rest.repos.getCommit).toHaveBeenCalledWith({
|
||||
owner: 'test-owner',
|
||||
repo: 'test-repo',
|
||||
ref: 'main'
|
||||
})
|
||||
expect(github.mockOctokit.rest.repos.getCommit).toHaveBeenCalledWith({
|
||||
owner: 'test-owner',
|
||||
repo: 'test-repo',
|
||||
ref: 'develop'
|
||||
})
|
||||
|
||||
expect(github.mockOctokit.rest.git.createRef).toHaveBeenCalledWith({
|
||||
owner: 'test-owner',
|
||||
repo: 'test-repo',
|
||||
ref: 'refs/tags/v1',
|
||||
sha: 'sha-main'
|
||||
})
|
||||
expect(github.mockOctokit.rest.git.createRef).toHaveBeenCalledWith({
|
||||
owner: 'test-owner',
|
||||
repo: 'test-repo',
|
||||
ref: 'refs/tags/v2',
|
||||
sha: 'sha-develop'
|
||||
})
|
||||
|
||||
expect(core.setOutput).toHaveBeenCalledWith('created', ['v1', 'v2'])
|
||||
})
|
||||
|
||||
it('handles various input formats (newlines and whitespace)', async () => {
|
||||
setupInputs({
|
||||
tags: ' v1 \n v1.0 \n v1.0.1 ',
|
||||
ref: 'abc123',
|
||||
github_token: 'test-token',
|
||||
when_exists: 'update'
|
||||
})
|
||||
setupCommitResolver('sha-abc123')
|
||||
setupTagDoesNotExist()
|
||||
|
||||
await run()
|
||||
|
||||
expect(github.mockOctokit.rest.git.createRef).toHaveBeenCalledTimes(3)
|
||||
expect(core.setOutput).toHaveBeenCalledWith('created', [
|
||||
'v1',
|
||||
'v1.0',
|
||||
'v1.0.1'
|
||||
])
|
||||
})
|
||||
|
||||
it('creates and updates tags in single run', async () => {
|
||||
setupInputs({
|
||||
tags: 'v1,v2',
|
||||
ref: 'abc123',
|
||||
github_token: 'test-token',
|
||||
when_exists: 'update'
|
||||
})
|
||||
setupCommitResolver('sha-abc123')
|
||||
setupTagExists('v1', 'sha-old')
|
||||
|
||||
await run()
|
||||
|
||||
expect(github.mockOctokit.rest.git.updateRef).toHaveBeenCalledTimes(1)
|
||||
expect(github.mockOctokit.rest.git.createRef).toHaveBeenCalledTimes(1)
|
||||
expect(core.setOutput).toHaveBeenCalledWith('created', ['v2'])
|
||||
expect(core.setOutput).toHaveBeenCalledWith('updated', ['v1'])
|
||||
expect(core.setOutput).toHaveBeenCalledWith('tags', ['v2', 'v1'])
|
||||
})
|
||||
|
||||
it('fails when ref is missing', async () => {
|
||||
setupInputs({
|
||||
tags: 'v1',
|
||||
ref: '',
|
||||
github_token: 'test-token',
|
||||
when_exists: 'update'
|
||||
})
|
||||
|
||||
await run()
|
||||
|
||||
expect(core.setFailed).toHaveBeenCalledWith(
|
||||
expect.stringContaining("Missing ref: provide 'ref' input")
|
||||
)
|
||||
})
|
||||
|
||||
it('fails when when_exists is fail and tag exists', async () => {
|
||||
setupInputs({
|
||||
tags: 'v1',
|
||||
ref: 'abc123',
|
||||
github_token: 'test-token',
|
||||
when_exists: 'fail'
|
||||
})
|
||||
setupCommitResolver('sha-abc123')
|
||||
setupTagExistsForAll('sha-old123')
|
||||
|
||||
await run()
|
||||
|
||||
expect(core.setFailed).toHaveBeenCalledWith("Tag 'v1' already exists.")
|
||||
expect(github.mockOctokit.rest.git.updateRef).not.toHaveBeenCalled()
|
||||
expect(github.mockOctokit.rest.git.createRef).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('fails when when_exists has invalid value', async () => {
|
||||
setupInputs({
|
||||
tags: 'v1',
|
||||
ref: 'abc123',
|
||||
github_token: 'test-token',
|
||||
when_exists: 'invalid'
|
||||
})
|
||||
setupCommitResolver('sha-abc123')
|
||||
setupTagExistsForAll('sha-old123')
|
||||
|
||||
await run()
|
||||
|
||||
expect(core.setFailed).toHaveBeenCalledWith(
|
||||
expect.stringContaining("Invalid value for 'when_exists'")
|
||||
)
|
||||
})
|
||||
|
||||
it('handles non-404 errors when checking if tag exists', async () => {
|
||||
setupInputs({
|
||||
tags: 'v1',
|
||||
ref: 'abc123',
|
||||
github_token: 'test-token',
|
||||
when_exists: 'update'
|
||||
})
|
||||
setupCommitResolver('sha-abc123')
|
||||
github.mockOctokit.rest.git.getRef.mockRejectedValue({
|
||||
status: 500,
|
||||
message: 'Internal Server Error'
|
||||
})
|
||||
|
||||
await run()
|
||||
|
||||
expect(core.setFailed).toHaveBeenCalledWith(
|
||||
expect.stringContaining('Action failed with error')
|
||||
)
|
||||
})
|
||||
|
||||
it('handles errors when resolving ref to SHA', async () => {
|
||||
setupInputs({
|
||||
tags: 'v1',
|
||||
ref: 'invalid-ref',
|
||||
github_token: 'test-token',
|
||||
when_exists: 'update'
|
||||
})
|
||||
github.mockOctokit.rest.repos.getCommit.mockRejectedValue(
|
||||
new Error('Reference not found')
|
||||
)
|
||||
|
||||
await run()
|
||||
|
||||
expect(core.setFailed).toHaveBeenCalledWith(
|
||||
expect.stringContaining("Failed to resolve ref 'invalid-ref'")
|
||||
)
|
||||
})
|
||||
|
||||
it('handles non-Error thrown when parsing tags', async () => {
|
||||
setupInputs({
|
||||
tags: 'v1',
|
||||
ref: 'abc123',
|
||||
github_token: 'test-token',
|
||||
when_exists: 'update'
|
||||
})
|
||||
csvParse.parse.mockImplementation(() => {
|
||||
throw 'Parse error: not an Error instance'
|
||||
})
|
||||
|
||||
await run()
|
||||
|
||||
expect(core.setFailed).toHaveBeenCalledWith(
|
||||
'Parse error: not an Error instance'
|
||||
)
|
||||
})
|
||||
|
||||
it('defaults to update mode when when_exists is empty', async () => {
|
||||
setupInputs({
|
||||
tags: 'v1',
|
||||
ref: 'abc123',
|
||||
github_token: 'test-token',
|
||||
when_exists: ''
|
||||
})
|
||||
setupCommitResolver('sha-abc123')
|
||||
setupTagExistsForAll('sha-old123')
|
||||
|
||||
await run()
|
||||
|
||||
expect(github.mockOctokit.rest.git.updateRef).toHaveBeenCalledTimes(1)
|
||||
expect(core.setOutput).toHaveBeenCalledWith('updated', ['v1'])
|
||||
})
|
||||
|
||||
it('handles duplicate tags by using last occurrence', async () => {
|
||||
setupInputs({
|
||||
tags: 'v1,v2,v1',
|
||||
ref: 'abc123',
|
||||
github_token: 'test-token',
|
||||
when_exists: 'update'
|
||||
})
|
||||
setupCommitResolver('sha-abc123')
|
||||
setupTagDoesNotExist()
|
||||
|
||||
await run()
|
||||
|
||||
// Should only create 2 tags (v1 and v2), not 3
|
||||
expect(github.mockOctokit.rest.git.createRef).toHaveBeenCalledTimes(2)
|
||||
expect(core.setOutput).toHaveBeenCalledWith('created', ['v1', 'v2'])
|
||||
})
|
||||
|
||||
it('optimizes by resolving unique refs only once', async () => {
|
||||
setupInputs({
|
||||
tags: 'v1:main,v2:main,v3:develop',
|
||||
ref: '',
|
||||
github_token: 'test-token',
|
||||
when_exists: 'update'
|
||||
})
|
||||
setupCommitResolver({
|
||||
main: 'sha-main',
|
||||
develop: 'sha-develop'
|
||||
})
|
||||
setupTagDoesNotExist()
|
||||
|
||||
await run()
|
||||
|
||||
// Should only call getCommit 2 times (main and develop), not 3
|
||||
expect(github.mockOctokit.rest.repos.getCommit).toHaveBeenCalledTimes(2)
|
||||
expect(github.mockOctokit.rest.git.createRef).toHaveBeenCalledTimes(3)
|
||||
})
|
||||
|
||||
it('handles tag with colon but empty ref part', async () => {
|
||||
setupInputs({
|
||||
tags: 'v1:,v2',
|
||||
ref: 'abc123',
|
||||
github_token: 'test-token',
|
||||
when_exists: 'update'
|
||||
})
|
||||
setupCommitResolver('sha-abc123')
|
||||
setupTagDoesNotExist()
|
||||
|
||||
await run()
|
||||
|
||||
// Both should use default ref
|
||||
expect(github.mockOctokit.rest.git.createRef).toHaveBeenCalledTimes(2)
|
||||
expect(core.setOutput).toHaveBeenCalledWith('created', ['v1', 'v2'])
|
||||
})
|
||||
|
||||
it('fails when tag specification has multiple colons', async () => {
|
||||
setupInputs({
|
||||
tags: 'stable:refs/heads/main:latest',
|
||||
ref: '',
|
||||
github_token: 'test-token',
|
||||
when_exists: 'update'
|
||||
})
|
||||
|
||||
await run()
|
||||
|
||||
expect(core.setFailed).toHaveBeenCalledWith(
|
||||
expect.stringContaining('Invalid tag specification')
|
||||
)
|
||||
expect(core.setFailed).toHaveBeenCalledWith(
|
||||
expect.stringContaining('too many colons')
|
||||
)
|
||||
})
|
||||
|
||||
it('handles mixed scenario with multiple tags', async () => {
|
||||
setupInputs({
|
||||
tags: 'v1,v2,v3',
|
||||
ref: 'abc123',
|
||||
github_token: 'test-token',
|
||||
when_exists: 'skip'
|
||||
})
|
||||
setupCommitResolver('sha-abc123')
|
||||
|
||||
// v1 exists, v2 and v3 don't
|
||||
github.mockOctokit.rest.git.getRef.mockImplementation(
|
||||
async (args: unknown) => {
|
||||
const { ref } = args as { ref: string }
|
||||
if (ref === 'tags/v1') {
|
||||
return {
|
||||
data: { ref: 'refs/tags/v1', object: { sha: 'sha-old' } }
|
||||
}
|
||||
}
|
||||
throw { status: 404 }
|
||||
}
|
||||
)
|
||||
|
||||
await run()
|
||||
|
||||
// Should skip v1, create v2 and v3
|
||||
expect(core.info).toHaveBeenCalledWith("Tag 'v1' exists, skipping.")
|
||||
expect(github.mockOctokit.rest.git.createRef).toHaveBeenCalledTimes(2)
|
||||
expect(core.setOutput).toHaveBeenCalledWith('created', ['v2', 'v3'])
|
||||
expect(core.setOutput).toHaveBeenCalledWith('updated', [])
|
||||
})
|
||||
|
||||
it('fails when tag name is empty (e.g., ":main")', async () => {
|
||||
setupInputs({
|
||||
tags: ':main',
|
||||
ref: '',
|
||||
github_token: 'test-token',
|
||||
when_exists: 'update'
|
||||
})
|
||||
setupCommitResolver('sha-main')
|
||||
|
||||
await run()
|
||||
|
||||
expect(core.setFailed).toHaveBeenCalledWith("Invalid tag: ':main'")
|
||||
expect(github.mockOctokit.rest.git.createRef).not.toHaveBeenCalled()
|
||||
expect(github.mockOctokit.rest.git.updateRef).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('fails when one of multiple tags has empty name with ref', async () => {
|
||||
setupInputs({
|
||||
tags: 'v1,:develop,v2',
|
||||
ref: 'abc123',
|
||||
github_token: 'test-token',
|
||||
when_exists: 'update'
|
||||
})
|
||||
setupCommitResolver({
|
||||
abc123: 'sha-abc123',
|
||||
develop: 'sha-develop'
|
||||
})
|
||||
setupTagDoesNotExist()
|
||||
|
||||
await run()
|
||||
|
||||
// Should fail on invalid tag during parsing, before processing any tags
|
||||
expect(core.setFailed).toHaveBeenCalledWith("Invalid tag: ':develop'")
|
||||
expect(github.mockOctokit.rest.git.createRef).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('fails when duplicate tag has different refs (explicit)', async () => {
|
||||
setupInputs({
|
||||
tags: 'v1:main,v1:develop',
|
||||
ref: '',
|
||||
github_token: 'test-token'
|
||||
})
|
||||
|
||||
await run()
|
||||
|
||||
expect(core.setFailed).toHaveBeenCalledWith(
|
||||
"Duplicate tag 'v1' with different refs: 'main' and 'develop'"
|
||||
)
|
||||
expect(github.mockOctokit.rest.git.createRef).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('fails when duplicate tag has different refs (default vs explicit)', async () => {
|
||||
setupInputs({
|
||||
tags: 'v1,v1:develop',
|
||||
ref: 'main',
|
||||
github_token: 'test-token'
|
||||
})
|
||||
|
||||
await run()
|
||||
|
||||
expect(core.setFailed).toHaveBeenCalledWith(
|
||||
"Duplicate tag 'v1' with different refs: 'main' and 'develop'"
|
||||
)
|
||||
expect(github.mockOctokit.rest.git.createRef).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('skips empty tags from double commas (e.g., "v1,,v2")', async () => {
|
||||
setupInputs({
|
||||
tags: 'v1,,v2',
|
||||
ref: 'abc123',
|
||||
github_token: 'test-token',
|
||||
when_exists: 'update'
|
||||
})
|
||||
setupCommitResolver('sha-abc123')
|
||||
setupTagDoesNotExist()
|
||||
|
||||
await run()
|
||||
|
||||
// Should skip empty tag and process v1 and v2
|
||||
expect(github.mockOctokit.rest.git.createRef).toHaveBeenCalledWith({
|
||||
owner: 'test-owner',
|
||||
repo: 'test-repo',
|
||||
ref: 'refs/tags/v1',
|
||||
sha: 'sha-abc123'
|
||||
})
|
||||
expect(github.mockOctokit.rest.git.createRef).toHaveBeenCalledWith({
|
||||
owner: 'test-owner',
|
||||
repo: 'test-repo',
|
||||
ref: 'refs/tags/v2',
|
||||
sha: 'sha-abc123'
|
||||
})
|
||||
expect(github.mockOctokit.rest.git.createRef).toHaveBeenCalledTimes(2)
|
||||
expect(core.setOutput).toHaveBeenCalledWith('created', ['v1', 'v2'])
|
||||
})
|
||||
|
||||
it('skips empty lines in multi-line input (e.g., "v1\\n\\nv2")', async () => {
|
||||
setupInputs({
|
||||
tags: 'v1\n\nv2',
|
||||
ref: 'abc123',
|
||||
github_token: 'test-token',
|
||||
when_exists: 'update'
|
||||
})
|
||||
setupCommitResolver('sha-abc123')
|
||||
setupTagDoesNotExist()
|
||||
|
||||
await run()
|
||||
|
||||
// Should skip empty line and process v1 and v2
|
||||
expect(github.mockOctokit.rest.git.createRef).toHaveBeenCalledWith({
|
||||
owner: 'test-owner',
|
||||
repo: 'test-repo',
|
||||
ref: 'refs/tags/v1',
|
||||
sha: 'sha-abc123'
|
||||
})
|
||||
expect(github.mockOctokit.rest.git.createRef).toHaveBeenCalledWith({
|
||||
owner: 'test-owner',
|
||||
repo: 'test-repo',
|
||||
ref: 'refs/tags/v2',
|
||||
sha: 'sha-abc123'
|
||||
})
|
||||
expect(github.mockOctokit.rest.git.createRef).toHaveBeenCalledTimes(2)
|
||||
expect(core.setOutput).toHaveBeenCalledWith('created', ['v1', 'v2'])
|
||||
})
|
||||
|
||||
it('skips empty tags from mix of empty CSV fields and empty lines', async () => {
|
||||
setupInputs({
|
||||
tags: 'v1,,v2\n\nv3,v4',
|
||||
ref: 'abc123',
|
||||
github_token: 'test-token',
|
||||
when_exists: 'update'
|
||||
})
|
||||
setupCommitResolver('sha-abc123')
|
||||
setupTagDoesNotExist()
|
||||
|
||||
await run()
|
||||
|
||||
// Should skip all empty tags and process v1, v2, v3, v4
|
||||
expect(github.mockOctokit.rest.git.createRef).toHaveBeenCalledWith({
|
||||
owner: 'test-owner',
|
||||
repo: 'test-repo',
|
||||
ref: 'refs/tags/v1',
|
||||
sha: 'sha-abc123'
|
||||
})
|
||||
expect(github.mockOctokit.rest.git.createRef).toHaveBeenCalledWith({
|
||||
owner: 'test-owner',
|
||||
repo: 'test-repo',
|
||||
ref: 'refs/tags/v2',
|
||||
sha: 'sha-abc123'
|
||||
})
|
||||
expect(github.mockOctokit.rest.git.createRef).toHaveBeenCalledWith({
|
||||
owner: 'test-owner',
|
||||
repo: 'test-repo',
|
||||
ref: 'refs/tags/v3',
|
||||
sha: 'sha-abc123'
|
||||
})
|
||||
expect(github.mockOctokit.rest.git.createRef).toHaveBeenCalledWith({
|
||||
owner: 'test-owner',
|
||||
repo: 'test-repo',
|
||||
ref: 'refs/tags/v4',
|
||||
sha: 'sha-abc123'
|
||||
})
|
||||
expect(github.mockOctokit.rest.git.createRef).toHaveBeenCalledTimes(4)
|
||||
expect(core.setOutput).toHaveBeenCalledWith('created', [
|
||||
'v1',
|
||||
'v2',
|
||||
'v3',
|
||||
'v4'
|
||||
])
|
||||
})
|
||||
})
|
||||
35
action.yml
35
action.yml
@@ -8,8 +8,25 @@ branding:
|
||||
|
||||
inputs:
|
||||
tags:
|
||||
description: "List/CSV of tags to create/update."
|
||||
required: true
|
||||
description: >-
|
||||
List/CSV of tags to create/update. Supports per-tag ref and annotation
|
||||
overrides using the format 'tag:ref:annotation'. Use 'tag::annotation' to
|
||||
specify an annotation with the default ref.
|
||||
required: false
|
||||
derive_from:
|
||||
description: >-
|
||||
Semver version string to derive tags from (e.g., 'v1.2.3'). When provided,
|
||||
generates tags using `derive_from_template` input. Default template will
|
||||
produce major and minor tags. (e.g., 'v1', 'v1.2')
|
||||
required: false
|
||||
derive_from_template:
|
||||
description: >-
|
||||
Handlebars template for deriving tags from the `derive_from` input. Uses
|
||||
the same format as the `tags` input, and supports the following handlebars
|
||||
placeholders: `{{prefix}}`, `{{major}}`, `{{minor}}`, `{{patch}}`,
|
||||
`{{prerelease}}`, `{{build}}`, `{{version}}`.
|
||||
required: false
|
||||
default: "{{prefix}}{{major}},{{prefix}}{{major}}.{{minor}}"
|
||||
ref:
|
||||
description: "The SHA or ref to tag. Defaults to SHA of current commit."
|
||||
required: false
|
||||
@@ -20,6 +37,18 @@ inputs:
|
||||
'fail'.
|
||||
required: false
|
||||
default: "update"
|
||||
annotation:
|
||||
description: >-
|
||||
Optional default annotation message for tags. If provided, creates
|
||||
annotated tags. If empty, creates lightweight tags. Can be overridden
|
||||
per-tag using the 'tag:ref:annotation' syntax in the tags input.
|
||||
required: false
|
||||
default: ""
|
||||
dry_run:
|
||||
description: >-
|
||||
If true, logs planned operations without executing them.
|
||||
required: false
|
||||
default: "false"
|
||||
github_token:
|
||||
description: "The GitHub token to use for authentication."
|
||||
required: false
|
||||
@@ -32,6 +61,8 @@ outputs:
|
||||
description: "List of tags that were created."
|
||||
updated:
|
||||
description: "List of tags that were updated."
|
||||
skipped:
|
||||
description: "List of tags that were skipped."
|
||||
|
||||
runs:
|
||||
using: node24
|
||||
|
||||
45023
dist/index.js
generated
vendored
45023
dist/index.js
generated
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
735
package-lock.json
generated
735
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
32
package.json
32
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "update-tags-action",
|
||||
"version": "1.0.1",
|
||||
"version": "2.3.0",
|
||||
"author": "jimeh",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
@@ -41,35 +41,37 @@
|
||||
"update-readme": "npx action-docs --update-readme && npx prettier --write README.md"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.11.1",
|
||||
"@actions/github": "^6.0.1",
|
||||
"csv-parse": "^6.1.0"
|
||||
"@actions/core": "^2.0.2",
|
||||
"@actions/github": "^7.0.0",
|
||||
"csv-parse": "^6.1.0",
|
||||
"handlebars": "^4.7.8",
|
||||
"semver": "^7.7.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/compat": "^1.4.0",
|
||||
"@eslint/compat": "^2.0.1",
|
||||
"@jest/globals": "^30.2.0",
|
||||
"@rollup/plugin-commonjs": "^28.0.9",
|
||||
"@rollup/plugin-commonjs": "^29.0.0",
|
||||
"@rollup/plugin-node-resolve": "^16.0.3",
|
||||
"@rollup/plugin-terser": "^0.4.4",
|
||||
"@rollup/plugin-typescript": "^12.3.0",
|
||||
"@types/jest": "^30.0.0",
|
||||
"@types/node": "^24.9.1",
|
||||
"@typescript-eslint/eslint-plugin": "^8.46.2",
|
||||
"@types/node": "^25.0.9",
|
||||
"@types/semver": "^7.7.1",
|
||||
"@typescript-eslint/eslint-plugin": "^8.53.0",
|
||||
"@typescript-eslint/parser": "^8.46.2",
|
||||
"action-docs": "^2.5.1",
|
||||
"eslint": "^9.38.0",
|
||||
"eslint": "^9.39.2",
|
||||
"eslint-config-prettier": "^10.1.8",
|
||||
"eslint-import-resolver-typescript": "^4.4.4",
|
||||
"eslint-plugin-import": "^2.32.0",
|
||||
"eslint-plugin-jest": "^29.0.1",
|
||||
"eslint-plugin-prettier": "^5.5.4",
|
||||
"eslint-plugin-jest": "^29.12.1",
|
||||
"eslint-plugin-prettier": "^5.5.5",
|
||||
"jest": "^30.2.0",
|
||||
"make-coverage-badge": "^1.2.0",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"prettier": "^3.6.2",
|
||||
"prettier": "^3.8.0",
|
||||
"prettier-eslint": "^16.4.2",
|
||||
"rollup": "^4.52.5",
|
||||
"ts-jest": "^29.4.5",
|
||||
"rollup": "^4.55.1",
|
||||
"ts-jest": "^29.4.6",
|
||||
"ts-jest-resolver": "^2.0.1",
|
||||
"typescript": "^5.9.3"
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
import commonjs from '@rollup/plugin-commonjs'
|
||||
import nodeResolve from '@rollup/plugin-node-resolve'
|
||||
import terser from '@rollup/plugin-terser'
|
||||
import typescript from '@rollup/plugin-typescript'
|
||||
|
||||
const config = {
|
||||
@@ -13,12 +12,7 @@ const config = {
|
||||
format: 'es',
|
||||
sourcemap: true
|
||||
},
|
||||
plugins: [
|
||||
typescript(),
|
||||
nodeResolve({ preferBuiltins: true }),
|
||||
commonjs(),
|
||||
terser()
|
||||
]
|
||||
plugins: [typescript(), nodeResolve({ preferBuiltins: true }), commonjs()]
|
||||
}
|
||||
|
||||
export default config
|
||||
|
||||
105
src/derive.ts
Normal file
105
src/derive.ts
Normal file
@@ -0,0 +1,105 @@
|
||||
import { parse } from 'csv-parse/sync'
|
||||
import Handlebars from 'handlebars'
|
||||
import * as semver from 'semver'
|
||||
|
||||
/**
|
||||
* Context containing parsed semver components for template rendering.
|
||||
*/
|
||||
export interface SemverContext {
|
||||
/** "v" or "V" if input had a prefix, empty string otherwise */
|
||||
prefix: string
|
||||
/** Major version number */
|
||||
major: number
|
||||
/** Minor version number */
|
||||
minor: number
|
||||
/** Patch version number */
|
||||
patch: number
|
||||
/** Prerelease identifier (e.g., "beta.1"), empty if none */
|
||||
prerelease: string
|
||||
/** Build metadata (e.g., "build.123"), empty if none */
|
||||
build: string
|
||||
/** Full version string without prefix */
|
||||
version: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a version string into semver components.
|
||||
*
|
||||
* @param input - Version string (e.g., "v1.2.3", "1.2.3-beta.1+build.456")
|
||||
* @returns Parsed semver context
|
||||
* @throws Error if the version string is not valid semver
|
||||
*/
|
||||
export function parseSemver(input: string): SemverContext {
|
||||
const trimmed = input.trim()
|
||||
if (!trimmed) {
|
||||
throw new Error('Invalid semver: empty string')
|
||||
}
|
||||
|
||||
// Check for v/V prefix and preserve original case
|
||||
const firstChar = trimmed[0]
|
||||
const hasPrefix = firstChar === 'v' || firstChar === 'V'
|
||||
const prefix = hasPrefix ? firstChar : ''
|
||||
const versionStr = hasPrefix ? trimmed.slice(1) : trimmed
|
||||
|
||||
// Parse with semver library
|
||||
const parsed = semver.parse(versionStr)
|
||||
if (!parsed) {
|
||||
throw new Error(`Invalid semver: '${input}'`)
|
||||
}
|
||||
|
||||
return {
|
||||
prefix,
|
||||
major: parsed.major,
|
||||
minor: parsed.minor,
|
||||
patch: parsed.patch,
|
||||
prerelease: parsed.prerelease.join('.'),
|
||||
build: parsed.build.join('.'),
|
||||
version: parsed.version
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a single template string with semver context using Handlebars.
|
||||
* Supports {{#if variable}}...{{/if}} conditionals for optional sections.
|
||||
*
|
||||
* @param template - Handlebars template string
|
||||
* @param ctx - Semver context for substitution
|
||||
* @returns Rendered string
|
||||
*/
|
||||
export function renderTemplate(template: string, ctx: SemverContext): string {
|
||||
const compiled = Handlebars.compile(template, { noEscape: true })
|
||||
// Convert numbers to strings so 0 is truthy in conditionals
|
||||
const stringCtx = {
|
||||
...ctx,
|
||||
major: String(ctx.major),
|
||||
minor: String(ctx.minor),
|
||||
patch: String(ctx.patch)
|
||||
}
|
||||
return compiled(stringCtx)
|
||||
}
|
||||
|
||||
/**
|
||||
* Derive tags from a semver version string using a template.
|
||||
*
|
||||
* @param deriveFrom - Semver version string (e.g., "v1.2.3")
|
||||
* @param template - CSV/newline-delimited Handlebars template string
|
||||
* @returns Array of derived tag strings
|
||||
*/
|
||||
export function deriveTags(deriveFrom: string, template: string): string[] {
|
||||
const ctx = parseSemver(deriveFrom)
|
||||
|
||||
// Render template with Handlebars first, enabling conditional tag inclusion
|
||||
const rendered = renderTemplate(template, ctx)
|
||||
|
||||
// Parse rendered result as CSV/newline delimited
|
||||
const tags = (
|
||||
parse(rendered, {
|
||||
delimiter: ',',
|
||||
trim: true,
|
||||
relax_column_count: true
|
||||
}) as string[][]
|
||||
).flat()
|
||||
|
||||
// Exclude empty tags and tags that are just the prefix with no version data
|
||||
return tags.filter((tag) => tag.length > 0 && tag !== ctx.prefix)
|
||||
}
|
||||
@@ -1,16 +1,20 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as github from '@actions/github'
|
||||
import { parseTagsInput, type Tag } from './tags.js'
|
||||
import { parse } from 'csv-parse/sync'
|
||||
import { deriveTags } from './derive.js'
|
||||
|
||||
const WHEN_EXISTS_MODES = ['update', 'skip', 'fail'] as const
|
||||
export type WhenExistsMode = (typeof WHEN_EXISTS_MODES)[number]
|
||||
|
||||
export interface Inputs {
|
||||
tags: Tag[]
|
||||
tags: string[]
|
||||
defaultRef: string
|
||||
whenExists: WhenExistsMode
|
||||
annotation: string
|
||||
dryRun: boolean
|
||||
owner: string
|
||||
repo: string
|
||||
octokit: ReturnType<typeof github.getOctokit>
|
||||
token: string
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -30,30 +34,64 @@ function validateWhenExists(input: string): WhenExistsMode {
|
||||
return input as WhenExistsMode
|
||||
}
|
||||
|
||||
const DEFAULT_DERIVE_FROM_TEMPLATE =
|
||||
'{{prefix}}{{major}},{{prefix}}{{major}}.{{minor}}'
|
||||
|
||||
/**
|
||||
* Get and validate action inputs.
|
||||
*
|
||||
* @returns Parsed and validated inputs
|
||||
*/
|
||||
export async function getInputs(): Promise<Inputs> {
|
||||
const tagsInput: string = core.getInput('tags', { required: true })
|
||||
export function getInputs(): Inputs {
|
||||
const tagsInput: string = core.getInput('tags')
|
||||
const deriveFrom: string = core.getInput('derive_from')
|
||||
const deriveFromTemplate: string =
|
||||
core.getInput('derive_from_template') || DEFAULT_DERIVE_FROM_TEMPLATE
|
||||
const defaultRef: string = core.getInput('ref')
|
||||
const whenExistsInput = core.getInput('when_exists') || 'update'
|
||||
const whenExists = validateWhenExists(whenExistsInput)
|
||||
const annotation: string = core.getInput('annotation')
|
||||
const dryRun: boolean = core.getBooleanInput('dry_run')
|
||||
const token: string = core.getInput('github_token', {
|
||||
required: true
|
||||
})
|
||||
|
||||
const octokit = github.getOctokit(token)
|
||||
const { owner, repo } = github.context.repo
|
||||
|
||||
const tags = await parseTagsInput(octokit, tagsInput, defaultRef, owner, repo)
|
||||
// Parse explicit tags as CSV/newline delimited strings
|
||||
const explicitTags: string[] = tagsInput
|
||||
? (
|
||||
parse(tagsInput, {
|
||||
delimiter: ',',
|
||||
trim: true,
|
||||
relax_column_count: true
|
||||
}) as string[][]
|
||||
).flat()
|
||||
: []
|
||||
|
||||
// Derive tags from semver version string if provided
|
||||
const derivedTags: string[] = deriveFrom
|
||||
? deriveTags(deriveFrom, deriveFromTemplate)
|
||||
: []
|
||||
|
||||
// Combine explicit and derived tags
|
||||
const tags = [...explicitTags, ...derivedTags]
|
||||
|
||||
// Validate that at least one tag source is provided
|
||||
if (tags.length === 0) {
|
||||
throw new Error(
|
||||
"No tags specified. Provide 'tags' input, 'derive_from' input, or both."
|
||||
)
|
||||
}
|
||||
|
||||
return {
|
||||
tags,
|
||||
defaultRef,
|
||||
whenExists,
|
||||
annotation,
|
||||
dryRun,
|
||||
owner,
|
||||
repo,
|
||||
octokit
|
||||
token
|
||||
}
|
||||
}
|
||||
|
||||
47
src/logger.ts
Normal file
47
src/logger.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import * as core from '@actions/core'
|
||||
import type { AnnotationProperties } from '@actions/core'
|
||||
|
||||
/**
|
||||
* Logger interface that mirrors @actions/core logging functions.
|
||||
*/
|
||||
export interface Logger {
|
||||
debug: (message: string) => void
|
||||
info: (message: string) => void
|
||||
notice: (message: string | Error, properties?: AnnotationProperties) => void
|
||||
warning: (message: string | Error, properties?: AnnotationProperties) => void
|
||||
error: (message: string | Error, properties?: AnnotationProperties) => void
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a logger that optionally prefixes all messages.
|
||||
*
|
||||
* @param prefix - Optional prefix to prepend to all log messages
|
||||
* @returns Logger instance with prefixed messages
|
||||
*/
|
||||
export function createLogger(prefix: string = ''): Logger {
|
||||
const prefixMessage = (msg: string | Error): string | Error => {
|
||||
if (!prefix) {
|
||||
return msg
|
||||
}
|
||||
if (typeof msg === 'string') {
|
||||
return `${prefix}${msg}`
|
||||
}
|
||||
// Wrap Error with prefixed message, preserving the original as cause
|
||||
const wrapped = new Error(`${prefix}${msg.message}`, { cause: msg })
|
||||
if (msg.stack) {
|
||||
wrapped.stack = msg.stack
|
||||
}
|
||||
return wrapped
|
||||
}
|
||||
|
||||
return {
|
||||
debug: (message: string) => core.debug(`${prefix}${message}`),
|
||||
info: (message: string) => core.info(`${prefix}${message}`),
|
||||
notice: (message: string | Error, properties?: AnnotationProperties) =>
|
||||
core.notice(prefixMessage(message), properties),
|
||||
warning: (message: string | Error, properties?: AnnotationProperties) =>
|
||||
core.warning(prefixMessage(message), properties),
|
||||
error: (message: string | Error, properties?: AnnotationProperties) =>
|
||||
core.error(prefixMessage(message), properties)
|
||||
}
|
||||
}
|
||||
45
src/main.ts
45
src/main.ts
@@ -1,6 +1,7 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as github from '@actions/github'
|
||||
import { getInputs } from './inputs.js'
|
||||
import { processTag } from './tags.js'
|
||||
import { planTagOperations, executeTagOperation } from './tags.js'
|
||||
|
||||
/**
|
||||
* The main function for the action.
|
||||
@@ -9,38 +10,40 @@ import { processTag } from './tags.js'
|
||||
*/
|
||||
export async function run(): Promise<void> {
|
||||
try {
|
||||
let inputs
|
||||
try {
|
||||
inputs = await getInputs()
|
||||
} catch (error) {
|
||||
// For parsing/validation errors, pass message directly.
|
||||
const message = error instanceof Error ? error.message : String(error)
|
||||
core.setFailed(message)
|
||||
return
|
||||
}
|
||||
const inputs = getInputs()
|
||||
const octokit = github.getOctokit(inputs.token)
|
||||
const operations = await planTagOperations(inputs, octokit)
|
||||
|
||||
const { tags, whenExists, owner, repo, octokit } = inputs
|
||||
if (inputs.dryRun) {
|
||||
core.info('[dry-run] Dry-run mode enabled, no changes will be made.')
|
||||
}
|
||||
|
||||
const created: string[] = []
|
||||
const updated: string[] = []
|
||||
const skipped: string[] = []
|
||||
|
||||
// Create or update all tags.
|
||||
for (const tag of tags) {
|
||||
const result = await processTag(tag, whenExists, owner, repo, octokit)
|
||||
// Execute all planned operations.
|
||||
for (const operation of operations) {
|
||||
await executeTagOperation(operation, octokit, { dryRun: inputs.dryRun })
|
||||
|
||||
if (result === 'failed') {
|
||||
return
|
||||
} else if (result === 'created') {
|
||||
created.push(tag.name)
|
||||
} else if (result === 'updated') {
|
||||
updated.push(tag.name)
|
||||
// Only track actual changes when not in dry-run mode
|
||||
if (!inputs.dryRun) {
|
||||
if (operation.operation === 'create') {
|
||||
created.push(operation.name)
|
||||
} else if (operation.operation === 'update') {
|
||||
updated.push(operation.name)
|
||||
} else if (operation.operation === 'skip') {
|
||||
skipped.push(operation.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
core.setOutput('created', created)
|
||||
core.setOutput('updated', updated)
|
||||
core.setOutput('skipped', skipped)
|
||||
core.setOutput('tags', created.concat(updated))
|
||||
} catch (error) {
|
||||
core.setFailed(`Action failed with error: ${String(error)}`)
|
||||
const message = error instanceof Error ? error.message : String(error)
|
||||
core.setFailed(message)
|
||||
}
|
||||
}
|
||||
|
||||
554
src/tags.ts
554
src/tags.ts
@@ -1,184 +1,319 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as github from '@actions/github'
|
||||
import { parse } from 'csv-parse/sync'
|
||||
import type { Inputs } from './inputs.js'
|
||||
import { createLogger, type Logger } from './logger.js'
|
||||
|
||||
export interface Tag {
|
||||
export interface ExistingTagInfo {
|
||||
commitSHA: string
|
||||
isAnnotated: boolean
|
||||
annotation?: string
|
||||
}
|
||||
|
||||
interface BaseOperation {
|
||||
name: string
|
||||
ref: string
|
||||
sha: string
|
||||
owner: string
|
||||
repo: string
|
||||
}
|
||||
|
||||
export type TagResult = 'created' | 'updated' | 'skipped' | 'failed'
|
||||
export interface CreateOperation extends BaseOperation {
|
||||
operation: 'create'
|
||||
annotation: string
|
||||
}
|
||||
|
||||
export interface UpdateOperation extends BaseOperation {
|
||||
operation: 'update'
|
||||
annotation: string
|
||||
existingSHA: string
|
||||
existingIsAnnotated: boolean
|
||||
reasons: string[]
|
||||
}
|
||||
|
||||
export interface SkipOperation extends BaseOperation {
|
||||
operation: 'skip'
|
||||
existingIsAnnotated: boolean
|
||||
reason: 'when_exists_skip' | 'already_matches'
|
||||
}
|
||||
|
||||
export type TagOperation = CreateOperation | UpdateOperation | SkipOperation
|
||||
|
||||
export interface ExecuteOptions {
|
||||
dryRun?: boolean
|
||||
}
|
||||
|
||||
interface ReadContext {
|
||||
owner: string
|
||||
repo: string
|
||||
octokit: ReturnType<typeof github.getOctokit>
|
||||
}
|
||||
|
||||
interface Context extends ReadContext {
|
||||
dryRun: boolean
|
||||
log: Logger
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse tags input string and resolve refs to SHAs.
|
||||
* Plan tag operations based on inputs.
|
||||
*
|
||||
* @param inputs - The validated inputs containing tags, refs, and configuration
|
||||
* @param octokit - The GitHub API client
|
||||
* @param tagsInput - The raw tags input string
|
||||
* @param defaultRef - The default ref to use if not specified per-tag
|
||||
* @param owner - The repository owner
|
||||
* @param repo - The repository name
|
||||
* @returns Array of desired tags with resolved SHAs
|
||||
* @returns Array of planned tag operations (create, update, or skip)
|
||||
*/
|
||||
export async function parseTagsInput(
|
||||
octokit: ReturnType<typeof github.getOctokit>,
|
||||
tagsInput: string,
|
||||
defaultRef: string,
|
||||
owner: string,
|
||||
repo: string
|
||||
): Promise<Tag[]> {
|
||||
const parsedTags: string[] = (
|
||||
parse(tagsInput, {
|
||||
delimiter: ',',
|
||||
trim: true,
|
||||
relax_column_count: true
|
||||
}) as string[][]
|
||||
).flat()
|
||||
|
||||
export async function planTagOperations(
|
||||
inputs: Inputs,
|
||||
octokit: ReturnType<typeof github.getOctokit>
|
||||
): Promise<TagOperation[]> {
|
||||
const uniqueRefs = new Set<string>()
|
||||
const tags: Record<string, string> = {}
|
||||
const tagRefs: Record<string, string> = {}
|
||||
const tagAnnotations: Record<string, string> = {}
|
||||
|
||||
for (const tag of inputs.tags) {
|
||||
const parts = tag.split(':')
|
||||
const tagName = (parts[0] || '').trim()
|
||||
const tagRef = (parts[1] || '').trim()
|
||||
// Join remaining parts back with colons to preserve annotation content
|
||||
const tagAnnotation = parts.slice(2).join(':').trim()
|
||||
|
||||
for (const tag of parsedTags) {
|
||||
const parts = tag.split(':').map((s) => s.trim())
|
||||
if (parts.length > 2) {
|
||||
throw new Error(
|
||||
`Invalid tag specification '${tag}': too many colons. ` +
|
||||
`Format should be 'tag' or 'tag:ref'.`
|
||||
)
|
||||
}
|
||||
const [tagName, tagRef] = parts
|
||||
if (!tagName) {
|
||||
// Skip completely empty tags, but fail on invalid ones like ":main"
|
||||
if (tagRef) {
|
||||
if (tagRef || tagAnnotation) {
|
||||
throw new Error(`Invalid tag: '${tag}'`)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
const ref = tagRef || defaultRef
|
||||
const ref = tagRef || inputs.defaultRef
|
||||
if (!ref) {
|
||||
throw new Error("Missing ref: provide 'ref' input or specify per-tag ref")
|
||||
}
|
||||
|
||||
// Check for duplicate tag with different ref.
|
||||
if (tags[tagName] && tags[tagName] !== ref) {
|
||||
// Check for duplicate tag with different ref
|
||||
if (tagRefs[tagName] && tagRefs[tagName] !== ref) {
|
||||
throw new Error(
|
||||
`Duplicate tag '${tagName}' with different refs: ` +
|
||||
`'${tags[tagName]}' and '${ref}'`
|
||||
`'${tagRefs[tagName]}' and '${ref}'`
|
||||
)
|
||||
}
|
||||
|
||||
tags[tagName] = ref
|
||||
tagRefs[tagName] = ref
|
||||
if (tagAnnotation) {
|
||||
tagAnnotations[tagName] = tagAnnotation
|
||||
}
|
||||
uniqueRefs.add(ref)
|
||||
}
|
||||
|
||||
// Pre-resolve all unique refs in parallel.
|
||||
const refToSha: Record<string, string> = {}
|
||||
const ctx: ReadContext = { owner: inputs.owner, repo: inputs.repo, octokit }
|
||||
const refSHAs: Record<string, string> = {}
|
||||
await Promise.all(
|
||||
Array.from(uniqueRefs).map(async (ref) => {
|
||||
refToSha[ref] = await resolveRefToSha(octokit, owner, repo, ref)
|
||||
refSHAs[ref] = await resolveRefToSha(ctx, ref)
|
||||
})
|
||||
)
|
||||
|
||||
// Build result array with resolved SHAs.
|
||||
const result: Tag[] = []
|
||||
for (const tagName in tags) {
|
||||
const tagRef = tags[tagName]
|
||||
result.push({
|
||||
name: tagName,
|
||||
ref: tagRef,
|
||||
sha: refToSha[tagRef]
|
||||
// Build result array with planned operations
|
||||
const tagNames = Object.keys(tagRefs)
|
||||
const result: TagOperation[] = await Promise.all(
|
||||
tagNames.map(async (tagName) => {
|
||||
const tagRef = tagRefs[tagName]
|
||||
const sha = refSHAs[tagRef]
|
||||
const annotation = tagAnnotations[tagName] || inputs.annotation
|
||||
|
||||
// Check if tag already exists
|
||||
let existing: ExistingTagInfo | undefined
|
||||
try {
|
||||
existing = await fetchTagInfo(ctx, tagName)
|
||||
|
||||
// Fail early if when_exists is 'fail'
|
||||
if (inputs.whenExists === 'fail') {
|
||||
throw new Error(`Tag '${tagName}' already exists.`)
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
// Check if it's a GitHub API error with a status property
|
||||
if (typeof error === 'object' && error !== null && 'status' in error) {
|
||||
const apiError = error as { status: number; message?: string }
|
||||
if (apiError.status === 404) {
|
||||
// Tag doesn't exist, existing remains undefined
|
||||
} else {
|
||||
// Some other API error
|
||||
throw new Error(
|
||||
`Failed to check if tag '${tagName}' exists: ${apiError.message || String(error)}`
|
||||
)
|
||||
}
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
const baseOp = {
|
||||
name: tagName,
|
||||
ref: tagRef,
|
||||
sha,
|
||||
owner: inputs.owner,
|
||||
repo: inputs.repo
|
||||
}
|
||||
|
||||
// Tag doesn't exist - plan creation
|
||||
if (!existing) {
|
||||
return {
|
||||
...baseOp,
|
||||
operation: 'create',
|
||||
annotation
|
||||
} as CreateOperation
|
||||
}
|
||||
|
||||
// Tag exists - determine operation based on mode and state
|
||||
if (inputs.whenExists === 'skip') {
|
||||
return {
|
||||
...baseOp,
|
||||
operation: 'skip',
|
||||
existingIsAnnotated: existing.isAnnotated,
|
||||
reason: 'when_exists_skip'
|
||||
} as SkipOperation
|
||||
}
|
||||
|
||||
// whenExists === 'update' - check if update is needed
|
||||
const { commitMatches, annotationMatches } = compareTagState(
|
||||
sha,
|
||||
annotation,
|
||||
existing
|
||||
)
|
||||
|
||||
if (commitMatches && annotationMatches) {
|
||||
return {
|
||||
...baseOp,
|
||||
operation: 'skip',
|
||||
existingIsAnnotated: existing.isAnnotated,
|
||||
reason: 'already_matches'
|
||||
} as SkipOperation
|
||||
}
|
||||
|
||||
// Plan update with reasons
|
||||
const reasons = getUpdateReasons(sha, annotation, existing)
|
||||
return {
|
||||
...baseOp,
|
||||
operation: 'update',
|
||||
annotation,
|
||||
existingSHA: existing.commitSHA,
|
||||
existingIsAnnotated: existing.isAnnotated,
|
||||
reasons
|
||||
} as UpdateOperation
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a single desired tag: create or update it based on configuration.
|
||||
* Execute a planned tag operation.
|
||||
*
|
||||
* @param tag - The desired tag to process
|
||||
* @param whenExists - What to do if the tag already exists
|
||||
* @param owner - Repository owner
|
||||
* @param repo - Repository name
|
||||
* @param operation - The planned tag operation to execute
|
||||
* @param octokit - GitHub API client
|
||||
* @returns The result of the tag operation
|
||||
* @param options - Execution options (e.g., dryRun)
|
||||
*/
|
||||
export async function processTag(
|
||||
tag: Tag,
|
||||
whenExists: 'update' | 'skip' | 'fail',
|
||||
owner: string,
|
||||
repo: string,
|
||||
octokit: ReturnType<typeof github.getOctokit>
|
||||
): Promise<TagResult> {
|
||||
const { name: tagName, sha } = tag
|
||||
export async function executeTagOperation(
|
||||
operation: TagOperation,
|
||||
octokit: ReturnType<typeof github.getOctokit>,
|
||||
options: ExecuteOptions = {}
|
||||
): Promise<void> {
|
||||
const dryRun = options.dryRun ?? false
|
||||
const ctx: Context = {
|
||||
owner: operation.owner,
|
||||
repo: operation.repo,
|
||||
octokit,
|
||||
dryRun,
|
||||
log: createLogger(dryRun ? '[dry-run] ' : '')
|
||||
}
|
||||
|
||||
try {
|
||||
// Check if the tag exists.
|
||||
const existing = await octokit.rest.git.getRef({
|
||||
owner,
|
||||
repo,
|
||||
ref: `tags/${tagName}`
|
||||
})
|
||||
if (operation.operation === 'skip') {
|
||||
logSkipOperation(ctx, operation)
|
||||
return
|
||||
}
|
||||
|
||||
// If the tag exists, decide action based on 'when_exists'.
|
||||
if (whenExists === 'update') {
|
||||
const existingSHA = existing.data.object.sha
|
||||
if (existingSHA === sha) {
|
||||
core.info(`Tag '${tagName}' already exists with desired SHA ${sha}.`)
|
||||
return 'skipped'
|
||||
}
|
||||
if (operation.operation === 'create') {
|
||||
await createTag(ctx, operation)
|
||||
return
|
||||
}
|
||||
|
||||
core.info(
|
||||
`Tag '${tagName}' exists, updating to SHA ${sha} ` +
|
||||
`(was ${existingSHA}).`
|
||||
)
|
||||
await octokit.rest.git.updateRef({
|
||||
owner,
|
||||
repo,
|
||||
ref: `tags/${tagName}`,
|
||||
sha,
|
||||
force: true
|
||||
})
|
||||
return 'updated'
|
||||
} else if (whenExists === 'skip') {
|
||||
core.info(`Tag '${tagName}' exists, skipping.`)
|
||||
return 'skipped'
|
||||
} else {
|
||||
// whenExists === 'fail'
|
||||
core.setFailed(`Tag '${tagName}' already exists.`)
|
||||
return 'failed'
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
const err = error as { status?: number }
|
||||
if (err?.status !== 404) {
|
||||
throw error
|
||||
}
|
||||
if (operation.operation === 'update') {
|
||||
await updateExistingTag(ctx, operation)
|
||||
return
|
||||
}
|
||||
|
||||
// If the tag doesn't exist (404), create it.
|
||||
core.info(`Tag '${tagName}' does not exist, creating with SHA ${sha}.`)
|
||||
await octokit.rest.git.createRef({
|
||||
owner,
|
||||
repo,
|
||||
ref: `refs/tags/${tagName}`,
|
||||
sha
|
||||
})
|
||||
return 'created'
|
||||
throw new Error(
|
||||
`Unknown operation type: ${(operation as TagOperation).operation}`
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a skip operation.
|
||||
*/
|
||||
function logSkipOperation(ctx: Context, operation: SkipOperation): void {
|
||||
if (operation.reason === 'when_exists_skip') {
|
||||
ctx.log.info(`Tag '${operation.name}' exists, skipping.`)
|
||||
} else {
|
||||
ctx.log.info(
|
||||
`Tag '${operation.name}' already exists with desired ` +
|
||||
`commit SHA ${operation.sha}` +
|
||||
(operation.existingIsAnnotated ? ' (annotated).' : '.')
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
async function resolveRefToSha(
|
||||
octokit: ReturnType<typeof github.getOctokit>,
|
||||
owner: string,
|
||||
repo: string,
|
||||
ref: string
|
||||
): Promise<string> {
|
||||
/**
|
||||
* Fetch information about an existing tag, dereferencing if annotated.
|
||||
*
|
||||
* @param ctx - Read-only operation context
|
||||
* @param tagName - The name of the tag to fetch
|
||||
* @returns Information about the existing tag
|
||||
*/
|
||||
async function fetchTagInfo(
|
||||
ctx: ReadContext,
|
||||
tagName: string
|
||||
): Promise<ExistingTagInfo> {
|
||||
const ref = await ctx.octokit.rest.git.getRef({
|
||||
owner: ctx.owner,
|
||||
repo: ctx.repo,
|
||||
ref: `tags/${tagName}`
|
||||
})
|
||||
const object = ref.data.object
|
||||
const isAnnotated = object.type === 'tag'
|
||||
|
||||
if (!isAnnotated) {
|
||||
return {
|
||||
commitSHA: object.sha,
|
||||
isAnnotated: false
|
||||
}
|
||||
}
|
||||
|
||||
// Dereference annotated tag to get underlying commit
|
||||
const tagRef = await ctx.octokit.rest.git.getTag({
|
||||
owner: ctx.owner,
|
||||
repo: ctx.repo,
|
||||
tag_sha: object.sha
|
||||
})
|
||||
|
||||
return {
|
||||
commitSHA: tagRef.data.object.sha,
|
||||
isAnnotated: true,
|
||||
annotation: tagRef.data.message
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a ref to a SHA.
|
||||
*
|
||||
* @param ctx - Read-only operation context
|
||||
* @param ref - The ref to resolve
|
||||
* @returns The SHA
|
||||
*/
|
||||
async function resolveRefToSha(ctx: ReadContext, ref: string): Promise<string> {
|
||||
try {
|
||||
const {
|
||||
data: { sha }
|
||||
} = await octokit.rest.repos.getCommit({
|
||||
owner,
|
||||
repo,
|
||||
} = await ctx.octokit.rest.repos.getCommit({
|
||||
owner: ctx.owner,
|
||||
repo: ctx.repo,
|
||||
ref
|
||||
})
|
||||
|
||||
@@ -187,3 +322,176 @@ async function resolveRefToSha(
|
||||
throw new Error(`Failed to resolve ref '${ref}' to a SHA: ${String(error)}`)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing tag to point to a new commit and/or annotation.
|
||||
*/
|
||||
async function updateExistingTag(
|
||||
ctx: Context,
|
||||
operation: UpdateOperation
|
||||
): Promise<void> {
|
||||
const commitMatches = operation.existingSHA === operation.sha
|
||||
const verb = ctx.dryRun ? 'Would update' : 'Updating'
|
||||
|
||||
if (commitMatches) {
|
||||
ctx.log.info(
|
||||
`${verb} tag '${operation.name}', ${operation.reasons.join(', ')}.`
|
||||
)
|
||||
} else {
|
||||
ctx.log.info(
|
||||
`${verb} tag '${operation.name}'` +
|
||||
`${operation.existingIsAnnotated ? ' (annotated)' : ''} ` +
|
||||
`to ${operation.reasons.join(', ')}.`
|
||||
)
|
||||
}
|
||||
|
||||
if (ctx.dryRun) {
|
||||
return
|
||||
}
|
||||
|
||||
const targetSha = await resolveTargetSHA(
|
||||
ctx,
|
||||
operation.name,
|
||||
operation.sha,
|
||||
operation.annotation
|
||||
)
|
||||
|
||||
await ctx.octokit.rest.git.updateRef({
|
||||
owner: ctx.owner,
|
||||
repo: ctx.repo,
|
||||
ref: `tags/${operation.name}`,
|
||||
sha: targetSha,
|
||||
force: true
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a tag (doesn't exist yet).
|
||||
*/
|
||||
async function createTag(
|
||||
ctx: Context,
|
||||
operation: CreateOperation
|
||||
): Promise<void> {
|
||||
const verb = ctx.dryRun ? 'Would create' : 'Creating'
|
||||
ctx.log.info(
|
||||
`${verb} tag '${operation.name}' at commit SHA ${operation.sha}` +
|
||||
(operation.annotation ? ' (annotated).' : '.')
|
||||
)
|
||||
|
||||
if (ctx.dryRun) {
|
||||
return
|
||||
}
|
||||
|
||||
const targetSha = await resolveTargetSHA(
|
||||
ctx,
|
||||
operation.name,
|
||||
operation.sha,
|
||||
operation.annotation
|
||||
)
|
||||
|
||||
await ctx.octokit.rest.git.createRef({
|
||||
owner: ctx.owner,
|
||||
repo: ctx.repo,
|
||||
ref: `refs/tags/${operation.name}`,
|
||||
sha: targetSha
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the target SHA for a tag (creates annotated tag object if needed).
|
||||
*
|
||||
* @param ctx - Read-only operation context
|
||||
* @param tagName - The tag name
|
||||
* @param commitSha - The commit SHA
|
||||
* @param annotation - The annotation message (if any)
|
||||
* @returns The SHA to use (tag object SHA if annotated, commit SHA otherwise)
|
||||
*/
|
||||
async function resolveTargetSHA(
|
||||
ctx: ReadContext,
|
||||
tagName: string,
|
||||
commitSha: string,
|
||||
annotation: string
|
||||
): Promise<string> {
|
||||
if (!annotation) {
|
||||
return commitSha
|
||||
}
|
||||
|
||||
const tagObject = await ctx.octokit.rest.git.createTag({
|
||||
owner: ctx.owner,
|
||||
repo: ctx.repo,
|
||||
tag: tagName,
|
||||
message: annotation,
|
||||
object: commitSha,
|
||||
type: 'commit'
|
||||
})
|
||||
|
||||
return tagObject.data.sha
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare existing tag state with desired target state.
|
||||
*
|
||||
* @param sha - The desired commit SHA
|
||||
* @param annotation - The desired annotation
|
||||
* @param existing - Information about the existing tag
|
||||
* @returns Object indicating whether commit and annotation match
|
||||
*/
|
||||
function compareTagState(
|
||||
sha: string,
|
||||
annotation: string,
|
||||
existing: ExistingTagInfo
|
||||
): {
|
||||
commitMatches: boolean
|
||||
annotationMatches: boolean
|
||||
} {
|
||||
const isAnnotated = existing.isAnnotated === true
|
||||
|
||||
const commitMatches = existing.commitSHA === sha
|
||||
const annotationMatches =
|
||||
(isAnnotated && !!annotation && existing.annotation === annotation) ||
|
||||
(!isAnnotated && !annotation) ||
|
||||
false
|
||||
|
||||
return { commitMatches, annotationMatches }
|
||||
}
|
||||
|
||||
/**
|
||||
* Get update reason messages based on what changed.
|
||||
*
|
||||
* @param sha - The desired commit SHA
|
||||
* @param annotation - The desired annotation
|
||||
* @param existing - Information about the existing tag
|
||||
* @returns Array of reason strings
|
||||
*/
|
||||
function getUpdateReasons(
|
||||
sha: string,
|
||||
annotation: string,
|
||||
existing: ExistingTagInfo
|
||||
): string[] {
|
||||
const { commitMatches, annotationMatches } = compareTagState(
|
||||
sha,
|
||||
annotation,
|
||||
existing
|
||||
)
|
||||
const reasons: string[] = []
|
||||
|
||||
if (!commitMatches) {
|
||||
reasons.push(`commit SHA ${sha} (was ${existing.commitSHA})`)
|
||||
}
|
||||
|
||||
if (!annotationMatches && annotation) {
|
||||
if (existing.isAnnotated === true) {
|
||||
reasons.push('annotation message changed')
|
||||
} else {
|
||||
reasons.push('adding annotation')
|
||||
}
|
||||
} else if (
|
||||
!annotationMatches &&
|
||||
!annotation &&
|
||||
existing.isAnnotated === true
|
||||
) {
|
||||
reasons.push('removing annotation')
|
||||
}
|
||||
|
||||
return reasons
|
||||
}
|
||||
|
||||
420
tests/derive.test.ts
Normal file
420
tests/derive.test.ts
Normal file
@@ -0,0 +1,420 @@
|
||||
/**
|
||||
* Unit tests for the derive module, src/derive.ts
|
||||
*/
|
||||
import { parseSemver, renderTemplate, deriveTags } from '../src/derive.js'
|
||||
|
||||
describe('parseSemver', () => {
|
||||
it('parses simple version without prefix', () => {
|
||||
const result = parseSemver('1.2.3')
|
||||
expect(result).toEqual({
|
||||
prefix: '',
|
||||
major: 1,
|
||||
minor: 2,
|
||||
patch: 3,
|
||||
prerelease: '',
|
||||
build: '',
|
||||
version: '1.2.3'
|
||||
})
|
||||
})
|
||||
|
||||
it('parses version with v prefix', () => {
|
||||
const result = parseSemver('v1.2.3')
|
||||
expect(result).toEqual({
|
||||
prefix: 'v',
|
||||
major: 1,
|
||||
minor: 2,
|
||||
patch: 3,
|
||||
prerelease: '',
|
||||
build: '',
|
||||
version: '1.2.3'
|
||||
})
|
||||
})
|
||||
|
||||
it('parses version with uppercase V prefix', () => {
|
||||
const result = parseSemver('V1.2.3')
|
||||
expect(result).toEqual({
|
||||
prefix: 'V',
|
||||
major: 1,
|
||||
minor: 2,
|
||||
patch: 3,
|
||||
prerelease: '',
|
||||
build: '',
|
||||
version: '1.2.3'
|
||||
})
|
||||
})
|
||||
|
||||
it('parses version with prerelease', () => {
|
||||
const result = parseSemver('v1.0.0-beta.1')
|
||||
expect(result).toEqual({
|
||||
prefix: 'v',
|
||||
major: 1,
|
||||
minor: 0,
|
||||
patch: 0,
|
||||
prerelease: 'beta.1',
|
||||
build: '',
|
||||
version: '1.0.0-beta.1'
|
||||
})
|
||||
})
|
||||
|
||||
it('parses version with build metadata', () => {
|
||||
const result = parseSemver('v1.0.0+build.456')
|
||||
expect(result).toEqual({
|
||||
prefix: 'v',
|
||||
major: 1,
|
||||
minor: 0,
|
||||
patch: 0,
|
||||
prerelease: '',
|
||||
build: 'build.456',
|
||||
version: '1.0.0'
|
||||
})
|
||||
})
|
||||
|
||||
it('parses version with both prerelease and build metadata', () => {
|
||||
const result = parseSemver('v1.2.3-alpha.1+build.789')
|
||||
expect(result).toEqual({
|
||||
prefix: 'v',
|
||||
major: 1,
|
||||
minor: 2,
|
||||
patch: 3,
|
||||
prerelease: 'alpha.1',
|
||||
build: 'build.789',
|
||||
version: '1.2.3-alpha.1'
|
||||
})
|
||||
})
|
||||
|
||||
it('handles whitespace around version string', () => {
|
||||
const result = parseSemver(' v1.2.3 ')
|
||||
expect(result).toEqual({
|
||||
prefix: 'v',
|
||||
major: 1,
|
||||
minor: 2,
|
||||
patch: 3,
|
||||
prerelease: '',
|
||||
build: '',
|
||||
version: '1.2.3'
|
||||
})
|
||||
})
|
||||
|
||||
it('throws on empty string', () => {
|
||||
expect(() => parseSemver('')).toThrow('Invalid semver: empty string')
|
||||
})
|
||||
|
||||
it('throws on whitespace only', () => {
|
||||
expect(() => parseSemver(' ')).toThrow('Invalid semver: empty string')
|
||||
})
|
||||
|
||||
it('throws on invalid semver', () => {
|
||||
expect(() => parseSemver('not-a-version')).toThrow(
|
||||
"Invalid semver: 'not-a-version'"
|
||||
)
|
||||
})
|
||||
|
||||
it('throws on incomplete version', () => {
|
||||
expect(() => parseSemver('v1.2')).toThrow("Invalid semver: 'v1.2'")
|
||||
})
|
||||
})
|
||||
|
||||
describe('renderTemplate', () => {
|
||||
const ctx = {
|
||||
prefix: 'v',
|
||||
major: 1,
|
||||
minor: 2,
|
||||
patch: 3,
|
||||
prerelease: 'beta.1',
|
||||
build: 'build.456',
|
||||
version: '1.2.3-beta.1'
|
||||
}
|
||||
|
||||
it('renders prefix placeholder', () => {
|
||||
expect(renderTemplate('{{prefix}}', ctx)).toBe('v')
|
||||
})
|
||||
|
||||
it('renders major placeholder', () => {
|
||||
expect(renderTemplate('{{major}}', ctx)).toBe('1')
|
||||
})
|
||||
|
||||
it('renders minor placeholder', () => {
|
||||
expect(renderTemplate('{{minor}}', ctx)).toBe('2')
|
||||
})
|
||||
|
||||
it('renders patch placeholder', () => {
|
||||
expect(renderTemplate('{{patch}}', ctx)).toBe('3')
|
||||
})
|
||||
|
||||
it('renders prerelease placeholder', () => {
|
||||
expect(renderTemplate('{{prerelease}}', ctx)).toBe('beta.1')
|
||||
})
|
||||
|
||||
it('renders build placeholder', () => {
|
||||
expect(renderTemplate('{{build}}', ctx)).toBe('build.456')
|
||||
})
|
||||
|
||||
it('renders version placeholder', () => {
|
||||
expect(renderTemplate('{{version}}', ctx)).toBe('1.2.3-beta.1')
|
||||
})
|
||||
|
||||
it('renders multiple placeholders', () => {
|
||||
expect(renderTemplate('{{prefix}}{{major}}.{{minor}}', ctx)).toBe('v1.2')
|
||||
})
|
||||
|
||||
it('renders same placeholder multiple times', () => {
|
||||
expect(renderTemplate('{{major}}-{{major}}', ctx)).toBe('1-1')
|
||||
})
|
||||
|
||||
it('preserves text without placeholders', () => {
|
||||
expect(renderTemplate('latest', ctx)).toBe('latest')
|
||||
})
|
||||
|
||||
it('handles empty prefix', () => {
|
||||
const noPrefix = { ...ctx, prefix: '' }
|
||||
expect(renderTemplate('{{prefix}}{{major}}', noPrefix)).toBe('1')
|
||||
})
|
||||
|
||||
it('handles empty prerelease', () => {
|
||||
const noPrerelease = { ...ctx, prerelease: '' }
|
||||
expect(renderTemplate('{{major}}-{{prerelease}}', noPrerelease)).toBe('1-')
|
||||
})
|
||||
|
||||
describe('Handlebars conditionals', () => {
|
||||
it('renders {{#if}} section when variable has value', () => {
|
||||
expect(
|
||||
renderTemplate('{{major}}{{#if prerelease}}-{{prerelease}}{{/if}}', ctx)
|
||||
).toBe('1-beta.1')
|
||||
})
|
||||
|
||||
it('omits {{#if}} section when variable is empty', () => {
|
||||
const noPrerelease = { ...ctx, prerelease: '' }
|
||||
expect(
|
||||
renderTemplate(
|
||||
'{{major}}{{#if prerelease}}-{{prerelease}}{{/if}}',
|
||||
noPrerelease
|
||||
)
|
||||
).toBe('1')
|
||||
})
|
||||
|
||||
it('handles {{#if}} with zero-valued numbers (converted to strings)', () => {
|
||||
const zeroMinor = { ...ctx, minor: 0 }
|
||||
expect(
|
||||
renderTemplate('{{major}}{{#if minor}}.{{minor}}{{/if}}', zeroMinor)
|
||||
).toBe('1.0')
|
||||
})
|
||||
|
||||
it('handles nested conditionals', () => {
|
||||
expect(
|
||||
renderTemplate(
|
||||
'{{major}}{{#if prerelease}}-{{prerelease}}{{#if build}}+{{build}}{{/if}}{{/if}}',
|
||||
ctx
|
||||
)
|
||||
).toBe('1-beta.1+build.456')
|
||||
})
|
||||
|
||||
it('handles nested conditionals with inner empty', () => {
|
||||
const noBuild = { ...ctx, build: '' }
|
||||
expect(
|
||||
renderTemplate(
|
||||
'{{major}}{{#if prerelease}}-{{prerelease}}{{#if build}}+{{build}}{{/if}}{{/if}}',
|
||||
noBuild
|
||||
)
|
||||
).toBe('1-beta.1')
|
||||
})
|
||||
|
||||
it('handles {{#unless}} for inverse logic', () => {
|
||||
const noPrerelease = { ...ctx, prerelease: '' }
|
||||
expect(
|
||||
renderTemplate('{{major}}{{#unless prerelease}}-stable{{/unless}}', ctx)
|
||||
).toBe('1')
|
||||
expect(
|
||||
renderTemplate(
|
||||
'{{major}}{{#unless prerelease}}-stable{{/unless}}',
|
||||
noPrerelease
|
||||
)
|
||||
).toBe('1-stable')
|
||||
})
|
||||
|
||||
it('handles multiple {{#if}} sections', () => {
|
||||
const noBuild = { ...ctx, build: '' }
|
||||
expect(
|
||||
renderTemplate(
|
||||
'{{major}}{{#if prerelease}}-{{prerelease}}{{/if}}{{#if build}}+{{build}}{{/if}}',
|
||||
noBuild
|
||||
)
|
||||
).toBe('1-beta.1')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('deriveTags', () => {
|
||||
it('generates tags with default-style template', () => {
|
||||
const result = deriveTags(
|
||||
'v1.2.3',
|
||||
'{{prefix}}{{major}},{{prefix}}{{major}}.{{minor}}'
|
||||
)
|
||||
expect(result).toEqual(['v1', 'v1.2'])
|
||||
})
|
||||
|
||||
it('generates single tag from simple template', () => {
|
||||
const result = deriveTags('v1.2.3', '{{prefix}}{{major}}')
|
||||
expect(result).toEqual(['v1'])
|
||||
})
|
||||
|
||||
it('handles version without prefix', () => {
|
||||
const result = deriveTags(
|
||||
'1.2.3',
|
||||
'{{prefix}}{{major}},{{prefix}}{{major}}.{{minor}}'
|
||||
)
|
||||
expect(result).toEqual(['1', '1.2'])
|
||||
})
|
||||
|
||||
it('handles prerelease in template', () => {
|
||||
const result = deriveTags(
|
||||
'v1.0.0-rc.1',
|
||||
'{{prefix}}{{major}}-{{prerelease}}'
|
||||
)
|
||||
expect(result).toEqual(['v1-rc.1'])
|
||||
})
|
||||
|
||||
it('filters empty tags and prefix-only tags from result', () => {
|
||||
const result = deriveTags('v1.2.3', '{{prefix}}{{major}},,{{prefix}}')
|
||||
expect(result).toEqual(['v1'])
|
||||
})
|
||||
|
||||
it('trims whitespace around template parts', () => {
|
||||
const result = deriveTags('v1.2.3', ' {{prefix}}{{major}} , latest ')
|
||||
expect(result).toEqual(['v1', 'latest'])
|
||||
})
|
||||
|
||||
it('generates full version tag', () => {
|
||||
const result = deriveTags('v1.2.3', '{{prefix}}{{version}}')
|
||||
expect(result).toEqual(['v1.2.3'])
|
||||
})
|
||||
|
||||
it('throws on invalid semver', () => {
|
||||
expect(() => deriveTags('invalid', '{{major}}')).toThrow(
|
||||
"Invalid semver: 'invalid'"
|
||||
)
|
||||
})
|
||||
|
||||
it('handles newline-delimited template', () => {
|
||||
const result = deriveTags(
|
||||
'v1.2.3',
|
||||
'{{prefix}}{{major}}\n{{prefix}}{{major}}.{{minor}}'
|
||||
)
|
||||
expect(result).toEqual(['v1', 'v1.2'])
|
||||
})
|
||||
|
||||
it('handles mixed newlines and commas in template', () => {
|
||||
const result = deriveTags(
|
||||
'v1.2.3',
|
||||
'{{prefix}}{{major}},{{prefix}}{{major}}.{{minor}}\nlatest'
|
||||
)
|
||||
expect(result).toEqual(['v1', 'v1.2', 'latest'])
|
||||
})
|
||||
|
||||
describe('with Handlebars conditionals', () => {
|
||||
it('generates tag with optional prerelease when present', () => {
|
||||
const result = deriveTags(
|
||||
'v1.0.0-beta.1',
|
||||
'{{prefix}}{{major}}{{#if prerelease}}-{{prerelease}}{{/if}}'
|
||||
)
|
||||
expect(result).toEqual(['v1-beta.1'])
|
||||
})
|
||||
|
||||
it('generates tag without prerelease section when absent', () => {
|
||||
const result = deriveTags(
|
||||
'v1.0.0',
|
||||
'{{prefix}}{{major}}{{#if prerelease}}-{{prerelease}}{{/if}}'
|
||||
)
|
||||
expect(result).toEqual(['v1'])
|
||||
})
|
||||
|
||||
it('generates multiple tags with conditionals', () => {
|
||||
const result = deriveTags(
|
||||
'v1.2.3-rc.1',
|
||||
'{{prefix}}{{major}},{{prefix}}{{major}}.{{minor}}{{#if prerelease}}-{{prerelease}}{{/if}}'
|
||||
)
|
||||
expect(result).toEqual(['v1', 'v1.2-rc.1'])
|
||||
})
|
||||
|
||||
it('handles build metadata conditional', () => {
|
||||
const result = deriveTags(
|
||||
'v1.0.0+build.123',
|
||||
'{{prefix}}{{major}}{{#if build}}+{{build}}{{/if}}'
|
||||
)
|
||||
expect(result).toEqual(['v1+build.123'])
|
||||
})
|
||||
|
||||
it('handles both prerelease and build conditionals', () => {
|
||||
const result = deriveTags(
|
||||
'v1.0.0-alpha.1+build.789',
|
||||
'{{prefix}}{{major}}{{#if prerelease}}-{{prerelease}}{{/if}}{{#if build}}+{{build}}{{/if}}'
|
||||
)
|
||||
expect(result).toEqual(['v1-alpha.1+build.789'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('conditional tag inclusion', () => {
|
||||
it('includes latest tag only for stable releases', () => {
|
||||
// Stable release gets latest tag
|
||||
const stable = deriveTags(
|
||||
'v1.2.3',
|
||||
'{{prefix}}{{major}},{{prefix}}{{major}}.{{minor}}{{#unless prerelease}},latest{{/unless}}'
|
||||
)
|
||||
expect(stable).toEqual(['v1', 'v1.2', 'latest'])
|
||||
|
||||
// Prerelease does not get latest tag
|
||||
const prerelease = deriveTags(
|
||||
'v1.2.3-beta.1',
|
||||
'{{prefix}}{{major}},{{prefix}}{{major}}.{{minor}}{{#unless prerelease}},latest{{/unless}}'
|
||||
)
|
||||
expect(prerelease).toEqual(['v1', 'v1.2'])
|
||||
})
|
||||
|
||||
it('conditionally includes entire tag group with {{#if}}', () => {
|
||||
// With prerelease: include prerelease-specific tags
|
||||
const withPre = deriveTags(
|
||||
'v2.0.0-rc.1',
|
||||
'{{prefix}}{{major}}{{#if prerelease}},{{prefix}}{{major}}-{{prerelease}}{{/if}}'
|
||||
)
|
||||
expect(withPre).toEqual(['v2', 'v2-rc.1'])
|
||||
|
||||
// Without prerelease: only major tag
|
||||
const withoutPre = deriveTags(
|
||||
'v2.0.0',
|
||||
'{{prefix}}{{major}}{{#if prerelease}},{{prefix}}{{major}}-{{prerelease}}{{/if}}'
|
||||
)
|
||||
expect(withoutPre).toEqual(['v2'])
|
||||
})
|
||||
|
||||
it('conditionally includes newline-separated tags', () => {
|
||||
// Stable release includes all tags
|
||||
const stable = deriveTags(
|
||||
'v1.0.0',
|
||||
'{{prefix}}{{major}}\n{{prefix}}{{major}}.{{minor}}{{#unless prerelease}}\nstable{{/unless}}'
|
||||
)
|
||||
expect(stable).toEqual(['v1', 'v1.0', 'stable'])
|
||||
|
||||
// Prerelease excludes stable tag
|
||||
const prerelease = deriveTags(
|
||||
'v1.0.0-alpha.1',
|
||||
'{{prefix}}{{major}}\n{{prefix}}{{major}}.{{minor}}{{#unless prerelease}}\nstable{{/unless}}'
|
||||
)
|
||||
expect(prerelease).toEqual(['v1', 'v1.0'])
|
||||
})
|
||||
|
||||
it('excludes multiple tags conditionally', () => {
|
||||
const result = deriveTags(
|
||||
'v1.0.0-beta.1',
|
||||
'{{prefix}}{{major}}{{#unless prerelease}},latest,stable,production{{/unless}}'
|
||||
)
|
||||
expect(result).toEqual(['v1'])
|
||||
})
|
||||
|
||||
it('includes multiple tags conditionally for stable', () => {
|
||||
const result = deriveTags(
|
||||
'v1.0.0',
|
||||
'{{prefix}}{{major}}{{#unless prerelease}},latest,stable,production{{/unless}}'
|
||||
)
|
||||
expect(result).toEqual(['v1', 'latest', 'stable', 'production'])
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -4,7 +4,9 @@ import { jest } from '@jest/globals'
|
||||
export const debug = jest.fn<typeof core.debug>()
|
||||
export const error = jest.fn<typeof core.error>()
|
||||
export const info = jest.fn<typeof core.info>()
|
||||
export const notice = jest.fn<typeof core.notice>()
|
||||
export const getInput = jest.fn<typeof core.getInput>()
|
||||
export const getBooleanInput = jest.fn<typeof core.getBooleanInput>()
|
||||
export const setOutput = jest.fn<typeof core.setOutput>()
|
||||
export const setFailed = jest.fn<typeof core.setFailed>()
|
||||
export const warning = jest.fn<typeof core.warning>()
|
||||
@@ -5,7 +5,9 @@ export const mockOctokit = {
|
||||
git: {
|
||||
getRef: jest.fn<(args: unknown) => Promise<unknown>>(),
|
||||
createRef: jest.fn<(args: unknown) => Promise<unknown>>(),
|
||||
updateRef: jest.fn<(args: unknown) => Promise<unknown>>()
|
||||
updateRef: jest.fn<(args: unknown) => Promise<unknown>>(),
|
||||
createTag: jest.fn<(args: unknown) => Promise<unknown>>(),
|
||||
getTag: jest.fn<(args: unknown) => Promise<unknown>>()
|
||||
},
|
||||
repos: {
|
||||
getCommit: jest.fn<(args: unknown) => Promise<unknown>>()
|
||||
193
tests/logger.test.ts
Normal file
193
tests/logger.test.ts
Normal file
@@ -0,0 +1,193 @@
|
||||
/**
|
||||
* Unit tests for the logger module, src/logger.ts
|
||||
*/
|
||||
import { jest } from '@jest/globals'
|
||||
import * as core from './fixtures/core.js'
|
||||
|
||||
jest.unstable_mockModule('@actions/core', () => core)
|
||||
|
||||
const { createLogger } = await import('../src/logger.js')
|
||||
|
||||
describe('createLogger', () => {
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks()
|
||||
})
|
||||
|
||||
describe('without prefix', () => {
|
||||
it('calls core.debug with the message', () => {
|
||||
const log = createLogger()
|
||||
log.debug('test debug message')
|
||||
expect(core.debug).toHaveBeenCalledWith('test debug message')
|
||||
})
|
||||
|
||||
it('calls core.info with the message', () => {
|
||||
const log = createLogger()
|
||||
log.info('test info message')
|
||||
expect(core.info).toHaveBeenCalledWith('test info message')
|
||||
})
|
||||
|
||||
it('calls core.notice with string message', () => {
|
||||
const log = createLogger()
|
||||
log.notice('test notice message')
|
||||
expect(core.notice).toHaveBeenCalledWith('test notice message', undefined)
|
||||
})
|
||||
|
||||
it('calls core.notice with Error unchanged', () => {
|
||||
const log = createLogger()
|
||||
const error = new Error('test error')
|
||||
log.notice(error)
|
||||
expect(core.notice).toHaveBeenCalledWith(error, undefined)
|
||||
})
|
||||
|
||||
it('calls core.notice with properties', () => {
|
||||
const log = createLogger()
|
||||
const props = { title: 'Notice Title' }
|
||||
log.notice('test notice', props)
|
||||
expect(core.notice).toHaveBeenCalledWith('test notice', props)
|
||||
})
|
||||
|
||||
it('calls core.warning with string message', () => {
|
||||
const log = createLogger()
|
||||
log.warning('test warning message')
|
||||
expect(core.warning).toHaveBeenCalledWith(
|
||||
'test warning message',
|
||||
undefined
|
||||
)
|
||||
})
|
||||
|
||||
it('calls core.warning with Error unchanged', () => {
|
||||
const log = createLogger()
|
||||
const error = new Error('warning error')
|
||||
log.warning(error)
|
||||
expect(core.warning).toHaveBeenCalledWith(error, undefined)
|
||||
})
|
||||
|
||||
it('calls core.warning with properties', () => {
|
||||
const log = createLogger()
|
||||
const props = { title: 'Warning Title' }
|
||||
log.warning('test warning', props)
|
||||
expect(core.warning).toHaveBeenCalledWith('test warning', props)
|
||||
})
|
||||
|
||||
it('calls core.error with string message', () => {
|
||||
const log = createLogger()
|
||||
log.error('test error message')
|
||||
expect(core.error).toHaveBeenCalledWith('test error message', undefined)
|
||||
})
|
||||
|
||||
it('calls core.error with Error unchanged', () => {
|
||||
const log = createLogger()
|
||||
const error = new Error('error error')
|
||||
log.error(error)
|
||||
expect(core.error).toHaveBeenCalledWith(error, undefined)
|
||||
})
|
||||
|
||||
it('calls core.error with properties', () => {
|
||||
const log = createLogger()
|
||||
const props = { title: 'Error Title' }
|
||||
log.error('test error', props)
|
||||
expect(core.error).toHaveBeenCalledWith('test error', props)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with prefix', () => {
|
||||
it('prefixes debug messages', () => {
|
||||
const log = createLogger('[dry-run] ')
|
||||
log.debug('test debug message')
|
||||
expect(core.debug).toHaveBeenCalledWith('[dry-run] test debug message')
|
||||
})
|
||||
|
||||
it('prefixes info messages', () => {
|
||||
const log = createLogger('[dry-run] ')
|
||||
log.info('test info message')
|
||||
expect(core.info).toHaveBeenCalledWith('[dry-run] test info message')
|
||||
})
|
||||
|
||||
it('prefixes notice string messages', () => {
|
||||
const log = createLogger('[dry-run] ')
|
||||
log.notice('test notice message')
|
||||
expect(core.notice).toHaveBeenCalledWith(
|
||||
'[dry-run] test notice message',
|
||||
undefined
|
||||
)
|
||||
})
|
||||
|
||||
it('wraps notice Error with prefixed message and cause', () => {
|
||||
const log = createLogger('[dry-run] ')
|
||||
const original = new Error('notice error')
|
||||
log.notice(original)
|
||||
|
||||
expect(core.notice).toHaveBeenCalledTimes(1)
|
||||
const [wrapped, props] = core.notice.mock.calls[0]
|
||||
expect(wrapped).toBeInstanceOf(Error)
|
||||
expect((wrapped as Error).message).toBe('[dry-run] notice error')
|
||||
expect((wrapped as Error).cause).toBe(original)
|
||||
expect((wrapped as Error).stack).toBe(original.stack)
|
||||
expect(props).toBeUndefined()
|
||||
})
|
||||
|
||||
it('prefixes warning string messages', () => {
|
||||
const log = createLogger('[dry-run] ')
|
||||
log.warning('test warning message')
|
||||
expect(core.warning).toHaveBeenCalledWith(
|
||||
'[dry-run] test warning message',
|
||||
undefined
|
||||
)
|
||||
})
|
||||
|
||||
it('wraps warning Error with prefixed message and cause', () => {
|
||||
const log = createLogger('[dry-run] ')
|
||||
const original = new Error('warning error')
|
||||
log.warning(original)
|
||||
|
||||
expect(core.warning).toHaveBeenCalledTimes(1)
|
||||
const [wrapped, props] = core.warning.mock.calls[0]
|
||||
expect(wrapped).toBeInstanceOf(Error)
|
||||
expect((wrapped as Error).message).toBe('[dry-run] warning error')
|
||||
expect((wrapped as Error).cause).toBe(original)
|
||||
expect((wrapped as Error).stack).toBe(original.stack)
|
||||
expect(props).toBeUndefined()
|
||||
})
|
||||
|
||||
it('prefixes error string messages', () => {
|
||||
const log = createLogger('[dry-run] ')
|
||||
log.error('test error message')
|
||||
expect(core.error).toHaveBeenCalledWith(
|
||||
'[dry-run] test error message',
|
||||
undefined
|
||||
)
|
||||
})
|
||||
|
||||
it('wraps error Error with prefixed message and cause', () => {
|
||||
const log = createLogger('[dry-run] ')
|
||||
const original = new Error('error error')
|
||||
log.error(original)
|
||||
|
||||
expect(core.error).toHaveBeenCalledTimes(1)
|
||||
const [wrapped, props] = core.error.mock.calls[0]
|
||||
expect(wrapped).toBeInstanceOf(Error)
|
||||
expect((wrapped as Error).message).toBe('[dry-run] error error')
|
||||
expect((wrapped as Error).cause).toBe(original)
|
||||
expect((wrapped as Error).stack).toBe(original.stack)
|
||||
expect(props).toBeUndefined()
|
||||
})
|
||||
|
||||
it('preserves properties when prefixing', () => {
|
||||
const log = createLogger('[test] ')
|
||||
const props = { title: 'Test Title', file: 'test.ts', startLine: 10 }
|
||||
log.warning('message with props', props)
|
||||
expect(core.warning).toHaveBeenCalledWith(
|
||||
'[test] message with props',
|
||||
props
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with empty prefix', () => {
|
||||
it('behaves the same as no prefix', () => {
|
||||
const log = createLogger('')
|
||||
log.info('test message')
|
||||
expect(core.info).toHaveBeenCalledWith('test message')
|
||||
})
|
||||
})
|
||||
})
|
||||
1888
tests/main.test.ts
Normal file
1888
tests/main.test.ts
Normal file
File diff suppressed because it is too large
Load Diff
285
tests/tags.test.ts
Normal file
285
tests/tags.test.ts
Normal file
@@ -0,0 +1,285 @@
|
||||
/**
|
||||
* Unit tests for tag operation execution, src/tags.ts
|
||||
*/
|
||||
import { jest } from '@jest/globals'
|
||||
import * as core from './fixtures/core.js'
|
||||
import * as github from './fixtures/github.js'
|
||||
import type { Inputs } from '../src/inputs.js'
|
||||
|
||||
// Mocks should be declared before the module being tested is imported.
|
||||
jest.unstable_mockModule('@actions/core', () => core)
|
||||
jest.unstable_mockModule('@actions/github', () => github)
|
||||
|
||||
// The module being tested should be imported dynamically.
|
||||
const { executeTagOperation, planTagOperations } =
|
||||
await import('../src/tags.js')
|
||||
import type {
|
||||
TagOperation,
|
||||
CreateOperation,
|
||||
UpdateOperation
|
||||
} from '../src/tags.js'
|
||||
|
||||
// Helper to create a minimal Inputs object for testing
|
||||
const createInputs = (overrides: Partial<Inputs> = {}): Inputs => ({
|
||||
tags: [],
|
||||
defaultRef: 'main',
|
||||
whenExists: 'update',
|
||||
annotation: '',
|
||||
dryRun: false,
|
||||
owner: 'test-owner',
|
||||
repo: 'test-repo',
|
||||
token: 'test-token',
|
||||
...overrides
|
||||
})
|
||||
|
||||
describe('planTagOperations', () => {
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks()
|
||||
github.getOctokit.mockReturnValue(github.mockOctokit)
|
||||
})
|
||||
|
||||
const setupCommitResolver = (
|
||||
refToSha: Record<string, string> | string
|
||||
): void => {
|
||||
if (typeof refToSha === 'string') {
|
||||
github.mockOctokit.rest.repos.getCommit.mockResolvedValue({
|
||||
data: { sha: refToSha }
|
||||
})
|
||||
} else {
|
||||
github.mockOctokit.rest.repos.getCommit.mockImplementation(
|
||||
async (args: unknown) => {
|
||||
const { ref } = args as { ref: string }
|
||||
const sha = refToSha[ref]
|
||||
if (sha) return { data: { sha } }
|
||||
throw new Error(`Unknown ref: ${ref}`)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const setupTagDoesNotExist = (): void => {
|
||||
github.mockOctokit.rest.git.getRef.mockRejectedValue({
|
||||
status: 404
|
||||
})
|
||||
}
|
||||
|
||||
describe('per-tag annotations', () => {
|
||||
it('parses per-tag annotation with explicit ref', async () => {
|
||||
const inputs = createInputs({
|
||||
tags: ['v1:main:Custom annotation'],
|
||||
annotation: 'Global annotation'
|
||||
})
|
||||
setupCommitResolver('sha-main')
|
||||
setupTagDoesNotExist()
|
||||
|
||||
const operations = await planTagOperations(
|
||||
inputs,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
github.mockOctokit as any
|
||||
)
|
||||
|
||||
expect(operations).toHaveLength(1)
|
||||
expect(operations[0].operation).toBe('create')
|
||||
expect((operations[0] as CreateOperation).annotation).toBe(
|
||||
'Custom annotation'
|
||||
)
|
||||
})
|
||||
|
||||
it('parses per-tag annotation with empty ref (fallback to default)', async () => {
|
||||
const inputs = createInputs({
|
||||
tags: ['v1::Custom annotation'],
|
||||
defaultRef: 'develop',
|
||||
annotation: 'Global annotation'
|
||||
})
|
||||
setupCommitResolver('sha-develop')
|
||||
setupTagDoesNotExist()
|
||||
|
||||
const operations = await planTagOperations(
|
||||
inputs,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
github.mockOctokit as any
|
||||
)
|
||||
|
||||
expect(operations).toHaveLength(1)
|
||||
expect(operations[0].operation).toBe('create')
|
||||
expect(operations[0].ref).toBe('develop')
|
||||
expect((operations[0] as CreateOperation).annotation).toBe(
|
||||
'Custom annotation'
|
||||
)
|
||||
})
|
||||
|
||||
it('handles annotation containing colons', async () => {
|
||||
const inputs = createInputs({
|
||||
tags: ['v1:main:Release: v1.0.0'],
|
||||
annotation: ''
|
||||
})
|
||||
setupCommitResolver('sha-main')
|
||||
setupTagDoesNotExist()
|
||||
|
||||
const operations = await planTagOperations(
|
||||
inputs,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
github.mockOctokit as any
|
||||
)
|
||||
|
||||
expect(operations).toHaveLength(1)
|
||||
expect((operations[0] as CreateOperation).annotation).toBe(
|
||||
'Release: v1.0.0'
|
||||
)
|
||||
})
|
||||
|
||||
it('falls back to global annotation when per-tag not specified', async () => {
|
||||
const inputs = createInputs({
|
||||
tags: ['v1', 'v2:main'],
|
||||
annotation: 'Global annotation'
|
||||
})
|
||||
setupCommitResolver('sha-main')
|
||||
setupTagDoesNotExist()
|
||||
|
||||
const operations = await planTagOperations(
|
||||
inputs,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
github.mockOctokit as any
|
||||
)
|
||||
|
||||
expect(operations).toHaveLength(2)
|
||||
expect((operations[0] as CreateOperation).annotation).toBe(
|
||||
'Global annotation'
|
||||
)
|
||||
expect((operations[1] as CreateOperation).annotation).toBe(
|
||||
'Global annotation'
|
||||
)
|
||||
})
|
||||
|
||||
it('mixes per-tag and global annotations', async () => {
|
||||
const inputs = createInputs({
|
||||
tags: ['v1:main:Per-tag message', 'v2'],
|
||||
annotation: 'Global annotation'
|
||||
})
|
||||
setupCommitResolver('sha-main')
|
||||
setupTagDoesNotExist()
|
||||
|
||||
const operations = await planTagOperations(
|
||||
inputs,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
github.mockOctokit as any
|
||||
)
|
||||
|
||||
expect(operations).toHaveLength(2)
|
||||
expect((operations[0] as CreateOperation).annotation).toBe(
|
||||
'Per-tag message'
|
||||
)
|
||||
expect((operations[1] as CreateOperation).annotation).toBe(
|
||||
'Global annotation'
|
||||
)
|
||||
})
|
||||
|
||||
it('uses per-tag annotation for update comparison', async () => {
|
||||
const inputs = createInputs({
|
||||
tags: ['v1:main:New annotation'],
|
||||
annotation: 'Global annotation',
|
||||
whenExists: 'update'
|
||||
})
|
||||
setupCommitResolver('sha-main')
|
||||
|
||||
// Tag exists with same commit but different annotation
|
||||
github.mockOctokit.rest.git.getRef.mockResolvedValue({
|
||||
data: {
|
||||
ref: 'refs/tags/v1',
|
||||
object: { sha: 'sha-tag-object', type: 'tag' }
|
||||
}
|
||||
})
|
||||
github.mockOctokit.rest.git.getTag.mockResolvedValue({
|
||||
data: {
|
||||
sha: 'sha-tag-object',
|
||||
message: 'Old annotation',
|
||||
object: { sha: 'sha-main', type: 'commit' }
|
||||
}
|
||||
})
|
||||
|
||||
const operations = await planTagOperations(
|
||||
inputs,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
github.mockOctokit as any
|
||||
)
|
||||
|
||||
expect(operations).toHaveLength(1)
|
||||
expect(operations[0].operation).toBe('update')
|
||||
expect((operations[0] as UpdateOperation).annotation).toBe(
|
||||
'New annotation'
|
||||
)
|
||||
expect((operations[0] as UpdateOperation).reasons).toContain(
|
||||
'annotation message changed'
|
||||
)
|
||||
})
|
||||
|
||||
it('skips tag when per-tag annotation matches existing', async () => {
|
||||
const inputs = createInputs({
|
||||
tags: ['v1:main:Same annotation'],
|
||||
annotation: 'Global annotation',
|
||||
whenExists: 'update'
|
||||
})
|
||||
setupCommitResolver('sha-main')
|
||||
|
||||
github.mockOctokit.rest.git.getRef.mockResolvedValue({
|
||||
data: {
|
||||
ref: 'refs/tags/v1',
|
||||
object: { sha: 'sha-tag-object', type: 'tag' }
|
||||
}
|
||||
})
|
||||
github.mockOctokit.rest.git.getTag.mockResolvedValue({
|
||||
data: {
|
||||
sha: 'sha-tag-object',
|
||||
message: 'Same annotation',
|
||||
object: { sha: 'sha-main', type: 'commit' }
|
||||
}
|
||||
})
|
||||
|
||||
const operations = await planTagOperations(
|
||||
inputs,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
github.mockOctokit as any
|
||||
)
|
||||
|
||||
expect(operations).toHaveLength(1)
|
||||
expect(operations[0].operation).toBe('skip')
|
||||
})
|
||||
|
||||
it('rejects empty tag name with annotation', async () => {
|
||||
const inputs = createInputs({
|
||||
tags: ['::Some annotation']
|
||||
})
|
||||
|
||||
await expect(
|
||||
planTagOperations(
|
||||
inputs,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
github.mockOctokit as any
|
||||
)
|
||||
).rejects.toThrow("Invalid tag: '::Some annotation'")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('executeTagOperation', () => {
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks()
|
||||
github.getOctokit.mockReturnValue(github.mockOctokit)
|
||||
})
|
||||
|
||||
it('throws error for unknown operation type', async () => {
|
||||
const invalidOperation = {
|
||||
operation: 'invalid',
|
||||
name: 'v1',
|
||||
ref: 'main',
|
||||
sha: 'abc123',
|
||||
owner: 'test-owner',
|
||||
repo: 'test-repo'
|
||||
} as unknown as TagOperation
|
||||
|
||||
await expect(
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
executeTagOperation(invalidOperation, github.mockOctokit as any)
|
||||
).rejects.toThrow('Unknown operation type: invalid')
|
||||
})
|
||||
})
|
||||
@@ -7,8 +7,7 @@
|
||||
},
|
||||
"exclude": ["dist", "node_modules"],
|
||||
"include": [
|
||||
"__fixtures__",
|
||||
"__tests__",
|
||||
"tests",
|
||||
"src",
|
||||
"eslint.config.mjs",
|
||||
"jest.config.js",
|
||||
|
||||
@@ -6,6 +6,6 @@
|
||||
"moduleResolution": "NodeNext",
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"exclude": ["__fixtures__", "__tests__", "coverage", "dist", "node_modules"],
|
||||
"exclude": ["tests", "coverage", "dist", "node_modules"],
|
||||
"include": ["src"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user