forked from UBC-Thunderbots/Software
-
Notifications
You must be signed in to change notification settings - Fork 0
162 lines (142 loc) · 5.23 KB
/
release.yml
File metadata and controls
162 lines (142 loc) · 5.23 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: Release binary
on:
schedule:
- cron: '0 0 * * 0' # Weekly Patch (Sundays)
- cron: '0 0 1 * *' # Monthly Minor (1st of the month)
workflow_dispatch:
inputs:
version_type:
description: 'Manual Release Level'
required: true
default: 'major'
type: choice
options:
- major
- minor
- patch
release_tag:
description: 'Specify the new release tag name (e.g., v1.2.3)'
required: false
type: string
target_commit:
description: 'Optional commit SHA/branch to release (leave empty for current HEAD)'
required: false
type: string
default: ''
jobs:
prepare_release:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.bump_logic.outputs.tag }}
should_release: ${{ steps.check.outputs.count > 0 }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.inputs.target_commit || github.sha }}
- name: Check for recent commits
id: check
run: |
git fetch --tags
LATEST_TAG=$(git describe --tags --match "v[0-9]*" --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "Latest tag: $LATEST_TAG"
# Prevent double release on the same day (unless manual dispatch)
if [ "${{ github.event_name }}" != "workflow_dispatch" ] && [ "$LATEST_TAG" != "v0.0.0" ]; then
TAG_DATE=$(git log -1 --format=%as "$LATEST_TAG")
TODAY=$(date +%Y-%m-%d)
echo "Tag Date: $TAG_DATE, Today: $TODAY"
if [ "$TAG_DATE" = "$TODAY" ]; then
echo "Already released $LATEST_TAG today. Skipping."
echo "count=0" >> $GITHUB_OUTPUT
exit 0
fi
fi
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "count=1" >> $GITHUB_OUTPUT
else
if [ "$LATEST_TAG" = "v0.0.0" ]; then
COUNT=$(git log --oneline | wc -l)
else
COUNT=$(git log "$LATEST_TAG"..HEAD --oneline | wc -l)
fi
echo "count=$COUNT" >> $GITHUB_OUTPUT
fi
- name: Determine Version Bump
if: steps.check.outputs.count > 0
id: bump_logic
run: |
LATEST_TAG=$(git describe --tags --match "v[0-9]*" --abbrev=0 2>/dev/null || echo "v1.0.0")
BASE_VERSION=${LATEST_TAG#v}
IFS='.' read -r major minor patch <<< "$BASE_VERSION"
if [ "${{ github.event.inputs.release_tag }}" != "" ]; then
NEW_TAG="${{ github.event.inputs.release_tag }}"
else
BUMP="patch"
if [ "$(date +%d)" = "01" ]; then BUMP="minor"; fi
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
BUMP="${{ github.event.inputs.version_type }}"
fi
if [ "$BUMP" = "major" ]; then
major=$((major + 1)); minor=0; patch=0
elif [ "$BUMP" = "minor" ]; then
minor=$((minor + 1)); patch=0
else
patch=$((patch + 1))
fi
NEW_TAG="v$major.$minor.$patch"
fi
echo "tag=$NEW_TAG" >> $GITHUB_OUTPUT
echo "Using version: $NEW_TAG"
- name: Draft Release Notes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: release-drafter/release-drafter@v6
with:
version: ${{ steps.bump_logic.outputs.tag }}
tag: ${{ steps.bump_logic.outputs.tag }}
upload_assets:
needs: prepare_release
if: needs.prepare_release.outputs.should_release == 'true'
strategy:
matrix:
platform: [ubuntu-x86, mac-arm64]
include:
- platform: ubuntu-x86
runner: ubuntu-24.04
- platform: mac-arm64
runner: macos-latest
runs-on: ${{ matrix.runner }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.inputs.target_commit || github.ref }}
- uses: ./.github/actions/environment-setup
- name: Build Binaries
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd src
TAG="${{ needs.prepare_release.outputs.tag }}"
bazel build --show_timestamps --copt=-O3 --verbose_failures \
-- //software:unix_full_system_tar_gen
ARTIFACT_NAME="unix_full_system_${TAG}_${{ matrix.platform }}.tar.gz"
mv bazel-bin/software/unix_full_system_tar_gen.tar.gz "${{ runner.temp }}/$ARTIFACT_NAME"
gh release upload "$TAG" "${{ runner.temp }}/$ARTIFACT_NAME"
publish_release:
needs: [prepare_release, upload_assets]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.target_commit || github.sha }}
- name: Undraft Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh release edit "${{ needs.prepare_release.outputs.tag }}" --draft=false --latest