|
| 1 | +# Generated by swift-plugin-generator 0.1.0 |
| 2 | +name: Check GitHub Release |
| 3 | + |
| 4 | +permissions: |
| 5 | + contents: write |
| 6 | + |
| 7 | +on: |
| 8 | + schedule: |
| 9 | + - cron: '20 8,20 * * *' |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +jobs: |
| 13 | + check: |
| 14 | + name: Check GitHub Release |
| 15 | + runs-on: ubuntu-latest |
| 16 | + env: |
| 17 | + BINARY_NAME: subtree |
| 18 | + BINARY_REPO: 21-DOT-DEV/subtree |
| 19 | + PLUGIN_REPO: 21-DOT-DEV/swift-plugin-subtree |
| 20 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 21 | + SEMANTIC_VERSIONING_REGEX: "^[v]?[0-9]+\\.[0-9]+\\.[0-9]+$" |
| 22 | + outputs: |
| 23 | + BINARY_NAME: ${{ env.BINARY_NAME }} |
| 24 | + BINARY_REPO: ${{ env.BINARY_REPO }} |
| 25 | + BINARY_VERSION: ${{ steps.two.outputs.BINARY_VERSION }} |
| 26 | + PLUGIN_VERSION: ${{ steps.one.outputs.PLUGIN_VERSION }} |
| 27 | + steps: |
| 28 | + - name: Get current plugin version |
| 29 | + id: one |
| 30 | + run: | |
| 31 | + PLUGIN_RELEASE=$(gh release list -R ${{ github.repository }} -L 10 --json tagName,publishedAt \ |
| 32 | + --jq 'map(select(.tagName | test(env.SEMANTIC_VERSIONING_REGEX))) | sort_by(.publishedAt) | reverse | .[0].tagName') |
| 33 | + echo "PLUGIN_VERSION=$PLUGIN_RELEASE" >> $GITHUB_OUTPUT |
| 34 | + echo "→ Plugin version: $PLUGIN_RELEASE" |
| 35 | + |
| 36 | + - name: Get current binary version |
| 37 | + id: two |
| 38 | + run: | |
| 39 | + BINARY_RELEASE=$(gh release list -R ${{ env.BINARY_REPO }} -L 10 --json tagName,publishedAt \ |
| 40 | + --jq 'map(select(.tagName | test(env.SEMANTIC_VERSIONING_REGEX))) | sort_by(.publishedAt) | reverse | .[0].tagName') |
| 41 | + echo "BINARY_VERSION=$BINARY_RELEASE" >> $GITHUB_OUTPUT |
| 42 | + echo "→ Binary version: $BINARY_RELEASE" |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | + update: |
| 48 | + name: Update Consumer Package |
| 49 | + needs: check |
| 50 | + runs-on: macos-15 |
| 51 | + if: ${{ needs.check.outputs.PLUGIN_VERSION != needs.check.outputs.BINARY_VERSION }} |
| 52 | + env: |
| 53 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 54 | + steps: |
| 55 | + - uses: actions/checkout@v4 |
| 56 | + |
| 57 | + - name: Update Package.swift with new artifact bundle |
| 58 | + run: | |
| 59 | + NEW_VERSION="${{ needs.check.outputs.BINARY_VERSION }}" |
| 60 | + NEW_URL="https://github.com/21-DOT-DEV/subtree/releases/download/${NEW_VERSION}/subtree.artifactbundle.zip" |
| 61 | + |
| 62 | + echo "→ Downloading artifact bundle from: $NEW_URL" |
| 63 | + curl -sL "$NEW_URL" -o bundle.zip |
| 64 | + |
| 65 | + echo "→ Calculating checksum..." |
| 66 | + NEW_CHECKSUM=$(swift package compute-checksum bundle.zip) |
| 67 | + rm bundle.zip |
| 68 | + |
| 69 | + echo "→ Updating Package.swift..." |
| 70 | + # Use awk to only update the binaryTarget url and checksum |
| 71 | + awk -v url="$NEW_URL" -v checksum="$NEW_CHECKSUM" ' |
| 72 | + /\.binaryTarget\(/ { in_binary = 1 } |
| 73 | + in_binary && /url:/ { |
| 74 | + sub(/url: ".*"/, "url: \"" url "\"") |
| 75 | + } |
| 76 | + in_binary && /checksum:/ { |
| 77 | + sub(/checksum: ".*"/, "checksum: \"" checksum "\"") |
| 78 | + } |
| 79 | + /\),/ && in_binary { in_binary = 0 } |
| 80 | + { print } |
| 81 | + ' Package.swift > Package.swift.tmp && mv Package.swift.tmp Package.swift |
| 82 | + |
| 83 | + echo "✓ Package.swift updated" |
| 84 | + |
| 85 | + - name: Validate updated Package.swift |
| 86 | + run: | |
| 87 | + swift build |
| 88 | + echo "✓ Build validation passed" |
| 89 | + |
| 90 | + - name: Fetch upstream release notes |
| 91 | + run: | |
| 92 | + NEW_VERSION="${{ needs.check.outputs.BINARY_VERSION }}" |
| 93 | + NOTES=$(gh release view "$NEW_VERSION" \ |
| 94 | + --repo "21-DOT-DEV/subtree" \ |
| 95 | + --json body \ |
| 96 | + --jq '.body' 2>/dev/null || echo "Release notes unavailable") |
| 97 | + echo "$NOTES" > release_notes.md |
| 98 | + |
| 99 | + - name: Commit, push, and create release |
| 100 | + run: | |
| 101 | + NEW_VERSION="${{ needs.check.outputs.BINARY_VERSION }}" |
| 102 | + |
| 103 | + git config user.name "github-actions[bot]" |
| 104 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 105 | + git add Package.swift |
| 106 | + git commit -m "chore: update to subtree $NEW_VERSION" |
| 107 | + git push |
| 108 | + |
| 109 | + gh release create "$NEW_VERSION" \ |
| 110 | + --repo "21-DOT-DEV/swift-plugin-subtree" \ |
| 111 | + --title "subtree $NEW_VERSION" \ |
| 112 | + --notes-file release_notes.md |
| 113 | + |
| 114 | + echo "✓ Committed, pushed, and created release: $NEW_VERSION" |
| 115 | +
|
0 commit comments