|
1 | 1 | name: Update Compatible Versions
|
2 | 2 |
|
3 | 3 | on:
|
4 |
| - workflow_run: |
5 |
| - workflows: [ "Build and Publish" ] |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened] # dont trigger on closed |
6 | 6 | branches:
|
| 7 | + - main |
7 | 8 | - develop
|
8 |
| - types: |
9 |
| - - completed |
10 |
| - |
11 |
| - pull_request: |
12 |
| - types: |
13 |
| - - closed # Ensures it runs only on PR closure (merge) |
14 | 9 |
|
15 | 10 | jobs:
|
16 | 11 | update-compatible-versions:
|
17 |
| - if: github.event.pull_request.merged == true # Runs only if PR is merged |
18 | 12 | runs-on: ubuntu-latest
|
19 | 13 |
|
20 | 14 | steps:
|
21 | 15 | - name: Checkout repository
|
22 | 16 | uses: actions/checkout@v4
|
| 17 | + with: |
| 18 | + ref: ${{ github.head_ref }} |
| 19 | + |
| 20 | + - name: Check if CLI version was already updated |
| 21 | + id: check_version |
| 22 | + run: | |
| 23 | + # Extract current version from pyproject.toml |
| 24 | + CURRENT_VERSION=$(grep '^version =' pyproject.toml | sed -E 's/version = "(.*)"/\1/') |
| 25 | + echo "Current version: $CURRENT_VERSION" |
| 26 | +
|
| 27 | + # Read the last entry from NDJSON file (if it exists) |
| 28 | + LAST_VERSION=$(tail -n 1 docs/compatible_version.ndjson 2>/dev/null | jq -r '."Cli Version"') |
| 29 | +
|
| 30 | + echo "Last updated version: $LAST_VERSION" |
| 31 | + echo "current=$CURRENT_VERSION" >> "$GITHUB_OUTPUT" |
| 32 | + echo "last=$LAST_VERSION" >> "$GITHUB_OUTPUT" |
| 33 | +
|
| 34 | + - name: Exit if already updated |
| 35 | + if: ${{ steps.check_version.outputs.current == steps.check_version.outputs.last }} |
| 36 | + run: | |
| 37 | + echo "This version was already recorded. Skipping update." |
23 | 38 |
|
24 | 39 | - name: Extract Versions from PR
|
| 40 | + if: ${{ steps.check_version.outputs.current != steps.check_version.outputs.last }} |
25 | 41 | id: extract_versions
|
26 | 42 | run: |
|
27 | 43 | PR_BODY="${{ github.event.pull_request.body }}"
|
|
50 | 66 | echo "$NEW_ENTRY" >> docs/compatible_version.ndjson
|
51 | 67 |
|
52 | 68 | - name: Embed Compatible Versions into README
|
| 69 | + if: ${{ steps.check_version.outputs.current != steps.check_version.outputs.last }} |
53 | 70 | run: |
|
54 | 71 | # Define markers
|
55 | 72 | START_MARKER="<!-- COMPATIBLE_VERSIONS_START -->"
|
@@ -77,10 +94,15 @@ jobs:
|
77 | 94 | mv README_UPDATED.md README.md
|
78 | 95 |
|
79 | 96 | - name: Commit and Push Changes
|
| 97 | + if: ${{ steps.check_version.outputs.current != steps.check_version.outputs.last }} |
80 | 98 | run: |
|
81 | 99 | git config user.name "GitHub Actions"
|
82 | 100 | git config user.email "[email protected]"
|
| 101 | + git pull origin ${{ github.head_ref }} |
83 | 102 | git add docs/compatible_version.ndjson README.md
|
84 | 103 | git commit -m "Updated docs/compatible_version.ndjson with PR #${{ github.event.pull_request.number }}"
|
85 |
| - git push |
86 |
| - continue-on-error: true # Avoid breaking workflow if no changes detected |
| 104 | +
|
| 105 | + - name: Push change to feature branch |
| 106 | + if: ${{ steps.check_version.outputs.current != steps.check_version.outputs.last }} |
| 107 | + run: | |
| 108 | + git push origin HEAD:${{ github.head_ref }} -f |
0 commit comments