|
6 | 6 | pull_request:
|
7 | 7 | branches: [ "main" ]
|
8 | 8 |
|
| 9 | +permissions: |
| 10 | + contents: write # required to push tags & create releases |
| 11 | + |
9 | 12 | jobs:
|
10 | 13 | build:
|
11 |
| - |
12 | 14 | runs-on: ubuntu-latest
|
13 |
| - |
14 | 15 | 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