-
Notifications
You must be signed in to change notification settings - Fork 0
112 lines (100 loc) · 4.13 KB
/
Copy pathrelease.yml
File metadata and controls
112 lines (100 loc) · 4.13 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
name: Create release
# Cutting a release means creating a tag and a GitHub Release. Doing that from a
# local clone requires pushing to `refs/tags/*`, which not every environment is
# permitted to do, so the tag is created here instead — the runner's
# GITHUB_TOKEN has `contents: write` and `gh release create` creates the tag as
# part of publishing.
#
# Release notes are read from a committed file rather than a dispatch input, so
# they are reviewed in a pull request before they are ever published, and the
# repo keeps a history of what each release claimed.
on:
workflow_dispatch:
inputs:
tag:
description: "Tag to create, e.g. v1.1 (must not already exist)"
required: true
type: string
draft:
description: "Create as a draft so it can be read before going public"
type: boolean
default: true
prerelease:
description: "Mark as a pre-release"
type: boolean
default: false
permissions:
contents: write
concurrency:
group: create-release
cancel-in-progress: false
jobs:
release:
runs-on: ubuntu-latest
# This repo is a template. Without this guard, every site generated from it
# would expose a workflow that cuts releases of somebody else's project.
if: github.repository == 'alshedivat/al-folio'
steps:
- name: Checkout 🛎️
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Validate inputs 🔍
id: check
env:
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
set -euo pipefail
tag="${{ inputs.tag }}"
# The dispatch UI lets you pick any branch, and GITHUB_SHA then points at
# that branch's tip — which is what gets tagged below. Without this check a
# permanent version tag could be cut from unmerged code, with release notes
# that were never reviewed. The repository guard above does not constrain
# the ref, only the repo.
if [ "${GITHUB_REF_NAME}" != "${DEFAULT_BRANCH}" ]; then
echo "::error::Releases must be cut from ${DEFAULT_BRANCH}, but this run was dispatched from '${GITHUB_REF_NAME}'."
echo "Merge the release notes first, then dispatch again from ${DEFAULT_BRANCH}."
exit 1
fi
if ! printf '%s' "$tag" | grep -Eq '^v[0-9]+\.[0-9]+(\.[0-9]+)?$'; then
echo "::error::'$tag' is not a version tag (expected v1.1 or v1.1.0)."
exit 1
fi
# Publishing is effectively irreversible once people have fetched the
# tag, so refuse rather than move an existing one.
if git rev-parse -q --verify "refs/tags/$tag" >/dev/null; then
echo "::error::Tag $tag already exists. Bump the version instead of retagging."
exit 1
fi
notes="docs/releases/${tag}.md"
if [ ! -s "$notes" ]; then
echo "::error::No release notes at $notes (missing or empty)."
echo "Add them in a pull request first — this workflow deliberately will not invent them."
exit 1
fi
echo "notes=$notes" >> "$GITHUB_OUTPUT"
echo "Will release $tag from ${GITHUB_SHA} using $notes"
- name: Create release 🚀
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
gh release create "${{ inputs.tag }}" \
--target "${GITHUB_SHA}" \
--title "al-folio ${{ inputs.tag }}" \
--notes-file "${{ steps.check.outputs.notes }}" \
--draft=${{ inputs.draft }} \
--prerelease=${{ inputs.prerelease }}
- name: Summary 📝
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
{
echo "### al-folio ${{ inputs.tag }}"
echo
echo "- commit: \`${GITHUB_SHA}\`"
echo "- draft: ${{ inputs.draft }}"
echo "- prerelease: ${{ inputs.prerelease }}"
echo
gh release view "${{ inputs.tag }}" --json url --jq '"[View release](" + .url + ")"'
} >> "$GITHUB_STEP_SUMMARY"