-
Notifications
You must be signed in to change notification settings - Fork 0
134 lines (109 loc) · 4.49 KB
/
release.yml
File metadata and controls
134 lines (109 loc) · 4.49 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
name: Release
on:
push:
branches:
- main
workflow_dispatch:
permissions:
contents: write
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
jobs:
release:
name: Release to Hex.pm
runs-on: ubuntu-latest
timeout-minutes: 15
if: github.event_name != 'push' || !startsWith(github.event.head_commit.message, '[Release]')
steps:
- name: Check out the repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Install tooling with mise
uses: jdx/mise-action@v4
with:
cache: true
- name: Install Hex and Rebar
run: |
mix local.hex --force
mix local.rebar --force
- name: Fetch dependencies
run: mix deps.get
- name: Plan release
id: plan
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
current_version=$(elixir scripts/version.exs current)
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || true)
if [ -n "$latest_tag" ]; then
git cliff --config .github/cliff-release.toml --context --unreleased > release-context.json
else
git cliff --config .github/cliff-release.toml --context > release-context.json
fi
releaseable_count=$(jq 'if length == 0 then 0 else .[0].commits | length end' release-context.json)
if [ "$releaseable_count" -eq 0 ]; then
echo "should_release=false" >> "$GITHUB_OUTPUT"
exit 0
fi
if jq -e '.[0].commits[] | select(.message | test("BREAKING CHANGE|!:"))' release-context.json > /dev/null; then
bump_type=major
elif jq -e '.[0].commits[] | select(.group == "Features")' release-context.json > /dev/null; then
bump_type=minor
else
bump_type=patch
fi
if [ -n "$latest_tag" ]; then
next_version=$(elixir scripts/version.exs bump "$latest_tag" "$bump_type")
git cliff --tag "$next_version" -o CHANGELOG.next.md
git cliff --config .github/cliff-release.toml --tag "$next_version" --unreleased --strip all -o RELEASE_NOTES.md
else
next_version="$current_version"
git cliff --tag "$next_version" -o CHANGELOG.next.md
git cliff --config .github/cliff-release.toml --tag "$next_version" --strip all -o RELEASE_NOTES.md
fi
echo "should_release=true" >> "$GITHUB_OUTPUT"
echo "current_version=$current_version" >> "$GITHUB_OUTPUT"
echo "next_version=$next_version" >> "$GITHUB_OUTPUT"
echo "bump_type=$bump_type" >> "$GITHUB_OUTPUT"
- name: Update version and changelog
if: steps.plan.outputs.should_release == 'true'
run: |
elixir scripts/version.exs set "${{ steps.plan.outputs.next_version }}"
mv CHANGELOG.next.md CHANGELOG.md
- name: Validate Hex package
if: steps.plan.outputs.should_release == 'true'
run: |
build_dir="$(mktemp -d /tmp/terrarium-hex-build-XXXXXX)"
mix hex.build --unpack -o "$build_dir"
- name: Publish release
id: publish
if: steps.plan.outputs.should_release == 'true'
env:
HEX_API_KEY: ${{ secrets.HEX_API_KEY }}
shell: bash
run: |
set -euo pipefail
: "${HEX_API_KEY:?HEX_API_KEY secret is required}"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add mix.exs CHANGELOG.md
git commit -m "[Release] Terrarium ${{ steps.plan.outputs.next_version }}"
git tag -a "${{ steps.plan.outputs.next_version }}" -m "${{ steps.plan.outputs.next_version }}"
mix hex.publish package --yes
git push origin HEAD:main
git push origin "${{ steps.plan.outputs.next_version }}"
echo "release_commit=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- name: Create GitHub release
if: steps.plan.outputs.should_release == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "${{ steps.plan.outputs.next_version }}" \
--repo "$GITHUB_REPOSITORY" \
--target "${{ steps.publish.outputs.release_commit }}" \
--title "${{ steps.plan.outputs.next_version }}" \
--notes-file RELEASE_NOTES.md