-
Notifications
You must be signed in to change notification settings - Fork 34
76 lines (69 loc) · 2.82 KB
/
Copy pathgithub-release.yml
File metadata and controls
76 lines (69 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
name: GitHub Release
# Creates (or updates) the GitHub Release for a vX.Y.Z tag, with the release
# notes generated by GitHub from the PRs merged since the previous tag.
# `.github/release.yml` controls how those notes are grouped.
#
# Three entry points, one implementation:
#
# workflow_call -- how the automated flow gets here. release.yml pushes the
# tag with GITHUB_TOKEN, and a tag pushed by GITHUB_TOKEN
# does NOT trigger another workflow, so release.yml calls
# this one directly instead of relying on the tag push.
# push (tags) -- for a tag pushed by hand
# (`git tag v0.3.35 && git push origin v0.3.35`).
# workflow_dispatch -- to back-fill the Release for a tag that already exists.
#
# Only one of these fires per tag in practice; if two ever did,
# action-gh-release updates the existing Release rather than failing.
on:
push:
tags:
- 'v*'
workflow_call:
inputs:
tag:
description: 'Tag to release, including the leading v'
required: true
type: string
workflow_dispatch:
inputs:
tag:
description: 'Tag to release, including the leading v (e.g. v0.3.35)'
required: true
type: string
permissions:
contents: write
jobs:
github-release:
name: Publish GitHub Release
runs-on: ubuntu-latest
steps:
# `inputs` is empty on a push event, so this falls back to the pushed tag.
- name: Resolve the tag being released
id: tag
run: echo "tag=${{ inputs.tag || github.ref_name }}" >> "$GITHUB_OUTPUT"
# fetch-depth: 0 so the full tag list is available to the next step.
- uses: actions/checkout@v4
with:
ref: ${{ steps.tag.outputs.tag }}
fetch-depth: 0
# Pin the comparison base explicitly. Left to itself, GitHub starts from
# the previous *Release* -- and this repo has 30-odd tags but no Releases
# yet, so the first generated notes would otherwise span the entire
# history. Picking the preceding vX.Y.Z tag keeps every set of notes to
# one version's worth of changes. Empty for the very first tag, which is
# the one case where letting GitHub decide is correct.
- name: Find the preceding tag
id: prev
run: |
prev=$(git tag --list 'v*' --sort=-v:refname \
| awk -v t="${{ steps.tag.outputs.tag }}" 'found { print; exit } $0 == t { found = 1 }')
echo "Previous tag: ${prev:-<none>}"
echo "tag=$prev" >> "$GITHUB_OUTPUT"
- name: Create or update the GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.tag.outputs.tag }}
name: ${{ steps.tag.outputs.tag }}
previous_tag: ${{ steps.prev.outputs.tag }}
generate_release_notes: true