Skip to content

Commit 14d0027

Browse files
committed
Create draft release via GitHub CLI or UI
1 parent ad698b6 commit 14d0027

File tree

2 files changed

+79
-28
lines changed

2 files changed

+79
-28
lines changed
Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,49 @@
1-
name: Prepare release
1+
# Create a draft release when triggered via Github's UI or Github CLI
2+
name: Prepare Release
23

34
on:
4-
push:
5-
tags:
6-
- "v[0-9]*.[0-9]*"
5+
workflow_dispatch:
6+
inputs:
7+
version:
8+
description: 'Version to release (e.g. 0.11.0)'
9+
required: true
10+
type: string
11+
12+
permissions:
13+
contents: write
714

815
jobs:
9-
update-release-notes:
10-
name: Update release
16+
release:
17+
name: Prepare Release
1118
runs-on: ubuntu-latest
1219
steps:
20+
- name: Check version
21+
run: |
22+
if ! [[ '${{ inputs.version }}' =~ ^[0-9]+[.][0-9]+([.][0-9]+)?$ ]]; then
23+
echo '${{ inputs.version }} does not match expected format `major.minor.patch?`' >&2
24+
exit 1
25+
fi
1326
- name: Checkout
1427
uses: actions/checkout@v4
15-
- name: Create archive
16-
id: archive
28+
with:
29+
ref: master # only create releases from main branch
30+
- name: Read section from CHANGELOG.md
31+
id: extract-changelog
32+
uses: sean0x42/markdown-extract@v2
33+
with:
34+
file: CHANGELOG.md
35+
pattern: ${{ inputs.version }}
36+
- name: Prepare release notes and artifacts
1737
run: |
18-
TAG="${GITHUB_REF_NAME}"
19-
REPOSITORY_NAME="${GITHUB_REPOSITORY#*/}"
20-
PREFIX="${REPOSITORY_NAME}-${TAG:1}"
21-
ARCHIVE="${PREFIX}.tar.gz"
22-
23-
echo "tgz=${ARCHIVE}" >> $GITHUB_OUTPUT
24-
25-
git archive --format=tar.gz --prefix="${PREFIX}/" -o "$ARCHIVE" "${TAG}"
26-
- name: Prepare bzlmod / WORKSPACE snippets
27-
run: .github/workflows/prepare_snippets.sh ${{ steps.archive.outputs.tgz }} > release_notes.txt
28-
- name: Generate changelog
38+
.github/workflows/release_prep.sh v${{ inputs.version }} > release_notes.txt
39+
printf '${{ steps.extract-changelog.outputs.markdown }}' >> release_notes.txt
40+
- name: Create draft release
41+
env:
42+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2943
run: |
30-
printf '\n-----\n\n' >> release_notes.txt
31-
awk -f .github/workflows/changelog.awk CHANGELOG.md >> release_notes.txt
32-
- name: Release
33-
uses: softprops/action-gh-release@v2
34-
with:
35-
draft: true
36-
body_path: release_notes.txt
37-
fail_on_unmatched_files: true
38-
files: ${{ steps.archive.outputs.tgz }}
44+
gh release create \
45+
--draft \
46+
--notes-file release_notes.txt \
47+
--title v${{ inputs.version }} \
48+
v${{ inputs.version }} \
49+
rules_nixpkgs-${{ inputs.version }}.tar.gz

.github/workflows/release_prep.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
TAG=$1
5+
REPO_NAME=${GITHUB_REPOSITORY#*/}
6+
# The prefix is chosen to match what GitHub generates for source archives
7+
PREFIX="${REPO_NAME}-${TAG:1}"
8+
ARCHIVE="${REPO_NAME}-${TAG:1}.tar.gz"
9+
git archive --format=tar.gz --prefix="${PREFIX}/" -o $ARCHIVE HEAD
10+
SHA=$(shasum -a 256 "$ARCHIVE" | awk '{print $1}')
11+
12+
cat << EOF
13+
## Using Bzlmod with Bazel 6+
14+
15+
1. Enable with \`common --enable_bzlmod\` in \`.bazelrc\`.
16+
2. Add to your \`MODULE.bazel\` file:
17+
18+
\`\`\`starlark
19+
bazel_dep(name = "${REPO_NAME}", version = "${TAG:1}")
20+
\`\`\`
21+
22+
## Using WORKSPACE
23+
24+
Paste this snippet into your \`WORKSPACE.bazel\` file:
25+
26+
\`\`\`starlark
27+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
28+
29+
http_archive(
30+
name = "${REPO_NAME}",
31+
sha256 = "${SHA}",
32+
strip_prefix = "$PREFIX",
33+
urls = ["https://github.com/$GITHUB_REPOSITORY/releases/download/$TAG/$ARCHIVE"],
34+
)
35+
36+
load("@${REPO_NAME}//haskell:repositories.bzl", "${REPO_NAME}_dependencies")
37+
38+
${REPO_NAME}_dependencies()
39+
\`\`\`
40+
EOF

0 commit comments

Comments
 (0)