|
| 1 | +name: Check Upstream Releases |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 6 * * *' # Run daily at 6 AM UTC |
| 6 | + workflow_dispatch: # Allow manual trigger |
| 7 | + |
| 8 | +jobs: |
| 9 | + check-upstream: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + pull-requests: write |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout repository |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 20 | + ref: stable |
| 21 | + |
| 22 | + - name: Get latest upstream tag |
| 23 | + id: upstream |
| 24 | + run: | |
| 25 | + # Fetch tags from upstream repository |
| 26 | + LATEST_TAG=$(git ls-remote --tags --sort=-v:refname \ |
| 27 | + https://github.com/lemonade-sdk/lemonade.git \ |
| 28 | + | grep -oP 'refs/tags/\K[^{}]+$' \ |
| 29 | + | head -n 1) |
| 30 | +
|
| 31 | + echo "Latest upstream tag: $LATEST_TAG" |
| 32 | + echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT |
| 33 | +
|
| 34 | + - name: Get current source-tag from snapcraft.yaml |
| 35 | + id: current |
| 36 | + run: | |
| 37 | + # Extract current source-tag if it exists |
| 38 | + CURRENT_TAG=$(grep -oP '^\s+source-tag:\s*\K.*' snap/snapcraft.yaml || echo "") |
| 39 | + echo "Current source-tag: $CURRENT_TAG" |
| 40 | + echo "tag=$CURRENT_TAG" >> $GITHUB_OUTPUT |
| 41 | +
|
| 42 | + - name: Check if update is needed |
| 43 | + id: check |
| 44 | + run: | |
| 45 | + if [ "${{ steps.upstream.outputs.tag }}" != "${{ steps.current.outputs.tag }}" ]; then |
| 46 | + echo "Update needed: ${{ steps.current.outputs.tag }} -> ${{ steps.upstream.outputs.tag }}" |
| 47 | + echo "update_needed=true" >> $GITHUB_OUTPUT |
| 48 | + else |
| 49 | + echo "Already up to date" |
| 50 | + echo "update_needed=false" >> $GITHUB_OUTPUT |
| 51 | + fi |
| 52 | +
|
| 53 | + - name: Update snapcraft.yaml |
| 54 | + if: steps.check.outputs.update_needed == 'true' |
| 55 | + run: | |
| 56 | + NEW_TAG="${{ steps.upstream.outputs.tag }}" |
| 57 | +
|
| 58 | + # Check if source-tag already exists in the lemonade part |
| 59 | + if grep -q '^\s\+source-tag:' snap/snapcraft.yaml; then |
| 60 | + # Update existing source-tag |
| 61 | + sed -i "s/^\(\s\+source-tag:\s*\).*/\1$NEW_TAG/" snap/snapcraft.yaml |
| 62 | + else |
| 63 | + # Add source-tag after source-subdir line in lemonade part |
| 64 | + sed -i "/^\s\+source-subdir: src\/app/a\\ source-tag: $NEW_TAG" snap/snapcraft.yaml |
| 65 | + fi |
| 66 | +
|
| 67 | + echo "Updated snapcraft.yaml to use tag: $NEW_TAG" |
| 68 | + cat snap/snapcraft.yaml |
| 69 | +
|
| 70 | + - name: Create Pull Request |
| 71 | + if: steps.check.outputs.update_needed == 'true' |
| 72 | + uses: peter-evans/create-pull-request@v6 |
| 73 | + with: |
| 74 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 75 | + commit-message: "Update to upstream ${{ steps.upstream.outputs.tag }}" |
| 76 | + title: "Update to upstream ${{ steps.upstream.outputs.tag }}" |
| 77 | + body: | |
| 78 | + Automated update to track upstream release. |
| 79 | +
|
| 80 | + **Changes:** |
| 81 | + - Updated source-tag from `${{ steps.current.outputs.tag }}` to `${{ steps.upstream.outputs.tag }}` |
| 82 | +
|
| 83 | + **Upstream release:** |
| 84 | + https://github.com/lemonade-sdk/lemonade/releases/tag/${{ steps.upstream.outputs.tag }} |
| 85 | + branch: update-upstream-${{ steps.upstream.outputs.tag }} |
| 86 | + delete-branch: true |
0 commit comments