Automated PIF Profile Generator #6
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: Automated PIF Profile Generator | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: '0 2 * * *' | |
| concurrency: | |
| group: pif-generator-${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: false | |
| jobs: | |
| test: | |
| name: Run Unit Tests | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| cache: 'pip' | |
| - name: Install package and test dependencies | |
| run: | | |
| pip install -e . | |
| pip install pytest | |
| - name: Run tests | |
| run: | | |
| pytest tests/ | |
| check-upstream: | |
| name: Check Upstream Releases | |
| needs: test | |
| runs-on: ubuntu-latest | |
| outputs: | |
| new_release: ${{ steps.check.outputs.new_release }} | |
| results: ${{ steps.check.outputs.results }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| cache: 'pip' | |
| - name: Install package | |
| run: | | |
| pip install -e . | |
| - name: Query upstream updates | |
| id: check | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| pif-gen check --state-dir state | |
| build-profiles: | |
| name: Extract and Build Profiles | |
| needs: check-upstream | |
| if: needs.check-upstream.outputs.new_release == 'true' | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 120 | |
| strategy: | |
| matrix: | |
| release: ${{ fromJson(needs.check-upstream.outputs.results) }} | |
| fail-fast: false | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| cache: 'pip' | |
| - name: Install package | |
| run: | | |
| pip install -e . | |
| - name: Generate JSON profiles | |
| run: | | |
| pif-gen build \ | |
| --channel "${{ matrix.release.channel }}" \ | |
| --assets-json '${{ toJson(matrix.release.assets) }}' \ | |
| --output-dir output \ | |
| --manifest output/manifest_${{ matrix.release.channel }}.txt | |
| - name: Validate generated JSON files | |
| run: | | |
| for file in output/*.json; do | |
| [ -e "$file" ] || continue | |
| python -m json.tool "$file" > /dev/null | |
| done | |
| - name: Save upstream tag info | |
| run: | | |
| mkdir -p state | |
| echo "${{ matrix.release.tag }}" > "state/last_${{ matrix.release.channel }}_tag.txt" | |
| - name: Upload channel output | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: channel-${{ matrix.release.channel }} | |
| path: output/*.json | |
| retention-days: 1 | |
| - name: Upload state tracker | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: state-${{ matrix.release.channel }} | |
| path: state/last_${{ matrix.release.channel }}_tag.txt | |
| retention-days: 1 | |
| publish-release: | |
| name: Publish Unified Release | |
| needs: build-profiles | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| cache: 'pip' | |
| - name: Install package | |
| run: | | |
| pip install -e . | |
| - name: Download all build artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: channel-* | |
| path: combined/ | |
| - name: Consolidate profiles and state | |
| run: | | |
| mkdir -p final_output state | |
| find combined/ -type f -name "*.json" -exec cp -v {} final_output/ \; | |
| find combined/ -type f -name "last_*_tag.txt" -exec cp -v {} state/ \; | |
| ls -1 final_output/*.json > final_output/manifest.txt | |
| echo "Total consolidated JSON files: $(wc -l < final_output/manifest.txt)" | |
| - name: Publish GitHub Release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| pif-gen publish \ | |
| --repo "${{ github.repository }}" \ | |
| --manifest final_output/manifest.txt | |
| - name: Update tracker state in git | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add state/last_*_tag.txt | |
| if ! git diff --staged --quiet; then | |
| git commit -m "chore(tracker): update release tag state" | |
| for i in {1..5}; do | |
| git pull --rebase origin main && git push origin main && break || sleep 2 | |
| done | |
| fi | |
| - name: Upload release bundle artifact | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: pif-profiles-unified-bundle | |
| path: final_output/ | |
| retention-days: 30 |