Skip to content

Phase 1: Separate generated files to gh-pages branch #77

Phase 1: Separate generated files to gh-pages branch

Phase 1: Separate generated files to gh-pages branch #77

Workflow file for this run

# Main PPA build workflow
# Triggers on PPA updates to build all packages
name: PPA Build (Main)
on:
push:
branches: [main]
paths-ignore:
- "**.md"
- "docs/**"
- ".github/workflows/main.yml"
pull_request:
branches: [main]
paths-ignore:
- "**.md"
- "docs/**"
- ".github/workflows/main.yml"
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
packages: ${{ steps.detect.outputs.packages }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
- name: Detect changed submodules
id: detect
run: |
# Get list of all submodules (as JSON array)
SUBMODULES=$(git submodule status | awk '{print $2}' | grep '^src/diepxuan/' | sed 's|^src/diepxuan/||' | sed 's|/$||' | jq -R -s -c 'split("\n") | map(select(length > 0))')
# For manual trigger, build all
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "packages=$SUBMODULES" >> $GITHUB_OUTPUT
echo "All packages will be built (manual trigger)"
exit 0
fi
# Get base ref
BASE_REF="${{ github.base_ref }}"
if [[ -z "$BASE_REF" ]]; then
BASE_REF="main"
fi
# Get changed files
CHANGES=$(git diff --name-only origin/$BASE_REF...HEAD 2>/dev/null || git diff --name-only HEAD~1...HEAD 2>/dev/null || echo "")
echo "Changes detected: $CHANGES"
# Find which submodules have changes (as JSON array)
CHANGED_PACKAGES="$SUBMODULES"
if [[ -n "$CHANGES" ]]; then
CHANGED_JSON="[]"
for submodule in $(git submodule status | awk '{print $2}' | grep '^src/diepxuan/' | sed 's|^src/diepxuan/||' | sed 's|/$||'); do
if echo "$CHANGES" | grep -q "^src/diepxuan/$submodule/"; then
echo "Package '$submodule' has changes"
CHANGED_JSON=$(echo "$CHANGED_JSON" | jq -c ". + [\"$submodule\"]")
fi
done
CHANGED_PACKAGES="$CHANGED_JSON"
fi
if [[ "$CHANGED_PACKAGES" == "[]" ]]; then
echo "No package changes detected"
echo "packages=[]" >> $GITHUB_OUTPUT
else
echo "packages=$CHANGED_PACKAGES" >> $GITHUB_OUTPUT
echo "Will build: $CHANGED_PACKAGES"
fi
package-build:
needs: detect-changes
if: needs.detect-changes.outputs.packages != ''
permissions:
contents: write
strategy:
max-parallel: 1 # Chỉ chạy 1 matrix job tại 1 thời điểm
fail-fast: false
matrix:
package: ${{ fromJson(needs.detect-changes.outputs.packages) }}
uses: diepxuan/.github/.github/workflows/debian-package-ppa.yml@main
with:
module: ${{ matrix.package }}
secrets:
GPG_KEY: ${{ secrets.GPG_KEY }}
GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }}
GIT_COMMITTER_EMAIL: ${{ secrets.GIT_COMMITTER_EMAIL }}
SSH_ID_RSA: ${{ secrets.SSH_ID_RSA }}
sync-gh-pages:
needs: package-build
if: success()
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout main (generated files)
uses: actions/checkout@v4
with:
ref: main
path: main-worktree
fetch-depth: 1
- name: Checkout gh-pages
uses: actions/checkout@v4
with:
ref: gh-pages
path: gh-pages-worktree
fetch-depth: 1
- name: Sync generated files to gh-pages
run: |
cd gh-pages-worktree
git config user.name "DiepXuan CI"
git config user.email "ci@diepxuan.com"
# Remove old generated files
rm -rf dists pool db lists key.gpg Release.gpg keyrings
# Copy new generated files from main
cp -r ../main-worktree/dists ./dists
cp -r ../main-worktree/pool ./pool
cp -r ../main-worktree/db ./db
cp -r ../main-worktree/lists ./lists
cp ../main-worktree/key.gpg ./key.gpg
cp ../main-worktree/Release.gpg ./Release.gpg
if [ -d ../main-worktree/keyrings ]; then
cp -r ../main-worktree/keyrings ./keyrings
fi
# Commit and push
git add -A
if ! git diff --cached --quiet; then
git commit -m "ci: sync generated files from main@${{ github.sha }}"
git push origin gh-pages
else
echo "No changes to sync"
fi