|
| 1 | +# This internal workflow creates a semver signed git tag. |
| 2 | +name: .release |
| 3 | + |
| 4 | +# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions |
| 5 | +permissions: |
| 6 | + contents: read |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 10 | + cancel-in-progress: true |
| 11 | + |
| 12 | +on: |
| 13 | + workflow_dispatch: |
| 14 | + inputs: |
| 15 | + version: |
| 16 | + description: "Semver version (e.g. v1.2.3)" |
| 17 | + required: true |
| 18 | + type: string |
| 19 | + ref: |
| 20 | + description: "Optional Git ref to tag (defaults to main HEAD)" |
| 21 | + required: false |
| 22 | + type: string |
| 23 | + default: refs/heads/main |
| 24 | + |
| 25 | +env: |
| 26 | + GITSIGN_VERSION: v0.14.0 |
| 27 | + |
| 28 | +jobs: |
| 29 | + release: |
| 30 | + runs-on: ubuntu-latest |
| 31 | + environment: release-prod |
| 32 | + permissions: |
| 33 | + contents: write # required to push the tag |
| 34 | + id-token: write # required for keyless gitsign |
| 35 | + steps: |
| 36 | + - |
| 37 | + name: Install npm deps |
| 38 | + uses: actions/github-script@v8 |
| 39 | + with: |
| 40 | + script: | |
| 41 | + await core.group(`Install npm deps`, async () => { |
| 42 | + await exec.exec('npm', ['install', 'semver']); |
| 43 | + }); |
| 44 | + - |
| 45 | + name: Check version |
| 46 | + uses: actions/github-script@v8 |
| 47 | + env: |
| 48 | + INPUT_VERSION: ${{ inputs.version }} |
| 49 | + with: |
| 50 | + script: | |
| 51 | + const semver = require('semver'); |
| 52 | + const version = core.getInput('version'); |
| 53 | + if (!semver.valid(version)) { |
| 54 | + core.setFailed(`Invalid version: ${version}`); |
| 55 | + } |
| 56 | + - |
| 57 | + name: GitHub auth token from GitHub App |
| 58 | + id: write-app |
| 59 | + uses: actions/create-github-app-token@v2 |
| 60 | + with: |
| 61 | + app-id: ${{ secrets.GITHUB_BUILDER_REPO_WRITE_APP_ID }} |
| 62 | + private-key: ${{ secrets.GITHUB_BUILDER_REPO_WRITE_APP_PRIVATE_KEY }} |
| 63 | + owner: docker |
| 64 | + repositories: github-builder |
| 65 | + - |
| 66 | + name: Checkout |
| 67 | + uses: actions/checkout@v6 |
| 68 | + with: |
| 69 | + ref: ${{ inputs.ref }} |
| 70 | + fetch-depth: 0 |
| 71 | + token: ${{ steps.write-app.outputs.token }} |
| 72 | + - |
| 73 | + name: Ensure tag does not exist |
| 74 | + uses: actions/github-script@v8 |
| 75 | + env: |
| 76 | + INPUT_VERSION: ${{ inputs.version }} |
| 77 | + with: |
| 78 | + script: | |
| 79 | + const version = core.getInput('version'); |
| 80 | + await exec.exec('git', ['rev-parse', '-q', '--verify', `refs/tags/${version}`], { |
| 81 | + ignoreReturnCode: true |
| 82 | + }).then(res => { |
| 83 | + if (res.exitCode != 0) { |
| 84 | + core.setFailed(`Tag ${version} already exists`); |
| 85 | + } |
| 86 | + }); |
| 87 | + - |
| 88 | + name: Install Gitsign |
| 89 | + run: | |
| 90 | + set -x |
| 91 | + go install github.com/sigstore/gitsign@${GITSIGN_VERSION} |
| 92 | + gitsign --version |
| 93 | + - |
| 94 | + name: Configure Git for Gitsign |
| 95 | + run: | |
| 96 | + set -x |
| 97 | + git config user.name "${GITHUB_ACTOR}" |
| 98 | + git config user.email "${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com" |
| 99 | + git config gpg.format x509 |
| 100 | + git config gpg.x509.program gitsign |
| 101 | + git config tag.gpgsign true |
| 102 | + git config gitsign.connectorID https://github.com/login/oauth |
| 103 | + git config gitsign.tokenProvider github-actions |
| 104 | + - |
| 105 | + name: Create signed tag |
| 106 | + uses: actions/github-script@v8 |
| 107 | + env: |
| 108 | + INPUT_VERSION: ${{ inputs.version }} |
| 109 | + with: |
| 110 | + script: | |
| 111 | + const version = core.getInput('version'); |
| 112 | + await exec.exec('git', ['tag', '-a', version, '-m', version]); |
| 113 | + await exec.exec('git', ['tag', '-v', version]); |
| 114 | + - |
| 115 | + name: Push tag |
| 116 | + uses: actions/github-script@v8 |
| 117 | + env: |
| 118 | + INPUT_VERSION: ${{ inputs.version }} |
| 119 | + with: |
| 120 | + script: | |
| 121 | + const version = core.getInput('version'); |
| 122 | + await exec.exec('git', ['push', 'origin', `refs/tags/${version}`]); |
0 commit comments