Dispatch wgc homebrew bump #2001
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: Dispatch wgc homebrew bump | |
| on: | |
| schedule: | |
| - cron: '0 * * * *' | |
| workflow_dispatch: | |
| permissions: {} | |
| jobs: | |
| dispatch: | |
| name: Dispatch wgc-release if cooldown cleared | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| steps: | |
| - name: Authenticate to homebrew-cosmo | |
| id: app-token | |
| uses: actions/create-github-app-token@v3 | |
| with: | |
| client-id: ${{ secrets.APP_CLIENT_ID }} | |
| private-key: ${{ secrets.APP_PRIVATE_KEY }} | |
| owner: wundergraph | |
| repositories: homebrew-cosmo | |
| permission-contents: write | |
| - name: Check cooldown and dispatch | |
| env: | |
| GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| # Newest x.y.z version past npm's 24h cooldown; the tap backfills older ones. | |
| cutoff=$(date -u -d '24 hours ago' +%Y-%m-%dT%H:%M:%SZ) | |
| target=$(npm view wgc time --json | jq -r --arg cutoff "$cutoff" ' | |
| to_entries | |
| | map(select(.key | test("^[0-9]+\\.[0-9]+\\.[0-9]+$"))) | |
| | map(select((.value | sub("\\.[0-9]+Z$"; "Z")) <= $cutoff)) | |
| | sort_by(.value) | |
| | last.key // empty') | |
| if [ -z "$target" ]; then | |
| echo "No wgc version older than the 24h cooldown yet." | |
| exit 0 | |
| fi | |
| formula=$(curl -fsSL https://raw.githubusercontent.com/wundergraph/homebrew-cosmo/main/Formula/wgc.rb) | |
| tap_version=$(grep -oE 'wgc-[0-9]+\.[0-9]+\.[0-9]+\.tgz' <<< "$formula" | head -n1 | sed -E 's/^wgc-(.*)\.tgz$/\1/') | |
| echo "target=$target tap=$tap_version" | |
| if [ "$target" = "$tap_version" ]; then | |
| echo "Tap already on $target, nothing to do." | |
| exit 0 | |
| fi | |
| echo "Dispatching wgc-release for $target" | |
| jq -nc --arg v "$target" '{event_type:"wgc-release",client_payload:{version:$v}}' \ | |
| | gh api --method POST repos/wundergraph/homebrew-cosmo/dispatches --input - |