Skip to content

Commit 529329b

Browse files
committed
Update workflow to support automatic releases
1 parent da9d55e commit 529329b

File tree

1 file changed

+65
-18
lines changed

1 file changed

+65
-18
lines changed

.github/workflows/c-cpp.yml

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,72 @@ on:
66
pull_request:
77
branches: [ "main" ]
88

9+
permissions:
10+
contents: write # required to push tags & create releases
11+
912
jobs:
1013
build:
11-
1214
runs-on: ubuntu-latest
13-
1415
steps:
15-
- uses: actions/checkout@v4
16-
- name: Clean build
17-
run: make clean || true
18-
19-
- name: Build (Release)
20-
run: make BUILD_TYPE=release
21-
22-
- name: Run watchdog
23-
run: |
24-
echo "Running processWatchdog..."
25-
chmod +x monitor.sh
26-
./monitor.sh 2 1 5 3 600 ./processWatchdog > release_watchdog_stdout.log 2> release_watchdog_stderr.log
27-
echo "Standard Output:"
28-
cat release_watchdog_stdout.log
29-
echo "Standard Error:"
30-
cat release_watchdog_stderr.log
16+
- uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0 # ensure full history & tags are available
19+
20+
- name: Clean build
21+
run: make clean || true
22+
23+
- name: Build (Release)
24+
run: make BUILD_TYPE=release
25+
26+
- name: Run watchdog
27+
run: |
28+
echo "Running processWatchdog..."
29+
chmod +x monitor.sh
30+
./monitor.sh 2 1 5 3 600 ./processWatchdog > release_watchdog_stdout.log 2> release_watchdog_stderr.log
31+
echo "Standard Output:"
32+
cat release_watchdog_stdout.log
33+
echo "Standard Error:"
34+
cat release_watchdog_stderr.log
35+
36+
# --- Release automation (only runs on push to main) ---
37+
38+
- name: Extract version from main.c
39+
id: get_version
40+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
41+
run: |
42+
VERSION=$(grep -oP '(?<=#define VERSION\s+")[^"]+' main.c || true)
43+
if [ -z "$VERSION" ]; then
44+
echo "Failed to extract VERSION from main.c"; exit 1
45+
fi
46+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
47+
echo "Detected version: $VERSION"
48+
49+
- name: Check if tag exists remotely
50+
id: check_tag
51+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
52+
run: |
53+
git fetch --tags --force
54+
TAG="v${{ steps.get_version.outputs.version }}"
55+
if git ls-remote --tags origin "refs/tags/${TAG}" | grep -q "${TAG}$"; then
56+
echo "exists=true" >> "$GITHUB_OUTPUT"
57+
echo "Tag ${TAG} already exists."
58+
else
59+
echo "exists=false" >> "$GITHUB_OUTPUT"
60+
echo "Tag ${TAG} does not exist."
61+
fi
62+
63+
- name: Create tag
64+
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.check_tag.outputs.exists == 'false'
65+
run: |
66+
git config user.name "github-actions"
67+
git config user.email "[email protected]"
68+
TAG="v${{ steps.get_version.outputs.version }}"
69+
git tag "${TAG}"
70+
git push origin "${TAG}"
71+
72+
- name: Create GitHub Release
73+
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.check_tag.outputs.exists == 'false'
74+
uses: softprops/action-gh-release@v2
75+
with:
76+
tag_name: v${{ steps.get_version.outputs.version }}
77+
generate_release_notes: true

0 commit comments

Comments
 (0)