-
Notifications
You must be signed in to change notification settings - Fork 0
124 lines (113 loc) · 4.25 KB
/
Copy pathrelease.yml
File metadata and controls
124 lines (113 loc) · 4.25 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
121
122
123
124
name: release
# Publishes to Clojars when a v* tag is pushed. The tag is the deliberate
# "this is worth a release" signal; nothing publishes on ordinary commits.
on:
push:
tags: ['v*']
workflow_dispatch: {} # manual run for testing; publishing is tag-only
permissions:
contents: write # create the GitHub Release
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21'
- uses: DeLaGuardo/setup-clojure@13.6.1
with:
cli: latest
- uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-m2-${{ hashFiles('deps.edn') }}
restore-keys: ${{ runner.os }}-m2-
- name: Verify tag matches build.clj version
if: github.ref_type == 'tag'
run: |
TAG="${GITHUB_REF_NAME#v}"
PROJ=$(sed -n 's/.*def version "\([^"]*\)".*/\1/p' build.clj)
echo "tag=$TAG build.clj=$PROJ"
if [ "$TAG" != "$PROJ" ]; then
echo "::error::tag v$TAG does not match build.clj version $PROJ"
exit 1
fi
- name: Verify tag matches project.clj version
if: github.ref_type == 'tag'
run: |
TAG="${GITHUB_REF_NAME#v}"
PROJ=$(sed -n 's/.*defproject [^ ]* "\([^"]*\)".*/\1/p' project.clj)
if [ -z "$PROJ" ]; then
PROJ=$(sed -n 's/.*(def version "\([^"]*\)").*/\1/p' project.clj)
fi
echo "tag=$TAG project.clj=$PROJ"
if [ -z "$PROJ" ] || [ "$TAG" != "$PROJ" ]; then
echo "::error::tag v$TAG does not match project.clj version $PROJ"
exit 1
fi
- name: Verify README install coordinate matches version
if: github.ref_type == 'tag'
run: |
TAG="${GITHUB_REF_NAME#v}"
LIB=$(grep -oE "net\.clojars\.[^ ')]+" build.clj | head -1)
if ! grep -qF "$LIB {:mvn/version \"$TAG\"}" README.md; then
echo "::error::README.md is missing install coordinate: $LIB {:mvn/version \"$TAG\"}"
exit 1
fi
- name: Verify doc/*.md install coordinates match version
if: github.ref_type == 'tag'
run: |
TAG="${GITHUB_REF_NAME#v}"
LIB=$(grep -oE "net\.clojars\.[^ ')]+" build.clj | head -1)
rc=0
shopt -s nullglob
for f in doc/*.md; do
while IFS= read -r ver; do
if [ "$ver" != "$TAG" ]; then
echo "::error file=$f::$f pins $LIB {:mvn/version \"$ver\"}, expected \"$TAG\""
rc=1
fi
done < <(grep -oE "net\.clojars\.[a-zA-Z0-9._/-]+ \{:mvn/version \"[^\"]+\"\}" "$f" | grep -F "$LIB {:mvn/version" | grep -oE '"[^"]+"' | tr -d '"')
done
exit $rc
- name: Verify tag commit is on main
if: github.ref_type == 'tag'
run: |
git fetch --no-tags origin main
if ! git merge-base --is-ancestor "$GITHUB_SHA" origin/main; then
echo "::error::tag $GITHUB_REF_NAME is not an ancestor of origin/main"
exit 1
fi
- name: Test
run: clojure -M:test
- name: Extract release notes from CHANGELOG
if: github.ref_type == 'tag'
run: |
VERSION="${GITHUB_REF_NAME#v}"
PATTERN=$(printf '%s' "$VERSION" | sed 's/\./\\./g')
awk -v p="$PATTERN" '
$0 ~ "^## \\[" p "\\]" {found=1; next}
found && /^## / {exit}
found {print}
' CHANGELOG.md > release-notes.md
if [ ! -s release-notes.md ]; then
echo "::error::CHANGELOG.md has no section for $VERSION"
exit 1
fi
cat release-notes.md
- name: Deploy to Clojars
if: github.ref_type == 'tag'
env:
CLOJARS_USERNAME: ${{ secrets.CLOJARS_USERNAME }}
CLOJARS_PASSWORD: ${{ secrets.CLOJARS_PASSWORD }}
run: clojure -T:build deploy
- name: Create GitHub Release
if: github.ref_type == 'tag'
uses: softprops/action-gh-release@v2
with:
body_path: release-notes.md
generate_release_notes: true