Repository navigation
144 lines (128 loc) · 5.07 KB
/
Copy pathdeploy.yml
File metadata and controls
144 lines (128 loc) · 5.07 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
name: Release & Deploy to Clojars
on:
push:
tags: ['v*']
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
name: Release & Deploy to Clojars
steps:
- uses: actions/checkout@v6
with:
ref: main
fetch-depth: 1
token: ${{ secrets.GITHUB_TOKEN }}
- name: Fetch tags and changelog history
run: |
git fetch --tags --no-recurse-submodules origin
git fetch --deepen=200 origin main
- uses: DeLaGuardo/setup-clojure@13.6.1
with:
cli: latest
- name: Cache Clojure deps
uses: actions/cache@v5
with:
path: |
~/.m2/repository
~/.gitlibs
~/.clojure/.cpcache
key: deps-${{ runner.os }}-${{ hashFiles('deps.edn') }}
restore-keys: |
deps-${{ runner.os }}-
- name: Generate changelog
id: changelog
run: |
PREV_TAG=$(git tag --sort=-v:refname | head -n 2 | tail -n 1)
CURRENT_TAG=${{ github.ref_name }}
if [ -z "$PREV_TAG" ] || [ "$PREV_TAG" = "$CURRENT_TAG" ]; then
CHANGELOG=$(git log --pretty=format:"- %s (%h)" $CURRENT_TAG)
else
CHANGELOG=$(git log --pretty=format:"- %s (%h)" ${PREV_TAG}..${CURRENT_TAG})
fi
{
echo "## What's Changed"
echo ""
echo "$CHANGELOG"
echo ""
echo "**Full Changelog**: https://github.com/Blockether/svar/compare/${PREV_TAG}...${CURRENT_TAG}"
} > /tmp/release_body.md
- name: Create GitHub Release
uses: softprops/action-gh-release@v3
with:
body_path: /tmp/release_body.md
- name: Check if version exists on Clojars
id: check-clojars
run: |
VERSION="${GITHUB_REF_NAME#v}"
STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
"https://repo.clojars.org/com/blockether/svar/$VERSION/svar-$VERSION.jar")
if [ "$STATUS" = "200" ]; then
echo "exists=true" >> "$GITHUB_OUTPUT"
echo "::notice::Version $VERSION already exists on Clojars — skipping deploy"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Compile Java sources
if: steps.check-clojars.outputs.exists != 'true'
run: clojure -T:build compile-java
- name: Build & Deploy to Clojars
if: steps.check-clojars.outputs.exists != 'true'
env:
VERSION: ${{ github.ref_name }}
CLOJARS_USERNAME: blockether-deployer
CLOJARS_PASSWORD: ${{ secrets.CLOJARS_DEPLOY_TOKEN }}
run: clojure -T:build deploy
- name: Update README.md version
run: |
VERSION="${GITHUB_REF_NAME#v}"
sed -i "s/{:mvn\/version \"[^\"]*\"}/{:mvn\/version \"$VERSION\"}/g" README.md
- name: Update CHANGELOG.md
run: |
PREV_TAG=$(git tag --sort=-v:refname | head -n 2 | tail -n 1)
CURRENT_TAG=${{ github.ref_name }}
DATE=$(date +%Y-%m-%d)
if [ -z "$PREV_TAG" ] || [ "$PREV_TAG" = "$CURRENT_TAG" ]; then
COMMITS=$(git log --pretty=format:"- %s" $CURRENT_TAG)
else
COMMITS=$(git log --pretty=format:"- %s" ${PREV_TAG}..${CURRENT_TAG})
fi
UNRELEASED_LINE=$(grep -n '^## \[Unreleased\]' CHANGELOG.md | head -1 | cut -d: -f1)
if [ -z "$UNRELEASED_LINE" ]; then
echo "ERROR: Could not find ## [Unreleased] section in CHANGELOG.md"
exit 1
fi
{
head -n "$UNRELEASED_LINE" CHANGELOG.md
echo ""
echo "## [$CURRENT_TAG] - $DATE"
echo ""
echo "### Changed"
echo "$COMMITS"
echo ""
tail -n +$((UNRELEASED_LINE + 1)) CHANGELOG.md
} > CHANGELOG.md.tmp && mv CHANGELOG.md.tmp CHANGELOG.md
sed -i "s|\[Unreleased\]: .*|[Unreleased]: https://github.com/Blockether/svar/compare/${CURRENT_TAG}...HEAD|" CHANGELOG.md
if ! grep -q "^\[${CURRENT_TAG}\]:" CHANGELOG.md; then
echo "[$CURRENT_TAG]: https://github.com/Blockether/svar/releases/tag/${CURRENT_TAG}" >> CHANGELOG.md
fi
- name: Bump VERSION to next patch
run: |
CURRENT="${GITHUB_REF_NAME#v}"
MAJOR=$(echo "$CURRENT" | cut -d. -f1)
MINOR=$(echo "$CURRENT" | cut -d. -f2)
PATCH=$(echo "$CURRENT" | cut -d. -f3)
NEXT_PATCH=$((PATCH + 1))
NEXT_VERSION="${MAJOR}.${MINOR}.${NEXT_PATCH}"
echo "$NEXT_VERSION" > resources/svar/VERSION
echo "Bumped VERSION to $NEXT_VERSION"
- name: Commit version updates
run: |
git config user.name "blockether-deployer"
git config user.email "contact@blockether.com"
git add README.md CHANGELOG.md resources/svar/VERSION
git diff --cached --quiet && echo "No changes to commit" || {
git commit -m "release: update version files for ${{ github.ref_name }}, bump to next dev version"
git push origin main
}