.github/workflows/cd.yml #12
Workflow file for this run
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
| on: | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| jobs: | |
| release: | |
| if: github.ref == 'refs/heads/main' | |
| timeout-minutes: 5 | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| permissions: | |
| contents: write | |
| pages: write | |
| id-token: write | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: cachix/install-nix-action@v31 | |
| with: | |
| github_access_token: ${{ secrets.GITHUB_TOKEN }} | |
| extra_nix_config: | | |
| extra-substituters = https://cache.garnix.io | |
| extra-trusted-public-keys = cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g= | |
| - uses: DeterminateSystems/magic-nix-cache-action@v13 | |
| - run: | | |
| nix develop -c just build | |
| nix develop -c just build-fr | |
| - name: Publish Timestamped Pre-Release | |
| run: | | |
| NOW=$(date -u +"%Y-%m-%dT%H:%M:%SZ") | |
| gh release create "pre-$(date -u +%Y-%m-%dT%H-%M-%S)" *.json \ | |
| --prerelease --title "$NOW" --notes "Automated Pre-Release for $NOW" | |
| - name: Publish Semantically Versionned Release | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| run: | | |
| TAG=${GITHUB_REF#refs/tags/} | |
| gh release create "$TAG" *.json --title "$TAG" --notes "Release $TAG" | |
| - run: | | |
| mkdir --verbose dist/ | |
| mv --verbose exercises*.json dist/ | |
| cp --verbose i18n.json dist/ | |
| - uses: actions/upload-pages-artifact@v4 | |
| with: { path: ./dist } | |
| - uses: actions/deploy-pages@v4 | |
| id: deployment | |
| cleanup: | |
| if: github.ref == 'refs/heads/main' | |
| timeout-minutes: 5 | |
| runs-on: ubuntu-latest | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - run: | # Cleanup rolling releases > 7 days or < 12 hours | |
| gh release list --json tagName,createdAt,isPrerelease \ | |
| --jq '.[]|select(.isPrerelease == true)|"\(.tagName) \(.createdAt)"' \ | |
| | while read -r OLD_TAG CREATED_AT; do | |
| TIMESTAMP=$(date -d "$CREATED_AT" +%s) | |
| if [ "$TIMESTAMP" -lt "$(date -d '7 days ago' +%s)" ] || { | |
| [ "$TIMESTAMP" -gt "$(date -d '12 hours ago' +%s)" ] && | |
| [ "$TIMESTAMP" -lt "$(date -d '10 minutes ago' +%s)" ]; }; then | |
| gh release delete "$OLD_TAG" --yes --cleanup-tag | |
| fi | |
| done | |