Update Package Version #626
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update Package Version | |
on: | |
schedule: | |
- cron: '0 */2 * * *' # Every 2 hours | |
workflow_dispatch: # Allow manual trigger | |
pull_request: | |
paths: | |
- 'sourcegraph-amp/PKGBUILD' | |
types: [opened, synchronize] | |
jobs: | |
check-and-update: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
ref: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref }} | |
fetch-depth: 0 | |
- name: Check if update is needed | |
id: version-check | |
run: | | |
chmod +x pkg.sh | |
if output=$(./pkg.sh check-latest); then | |
echo "update_needed=true" >> $GITHUB_OUTPUT | |
echo "$output" >> $GITHUB_OUTPUT | |
echo "✅ Update available - proceeding with Docker build" | |
else | |
echo "update_needed=false" >> $GITHUB_OUTPUT | |
echo "ℹ️ No update needed - skipping Docker build" | |
fi | |
- name: Set up Docker Buildx | |
if: steps.version-check.outputs.update_needed == 'true' | |
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3 | |
- name: Build and run update in Arch container | |
if: steps.version-check.outputs.update_needed == 'true' | |
run: | | |
# Build the container with caching | |
docker buildx build \ | |
--load \ | |
--cache-from type=gha \ | |
--cache-to type=gha,mode=max \ | |
-t arch-builder \ | |
-f .github/Dockerfile \ | |
.github | |
# Run the container with workspace mounted | |
docker run --rm \ | |
-v ${{ github.workspace }}:/workspace \ | |
-w /workspace \ | |
arch-builder \ | |
bash -c " | |
chown -R builder:builder /workspace && | |
su - builder -c 'cd /workspace && chmod +x pkg.sh && ./pkg.sh update --ci' | |
" | |
- name: Fix file permissions | |
run: | | |
# Restore ownership to the GitHub Actions user | |
sudo chown -R $(whoami):$(whoami) ${{ github.workspace }} | |
- name: Show changes | |
run: | | |
echo "=== Git status ===" | |
git status | |
echo "=== PKGBUILD changes ===" | |
git diff sourcegraph-amp/PKGBUILD || echo "No PKGBUILD changes" | |
echo "=== .SRCINFO changes ===" | |
git diff sourcegraph-amp/.SRCINFO || echo "No .SRCINFO changes" | |
# Handle updates to existing PRs (renovate, manual PRs) | |
- name: Push updates to existing PR | |
if: github.event_name == 'pull_request' && steps.version-check.outputs.update_needed == 'true' | |
run: git push | |
# Handle scheduled/manual runs - create new PR and auto-merge | |
- name: Create and auto-merge new PR | |
if: github.event_name != 'pull_request' && steps.version-check.outputs.update_needed == 'true' | |
run: | | |
# Create and push branch | |
updated_ver=$(./pkg.sh get-version) | |
BRANCH_NAME="update/amp-$updated_ver" | |
git checkout -b "$BRANCH_NAME" | |
git push origin "$BRANCH_NAME" | |
# Create PR | |
PR_URL=$(gh pr create \ | |
--title "Update @sourcegraph/amp to $updated_ver" \ | |
--body "🤖 **Automated package update** | |
Updates \`@sourcegraph/amp\` to \`$updated_ver\` | |
**Changes:** | |
- Updated \`_npmver\` to \`$updated_ver\` | |
- Reset \`pkgrel\` to \`1\` | |
- Updated checksums | |
- Regenerated \`.SRCINFO\` | |
Auto-generated by GitHub Actions 🚀" \ | |
--head "$BRANCH_NAME") | |
# Extract PR number and merge | |
PR_NUMBER=$(echo "$PR_URL" | grep -o '[0-9]\+$') | |
gh pr merge $PR_NUMBER --rebase --admin | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# Sync to main and publish to AUR after successful update | |
- name: Sync to main branch before publishing | |
if: steps.version-check.outputs.update_needed == 'true' | |
run: | | |
git fetch origin | |
git checkout ${{ github.ref_name }} | |
git reset --hard origin/${{ github.ref_name }} | |
- name: Publish to AUR | |
if: steps.version-check.outputs.update_needed == 'true' | |
uses: ./.github/actions/publish-aur | |
with: | |
aur_ssh_private_key: ${{ secrets.AUR_SSH_PRIVATE_KEY }} | |
package_directory: sourcegraph-amp |