Repository navigation
120 lines (111 loc) · 4.52 KB
/
Copy pathgithub-release.yml
File metadata and controls
120 lines (111 loc) · 4.52 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Hand-maintained (like benchmarks.yml and update-readme-version.yml) — NOT
# generated by sbt githubWorkflowGenerate; do not add it to the sbt-typelevel
# config.
#
# Follow-up to a successful release: when the tag build of "Continuous
# Integration" (which publishes to Maven Central) completes green, create the
# GitHub Release for that tag. The body is the tag's `## [x.y.z]` section from
# CHANGELOG.md — the curated headline — with GitHub's auto-generated notes
# (PR list + contributors) appended. A missing changelog section FAILS the
# run on purpose: cutting the section is part of releasing. If the release
# already exists (e.g. created by hand before CI finished), the run
# short-circuits green BEFORE the changelog gate — its job is already done.
# `workflow_dispatch` backfills a release for any existing tag.
name: GitHub Release
on:
workflow_run:
workflows: ["Continuous Integration"]
types: [completed]
workflow_dispatch:
inputs:
tag:
description: "Existing v* tag to (re)create the release for"
required: true
type: string
permissions:
contents: write
concurrency:
group: github-release
cancel-in-progress: false
jobs:
create-release:
runs-on: ubuntu-22.04
# workflow_run fires for every CI completion; act only on a SUCCESSFUL
# tag build (head_branch is the tag name for tag-triggered runs).
if: >-
github.event_name == 'workflow_dispatch' ||
(github.event.workflow_run.conclusion == 'success' &&
startsWith(github.event.workflow_run.head_branch, 'v'))
steps:
- name: Resolve tag
id: tag
env:
EVENT_NAME: ${{ github.event_name }}
INPUT_TAG: ${{ inputs.tag }}
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
run: |
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
TAG="$INPUT_TAG"
else
TAG="$HEAD_BRANCH"
fi
# Final releases only — no GitHub Release for RCs/milestones.
if ! echo "$TAG" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "Not a final release tag: $TAG — skipping."
echo "tag=" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
# The release may already exist (manual creation, previous backfill).
# Detect it BEFORE the changelog gate: the workflow's job is done, so
# exit green instead of failing on a section the frozen tag can't grow.
- name: Check for an existing release
id: existing
if: steps.tag.outputs.tag != ''
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ steps.tag.outputs.tag }}
run: |
if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" > /dev/null 2>&1; then
echo "Release $TAG already exists — leaving it untouched."
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- uses: actions/checkout@v7
if: steps.tag.outputs.tag != '' && steps.existing.outputs.exists != 'true'
with:
ref: ${{ steps.tag.outputs.tag }}
- name: Extract the tag's CHANGELOG section
if: steps.tag.outputs.tag != '' && steps.existing.outputs.exists != 'true'
env:
TAG: ${{ steps.tag.outputs.tag }}
run: |
VERSION="${TAG#v}"
awk -v ver="$VERSION" '
$0 ~ "^## \\[" ver "\\]" { hit = 1; next }
hit && /^## \[/ { exit }
hit { print }
' CHANGELOG.md > release-body.md
if ! grep -q '[^[:space:]]' release-body.md; then
echo "::error::CHANGELOG.md has no '## [$VERSION]' section — cut one before releasing."
exit 1
fi
echo "--- release body ---"; cat release-body.md
- name: Create the release
if: steps.tag.outputs.tag != '' && steps.existing.outputs.exists != 'true'
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ steps.tag.outputs.tag }}
run: |
# Race guard: the release may have appeared since the check above.
if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" > /dev/null 2>&1; then
echo "Release $TAG already exists — leaving it untouched."
exit 0
fi
gh release create "$TAG" \
--repo "$GITHUB_REPOSITORY" \
--title "$TAG" \
--verify-tag \
--notes-file release-body.md \
--generate-notes