|
10 | 10 | name: Tests for "release/plan" action |
11 | 11 | runs-on: ubuntu-latest |
12 | 12 | permissions: |
13 | | - contents: read |
| 13 | + contents: write |
14 | 14 | pull-requests: read |
15 | 15 | steps: |
16 | 16 | - name: Arrange - Checkout |
|
37 | 37 | assert.ok(process.env.RELEASE_TAG.startsWith('get-configuration-'), `Expected tag to start with "get-configuration-", got "${process.env.RELEASE_TAG}"`); |
38 | 38 | assert.ok(process.env.RELEASE_NAME, 'Expected planned name to be set'); |
39 | 39 | assert.ok(process.env.RELEASE_NAME.startsWith('Version get-configuration - '), `Expected name to start with "Version get-configuration - ", got "${process.env.RELEASE_NAME}"`); |
| 40 | +
|
| 41 | + - name: Arrange - Create colliding tag |
| 42 | + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 |
| 43 | + env: |
| 44 | + RELEASE_TAG: ${{ steps.drafter-plan.outputs.tag }} |
| 45 | + TARGET_SHA: ${{ github.sha }} |
| 46 | + with: |
| 47 | + github-token: ${{ github.token }} |
| 48 | + script: | |
| 49 | + const releaseTag = (process.env.RELEASE_TAG || '').trim(); |
| 50 | + const targetSha = (process.env.TARGET_SHA || '').trim(); |
| 51 | +
|
| 52 | + if (!releaseTag) { |
| 53 | + throw new Error('Expected planned release tag before creating a colliding tag'); |
| 54 | + } |
| 55 | +
|
| 56 | + if (!targetSha) { |
| 57 | + throw new Error('Expected target sha before creating a colliding tag'); |
| 58 | + } |
| 59 | +
|
| 60 | + await github.rest.git.createRef({ |
| 61 | + owner: context.repo.owner, |
| 62 | + repo: context.repo.repo, |
| 63 | + ref: `refs/tags/${releaseTag}`, |
| 64 | + sha: targetSha, |
| 65 | + }); |
| 66 | +
|
| 67 | + - name: Act - Plan drafter release with existing tag |
| 68 | + id: existing-tag-plan |
| 69 | + continue-on-error: true |
| 70 | + uses: ./actions/release/plan |
| 71 | + with: |
| 72 | + working-directory: actions/release/get-configuration |
| 73 | + |
| 74 | + - name: Assert - Existing remote tag blocks release plan |
| 75 | + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 |
| 76 | + env: |
| 77 | + RELEASE_TAG: ${{ steps.drafter-plan.outputs.tag }} |
| 78 | + STEP_OUTCOME: ${{ steps.existing-tag-plan.outcome }} |
| 79 | + with: |
| 80 | + script: | |
| 81 | + const assert = require('node:assert'); |
| 82 | +
|
| 83 | + const releaseTag = (process.env.RELEASE_TAG || '').trim(); |
| 84 | + const stepOutcome = (process.env.STEP_OUTCOME || '').trim(); |
| 85 | +
|
| 86 | + assert.ok(releaseTag, 'Expected colliding tag to be set'); |
| 87 | + assert.equal(stepOutcome, 'failure', `Expected plan action to fail when tag already exists, got "${stepOutcome}"`); |
| 88 | +
|
| 89 | + - name: Cleanup - Delete colliding tag |
| 90 | + if: always() |
| 91 | + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 |
| 92 | + env: |
| 93 | + RELEASE_TAG: ${{ steps.drafter-plan.outputs.tag }} |
| 94 | + with: |
| 95 | + github-token: ${{ github.token }} |
| 96 | + script: | |
| 97 | + const releaseTag = (process.env.RELEASE_TAG || '').trim(); |
| 98 | +
|
| 99 | + if (!releaseTag) { |
| 100 | + return; |
| 101 | + } |
| 102 | +
|
| 103 | + try { |
| 104 | + await github.rest.git.deleteRef({ |
| 105 | + owner: context.repo.owner, |
| 106 | + repo: context.repo.repo, |
| 107 | + ref: `tags/${releaseTag}`, |
| 108 | + }); |
| 109 | + } catch (error) { |
| 110 | + if (error.status === 404) { |
| 111 | + return; |
| 112 | + } |
| 113 | +
|
| 114 | + throw error; |
| 115 | + } |
0 commit comments