Skip to content

Commit 64eca49

Browse files
authored
Merge pull request #21 from LonghornRacingElectric/releases
automatic releases based on project/version
2 parents a1b0f33 + 0b08e38 commit 64eca49

1 file changed

Lines changed: 56 additions & 20 deletions

File tree

.github/workflows/release.yml

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,97 @@
1-
# .github/workflows/release.yml
21
name: Release
32

43
on:
54
push:
65
tags:
76
- "**/v*"
8-
- "**/v*"
97

108
jobs:
119
build_and_release:
1210
runs-on: ubuntu-latest
1311
steps:
1412
- name: Checkout
15-
uses: actions/checkout@v3
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
1616

1717
- name: Get Bazel
1818
uses: bazel-contrib/setup-bazel@0.8.1
1919
with:
20-
# Avoid downloading Bazel every time.
2120
bazelisk-cache: true
22-
# Store build cache per workflow.
2321
disk-cache: ${{ github.workflow }}
24-
# Share repository cache between workflows.
2522
repository-cache: true
2623

27-
- name: Build Release Artifacts
28-
id: build
24+
- name: Generate Changelog
25+
id: generate_changelog
2926
run: |
3027
FULL_TAG="${{ github.ref_name }}"
31-
PROJECT_NAME="${FULL_TAG%/*}"
32-
bazel build //${PROJECT_NAME}:release
33-
ARTIFACT_PATH=$(bazel cquery --output=files //${PROJECT_NAME}:release)
34-
echo "::set-output name=artifact_path::${ARTIFACT_PATH}"
35-
echo "::set-output name=artifact_name::$(basename ${ARTIFACT_PATH})"
28+
29+
if [[ "$FULL_TAG" == *"/"* ]]; then
30+
PROJECT_NAME="${FULL_TAG%/*}"
31+
TAG_PATTERN="${PROJECT_NAME}/v*"
32+
else
33+
PROJECT_NAME=""
34+
TAG_PATTERN="v*"
35+
fi
36+
37+
echo "Current tag: ${FULL_TAG}"
38+
echo "Project component: ${PROJECT_NAME}"
39+
echo "Tag pattern: ${TAG_PATTERN}"
40+
41+
# Get the previous tag for this specific component by listing all matching tags,
42+
# sorting them by version, and picking the second to last one.
43+
PREVIOUS_TAG=$(git tag -l "${TAG_PATTERN}" | sort -V | tail -n 2 | head -n 1)
44+
45+
if [ -z "$PREVIOUS_TAG" ]; then
46+
echo "No previous tag found for this component. Using first commit."
47+
LOG_MESSAGES=$(git log --pretty=format:'- %s (%h)')
48+
else
49+
echo "Found previous tag: ${PREVIOUS_TAG}"
50+
# Generate the log from the previous tag to the current one (HEAD)
51+
LOG_MESSAGES=$(git log "${PREVIOUS_TAG}"..HEAD --pretty=format:'- %s (%h)')
52+
fi
53+
54+
echo "Generated changelog:"
55+
echo "$LOG_MESSAGES"
56+
57+
{
58+
echo "changelog<<EOF"
59+
echo "$LOG_MESSAGES"
60+
echo "EOF"
61+
} >> "$GITHUB_OUTPUT"
3662
3763
- name: Create Release
64+
id: create_release
3865
uses: actions/create-release@v1
3966
env:
4067
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4168
with:
42-
tag_name: ${{ github.ref }}
43-
release_name: Release ${{ github.ref }}
69+
tag_name: ${{ github.ref_name }}
70+
release_name: Release ${{ github.ref_name }}
4471
body: |
45-
${{ github.event.head_commit.message }}
46-
New release for ${{ github.ref }}
72+
## Changelog
73+
${{ steps.generate_changelog.outputs.changelog }}
4774
draft: false
4875
prerelease: false
4976

5077
- name: Build and Upload Release Artifacts
5178
env:
5279
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5380
run: |
54-
PROJECT_NAME=$(echo ${{ github.ref_name }} | cut -d/ -f1)
55-
bazel build //${PROJECT_NAME}/firmware:release
81+
FULL_TAG="${{ github.ref_name }}"
82+
83+
if [[ "$FULL_TAG" == *"/"* ]]; then
84+
PROJECT_NAME="${FULL_TAG%/*}"
85+
MAIN_TARGET="//${PROJECT_NAME}:release"
86+
else
87+
MAIN_TARGET="//:release"
88+
fi
89+
90+
echo "Building main target: ${MAIN_TARGET}"
91+
bazel build ${MAIN_TARGET}
5692
5793
echo "Uploading assets..."
58-
for file in $(bazel cquery --output=files //${PROJECT_NAME}/firmware:release); do
94+
for file in $(bazel cquery --output=files "${MAIN_TARGET}"); do
5995
echo "Uploading $file"
6096
gh release upload ${{ github.ref_name }} "$file" --clobber
6197
done

0 commit comments

Comments
 (0)