Build Version Cache #63
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: Build Version Cache | |
| on: | |
| # You can manually run this workflow. | |
| workflow_dispatch: | |
| # This workflow is triggered when all of the following workflows are completed: | |
| workflow_run: | |
| workflows: ["Build on Windows: Mesa Lavapipe", "Build on Windows: Swiftshader"] | |
| types: [completed] | |
| jobs: | |
| update-version-cache: | |
| runs-on: ubuntu-latest | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v6 | |
| - name: Get releases | |
| run: | | |
| gh api repos/${{ github.repository }}/releases --paginate | jq '[ | |
| .[] | { | |
| tag: .tag_name, | |
| assets: [.assets[] | { | |
| name: .name, | |
| version: ( .name | capture("(?<version>[0-9]+\\.[0-9]+\\.[0-9]+(?:\\.[0-9]+)?)").version), | |
| url: .browser_download_url | |
| }] | |
| } | |
| ]' > releases.json | |
| cat releases.json | |
| - name: Generate versions_list.json | |
| run: | | |
| jq 'reduce .[] as $release ({}; | |
| reduce $release.assets[] as $asset (.; | |
| ($asset.name | capture("^(?<base>.+)-(?<version>[0-9]+\\.[0-9]+\\.[0-9]+(?:\\.[0-9]+)?)")) as $captured | | |
| .[$captured.base] += [{ | |
| "version": $captured.version, | |
| "tag": $release.tag, | |
| "url": $asset.url | |
| }] | |
| ) | |
| )' releases.json > version_list.json | |
| cat version_list.json | |
| - name: Add "latest" and "by_version" fields | |
| run: | | |
| jq '{ | |
| latest: with_entries({ | |
| key: .key, | |
| value: (.value | max_by([(.version | split(".") | map(tonumber)), (.tag | tonumber)])) | |
| }), | |
| by_version: with_entries({ | |
| key: .key, | |
| value: (reduce .value[] as $item ({}; . + { | |
| ($item.version): ( | |
| .[$item.version] // [] | . + [{ | |
| tag: $item.tag, | |
| url: $item.url | |
| }] | |
| ) | |
| })) | |
| }) | |
| }' version_list.json > versions.json | |
| cat versions.json | |
| - name: Upload `versions.json` | |
| run: | | |
| LATEST_TAG=$(gh api repos/${{ github.repository }}/releases/latest --jq .tag_name) | |
| gh release upload $LATEST_TAG versions.json --repo ${{ github.repository }} --clobber | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |