-
Notifications
You must be signed in to change notification settings - Fork 0
103 lines (90 loc) · 3.24 KB
/
build-main.yml
File metadata and controls
103 lines (90 loc) · 3.24 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
name: Build Main
on:
push:
branches: [main]
# Prevent concurrent releases racing to create the same version tag
concurrency:
group: release
cancel-in-progress: false
permissions:
contents: write
jobs:
check-release:
runs-on: ubuntu-latest
outputs:
should_release: ${{ steps.check_changes.outputs.should_release }}
release_tag: ${{ steps.version_outputs.outputs.tag }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate changelog
id: changelog
uses: orhun/git-cliff-action@v4
with:
config: .github/cliff.toml
args: --unreleased --strip header
- name: Check for release-worthy changes
id: check_changes
# git-cliff outputs ### section headers only when there are matching commits
# (## [unreleased] header is always output, so we check for ### specifically)
run: |
if echo "${{ steps.changelog.outputs.content }}" | grep -q '###'; then
echo "Release-worthy changes found"
echo "should_release=true" >> $GITHUB_OUTPUT
else
echo "No release-worthy changes found"
echo "should_release=false" >> $GITHUB_OUTPUT
fi
- name: Detect bump type
if: steps.check_changes.outputs.should_release == 'true'
id: bump
run: |
BUMP_TYPE=$(.github/workflows/detect-bump.sh)
echo "type=$BUMP_TYPE" >> $GITHUB_OUTPUT
echo "Bump type: $BUMP_TYPE"
- name: Calculate next version
if: steps.check_changes.outputs.should_release == 'true'
id: version
uses: orhun/git-cliff-action@v4
with:
config: .github/cliff.toml
args: --bump ${{ steps.bump.outputs.type }} --bumped-version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set version outputs
if: steps.check_changes.outputs.should_release == 'true'
id: version_outputs
run: |
VERSION="${{ steps.version.outputs.content }}"
VERSION="${VERSION#v}" # Remove v prefix if present
VERSION="${VERSION%%$'\n'*}" # Remove any trailing newlines
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=v$VERSION" >> $GITHUB_OUTPUT
echo "Version: $VERSION, Tag: v$VERSION"
ci:
needs: check-release
uses: ./.github/workflows/_ci.yml
secrets: inherit
with:
release_tag: ${{ needs.check-release.outputs.release_tag }}
create-tag:
needs: [check-release, ci]
if: needs.check-release.outputs.should_release == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
- name: Create git tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag ${{ needs.check-release.outputs.release_tag }}
git push origin ${{ needs.check-release.outputs.release_tag }}
release:
needs: [check-release, ci, create-tag]
if: needs.check-release.outputs.should_release == 'true'
uses: ./.github/workflows/_release.yml
with:
release_tag: ${{ needs.check-release.outputs.release_tag }}