|
| 1 | +name: Auto-publish tags |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' # Push events to release tags |
| 7 | + |
| 8 | +jobs: |
| 9 | + build: |
| 10 | + name: Publish GitHub Release from tag |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v2 |
| 14 | + with: |
| 15 | + fetch-depth: 0 |
| 16 | + - name: Import public GPG keys to verify the tag |
| 17 | + uses: actions/github-script@v3 |
| 18 | + with: |
| 19 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 20 | + script: | |
| 21 | + const { execSync } = require('child_process') |
| 22 | +
|
| 23 | + for (const { key_id, raw_key } of (await github.users.listGpgKeysForUser({ |
| 24 | + username: 'dscho' |
| 25 | + })).data) { |
| 26 | + execSync(`gpg ${raw_key ? '--import' : `--recv-keys ${key_id}`}`, |
| 27 | + { input: raw_key, stdio: [null, 'inherit', 'inherit'] }) |
| 28 | + } |
| 29 | + - name: Check prerequisites |
| 30 | + id: prerequisites |
| 31 | + run: | |
| 32 | + die () { |
| 33 | + echo "::error::$*" >&2 |
| 34 | + exit 1 |
| 35 | + } |
| 36 | +
|
| 37 | + tag_name=${GITHUB_REF#refs/tags/} |
| 38 | + test "x$GITHUB_REF" != "x$tag_name" || die "Not a tag: $GITHUB_REF" |
| 39 | +
|
| 40 | + train="$(echo "$tag_name" | sed -n 's|^\(v[0-9][0-9]*\)[.0-9]*$|\1|p')" |
| 41 | + test -n "$train" || die "Unexpected tag name: $tag_name" |
| 42 | + echo "$train" >train |
| 43 | +
|
| 44 | + if train_rev="$(git rev-parse --verify "refs/remotes/origin/$train")" |
| 45 | + then |
| 46 | + test 0 -eq "$(git rev-list --count "$GITHUB_REF..$train_rev")" || |
| 47 | + die "Branch '$train' does not fast-forward to tag '$tag_name'" |
| 48 | + else |
| 49 | + test "$train.0.0" = "$tag_name" || die "Branch '$train' does not yet exist?!?" |
| 50 | + fi |
| 51 | +
|
| 52 | + git tag --verify "$tag_name" || die "Tag does not have a valid signature: $tag_name" |
| 53 | +
|
| 54 | + test "$(git rev-parse --verify refs/remotes/origin/main 2>&1)" = \ |
| 55 | + "$(git rev-parse --verify "$GITHUB_REF^0")" || |
| 56 | + die "The tag '$tag_name' does not point to the tip of 'main'" |
| 57 | +
|
| 58 | + echo "$tag_name" >tag_name |
| 59 | + git cat-file tag "$GITHUB_REF" | sed -e '1,/^$/d' -e '/-----BEGIN PGP SIGNATURE-----/,$d' >body |
| 60 | + - name: Create Release |
| 61 | + if: github.repository_owner == 'git-for-windows' |
| 62 | + uses: actions/github-script@v3 |
| 63 | + with: |
| 64 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 65 | + script: | |
| 66 | + const { readFileSync } = require('fs') |
| 67 | +
|
| 68 | + await github.repos.createRelease({ |
| 69 | + owner: context.repo.owner, |
| 70 | + repo: context.repo.repo, |
| 71 | + tag_name: readFileSync('tag_name').toString(), |
| 72 | + draft: true, |
| 73 | + prerelease: false, |
| 74 | + body: readFileSync('body').toString() |
| 75 | + }) |
| 76 | + - name: Push to release train branch |
| 77 | + if: github.repository_owner == 'git-for-windows' |
| 78 | + run: git push origin "$GITHUB_REF^0:refs/heads/$(cat train)" |
0 commit comments