Skip to content

Commit

Permalink
fix(action): add delay when deleting tags (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher authored Jun 11, 2024
1 parent 320d809 commit 9c6ebff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ steps:
| keepPreReleaseCount | The number of pre-releases to keep. | `2` | `false` |
| name | The version to create. | | `true` |
| prerelease | Whether the release is a prerelease. | `true` | `false` |
| sleepDuration | The duration to sleep in seconds before deleting tags. | `15` | `false` |
| tag | The tag to create. | | `true` |
| token | GitHub Token. | | `true` |

Expand Down
14 changes: 13 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ inputs:
description: 'Whether the release is a prerelease.'
required: false
default: 'true'
sleepDuration:
description: 'The duration to sleep in seconds before deleting tags.'
required: false
default: '15'
tag:
description: 'The tag to create.'
required: true
Expand Down Expand Up @@ -90,12 +94,14 @@ runs:
env:
DELETE_TAGS: ${{ inputs.deletePreReleaseTags }}
KEEP_LATEST: ${{ inputs.keepPreReleaseCount }}
SLEEP_DURATION: ${{ inputs.sleepDuration }}
with:
github-token: ${{ inputs.token }}
script: |
// process input
const DELETE_TAGS = process.env.DELETE_TAGS.toLowerCase() === 'true';
const KEEP_LATEST = parseInt(process.env.KEEP_LATEST, 10);
const SLEEP_DURATION = parseInt(process.env.SLEEP_DURATION, 10);
console.log(`DELETE_TAGS: ${DELETE_TAGS}`);
console.log(`KEEP_LATEST: ${KEEP_LATEST}`);
Expand Down Expand Up @@ -145,8 +151,14 @@ runs:
console.error(`Failed to delete release: ${release.tag_name}`);
console.error(error);
}
}
// sleep to allow any on release deleted event workflow runs to be created
// if the tag is deleted before the workflow run is created, the run will fail to be created
await new Promise(resolve => setTimeout(resolve, SLEEP_DURATION * 1000));
if (DELETE_TAGS) {
if (DELETE_TAGS) {
for (let i = 0; i < preReleases.length - KEEP_LATEST; i++) {
console.log(`Deleting tag: ${release.tag_name}`);
try {
await github.rest.git.deleteRef({
Expand Down

0 comments on commit 9c6ebff

Please sign in to comment.