Skip to content

Check GitHub Release #18

Check GitHub Release

Check GitHub Release #18

# Generated by swift-plugin-generator 0.1.0
name: Check GitHub Release
permissions:
contents: write
on:
schedule:
- cron: '20 8,20 * * *'
workflow_dispatch:
jobs:
check:
name: Check GitHub Release
runs-on: ubuntu-latest
env:
BINARY_NAME: subtree
BINARY_REPO: 21-DOT-DEV/subtree
PLUGIN_REPO: 21-DOT-DEV/swift-plugin-subtree
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SEMANTIC_VERSIONING_REGEX: "^[v]?[0-9]+\\.[0-9]+\\.[0-9]+$"
outputs:
BINARY_NAME: ${{ env.BINARY_NAME }}
BINARY_REPO: ${{ env.BINARY_REPO }}
BINARY_VERSION: ${{ steps.two.outputs.BINARY_VERSION }}
PLUGIN_VERSION: ${{ steps.one.outputs.PLUGIN_VERSION }}
steps:
- name: Get current plugin version
id: one
run: |
PLUGIN_RELEASE=$(gh release list -R ${{ github.repository }} -L 10 --json tagName,publishedAt \
--jq 'map(select(.tagName | test(env.SEMANTIC_VERSIONING_REGEX))) | sort_by(.publishedAt) | reverse | .[0].tagName')
echo "PLUGIN_VERSION=$PLUGIN_RELEASE" >> $GITHUB_OUTPUT
echo "→ Plugin version: $PLUGIN_RELEASE"
- name: Get current binary version
id: two
run: |
BINARY_RELEASE=$(gh release list -R ${{ env.BINARY_REPO }} -L 10 --json tagName,publishedAt \
--jq 'map(select(.tagName | test(env.SEMANTIC_VERSIONING_REGEX))) | sort_by(.publishedAt) | reverse | .[0].tagName')
echo "BINARY_VERSION=$BINARY_RELEASE" >> $GITHUB_OUTPUT
echo "→ Binary version: $BINARY_RELEASE"
update:
name: Update Consumer Package
needs: check
runs-on: macos-15
if: ${{ needs.check.outputs.PLUGIN_VERSION != needs.check.outputs.BINARY_VERSION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
- name: Update Package.swift with new artifact bundle
run: |
NEW_VERSION="${{ needs.check.outputs.BINARY_VERSION }}"
NEW_URL="https://github.com/21-DOT-DEV/subtree/releases/download/${NEW_VERSION}/subtree.artifactbundle.zip"
echo "→ Downloading artifact bundle from: $NEW_URL"
curl -sL "$NEW_URL" -o bundle.zip
echo "→ Calculating checksum..."
NEW_CHECKSUM=$(swift package compute-checksum bundle.zip)
rm bundle.zip
echo "→ Updating Package.swift..."
# Use awk to only update the binaryTarget url and checksum
awk -v url="$NEW_URL" -v checksum="$NEW_CHECKSUM" '
/\.binaryTarget\(/ { in_binary = 1 }
in_binary && /url:/ {
sub(/url: ".*"/, "url: \"" url "\"")
}
in_binary && /checksum:/ {
sub(/checksum: ".*"/, "checksum: \"" checksum "\"")
}
/\),/ && in_binary { in_binary = 0 }
{ print }
' Package.swift > Package.swift.tmp && mv Package.swift.tmp Package.swift
echo "✓ Package.swift updated"
- name: Validate updated Package.swift
run: |
swift build
echo "✓ Build validation passed"
- name: Fetch upstream release notes
run: |
NEW_VERSION="${{ needs.check.outputs.BINARY_VERSION }}"
NOTES=$(gh release view "$NEW_VERSION" \
--repo "21-DOT-DEV/subtree" \
--json body \
--jq '.body' 2>/dev/null || echo "Release notes unavailable")
echo "$NOTES" > release_notes.md
- name: Commit, push, and create release
run: |
NEW_VERSION="${{ needs.check.outputs.BINARY_VERSION }}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Package.swift
git commit -m "chore: update to subtree $NEW_VERSION"
git push
gh release create "$NEW_VERSION" \
--repo "21-DOT-DEV/swift-plugin-subtree" \
--title "subtree $NEW_VERSION" \
--notes-file release_notes.md
echo "✓ Committed, pushed, and created release: $NEW_VERSION"