Skip to content

Update APK Repository #30

Update APK Repository

Update APK Repository #30

Workflow file for this run

name: Update APK Repository
on:
workflow_dispatch:
inputs:
project:
description: 'Specific project to update (leave empty for all)'
required: false
type: string
dry_run:
description: 'Dry run (do not create PR)'
required: false
type: boolean
default: false
rebuild:
description: 'Force rebuild all packages (re-download and re-process)'
required: false
type: boolean
default: false
permissions:
contents: write
pull-requests: write
jobs:
generate:
runs-on: ubuntu-latest
container:
image: alpine:latest
steps:
- name: Install dependencies
run: |
apk add --no-cache git python3 py3-pip py3-yaml openssl bash curl abuild
- name: Checkout main branch
uses: actions/checkout@v4
with:
path: main
- name: Checkout gh-pages branch
uses: actions/checkout@v4
with:
ref: gh-pages
path: gh-pages
continue-on-error: true
- name: Initialize gh-pages if not exists
shell: bash
run: |
if [ ! -d "gh-pages/.git" ]; then
mkdir -p gh-pages
cd gh-pages
git init
git checkout -b gh-pages
echo "# APK Repository" > README.md
git add README.md
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git commit -m "Initialize gh-pages branch"
fi
- name: Setup RSA signing key
if: ${{ vars.APK_SIGNING_KEY != '' }}
shell: bash
run: |
echo "${{ secrets.APK_PRIVATE_KEY }}" > /tmp/signing.key
chmod 600 /tmp/signing.key
- name: Generate APK repository
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd main
ARGS="--config projects.yaml --output ../gh-pages"
if [ -n "${{ github.event.inputs.project }}" ]; then
ARGS="$ARGS --project '${{ github.event.inputs.project }}'"
fi
if [ "${{ github.event.inputs.dry_run }}" = "true" ]; then
ARGS="$ARGS --dry-run"
fi
if [ "${{ github.event.inputs.rebuild }}" = "true" ]; then
ARGS="$ARGS --rebuild"
fi
if [ -n "${{ vars.APK_SIGNING_KEY }}" ]; then
ARGS="$ARGS --private-key /tmp/signing.key"
else
ARGS="$ARGS --no-sign"
fi
eval python3 scripts/generate_repo.py $ARGS
- name: Check for changes
if: ${{ github.event.inputs.dry_run != 'true' }}
id: changes
shell: bash
run: |
cd gh-pages
git add -A
if git diff --cached --quiet; then
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "No changes detected"
else
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "Changes detected:"
git diff --cached --name-only
fi
- name: Create Pull Request
if: ${{ github.event.inputs.dry_run != 'true' && steps.changes.outputs.has_changes == 'true' }}
shell: bash
run: |
# Install GitHub CLI
apk add --no-cache github-cli
cd gh-pages
# Configure git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Create unique branch name
BRANCH_NAME="update-repo/${{ github.run_id }}"
git checkout -b "$BRANCH_NAME"
# Commit changes
if [ -n "${{ github.event.inputs.project }}" ]; then
COMMIT_MSG="chore: update ${{ github.event.inputs.project }} packages"
else
COMMIT_MSG="chore: update all packages"
fi
git commit -m "$COMMIT_MSG"
# Push branch
git remote set-url origin "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git"
git push -u origin "$BRANCH_NAME"
# Create PR
cd ../main
if [ -n "${{ github.event.inputs.project }}" ]; then
PR_TITLE="Update APK packages: ${{ github.event.inputs.project }}"
else
PR_TITLE="Update APK packages: all projects"
fi
# Get list of changed files
CHANGED_FILES=$(cd ../gh-pages && git diff --name-only HEAD~1 2>/dev/null || echo "New repository initialization")
# Create PR body
PR_BODY="## Summary
Automated update of APK repository packages.
**Triggered by:** ${{ github.actor }}
**Run ID:** ${{ github.run_id }}
## Changes
\`\`\`
${CHANGED_FILES}
\`\`\`
---
🤖 Generated by GitHub Actions"
gh pr create \
--base gh-pages \
--head "$BRANCH_NAME" \
--title "$PR_TITLE" \
--body "$PR_BODY"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Summary
shell: bash
run: |
if [ "${{ github.event.inputs.dry_run }}" = "true" ]; then
echo "## Dry Run Complete" >> $GITHUB_STEP_SUMMARY
echo "No changes were made." >> $GITHUB_STEP_SUMMARY
elif [ "${{ steps.changes.outputs.has_changes }}" = "true" ]; then
echo "## PR Created" >> $GITHUB_STEP_SUMMARY
echo "A pull request has been created to update the APK repository." >> $GITHUB_STEP_SUMMARY
else
echo "## No Changes" >> $GITHUB_STEP_SUMMARY
echo "No package updates were needed." >> $GITHUB_STEP_SUMMARY
fi