Check for CLI updates #212
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: Check for CLI updates | |
| on: | |
| schedule: | |
| - cron: '0 10 * * *' | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| pull-requests: read | |
| jobs: | |
| check-updates: | |
| name: Recover missed stable release dispatches | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| steps: | |
| - name: Checkout docs repository | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # ratchet:actions/checkout@v7.0.1 | |
| - name: Resolve latest stable tower-cli release | |
| id: latest | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| release=$(curl --fail --silent --show-error \ | |
| --header "Authorization: Bearer $GH_TOKEN" \ | |
| --header "X-GitHub-Api-Version: 2022-11-28" \ | |
| https://api.github.com/repos/seqeralabs/tower-cli/releases/latest) | |
| tag_name=$(jq -r '.tag_name // empty' <<< "$release") | |
| release_id=$(jq -r '.id // empty' <<< "$release") | |
| published_at=$(jq -r '.published_at // empty' <<< "$release") | |
| if [ -z "$tag_name" ] || [ -z "$release_id" ]; then | |
| echo "GitHub did not return a published stable release" | |
| exit 1 | |
| fi | |
| branch_ref=$(printf '%s' "$tag_name" | sed -E 's/[^0-9A-Za-z._-]+/-/g') | |
| { | |
| echo "tag_name=$tag_name" | |
| echo "release_id=$release_id" | |
| echo "published_at=$published_at" | |
| echo "branch_ref=$branch_ref" | |
| } >> "$GITHUB_OUTPUT" | |
| - name: Check documented release and open PRs | |
| id: check | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| LATEST_TAG: ${{ steps.latest.outputs.tag_name }} | |
| BRANCH_REF: ${{ steps.latest.outputs.branch_ref }} | |
| run: | | |
| documented_tag=$(jq -r '.tag_name // empty' platform-cli-docs/release.json 2>/dev/null || true) | |
| open_prs=$(curl --fail --silent --show-error \ | |
| --header "Authorization: Bearer $GH_TOKEN" \ | |
| --header "X-GitHub-Api-Version: 2022-11-28" \ | |
| "https://api.github.com/repos/seqeralabs/docs/pulls?state=open&head=seqeralabs:cli-docs-$BRANCH_REF" \ | |
| | jq 'length') | |
| if [ "$documented_tag" = "$LATEST_TAG" ]; then | |
| echo "dispatch=false" >> "$GITHUB_OUTPUT" | |
| echo "$LATEST_TAG is already documented" | |
| elif [ "$open_prs" -gt 0 ]; then | |
| echo "dispatch=false" >> "$GITHUB_OUTPUT" | |
| echo "A documentation PR for $LATEST_TAG is already open" | |
| else | |
| echo "dispatch=true" >> "$GITHUB_OUTPUT" | |
| echo "$LATEST_TAG needs a documentation update" | |
| fi | |
| - name: Build dispatch payload | |
| if: steps.check.outputs.dispatch == 'true' | |
| id: payload | |
| env: | |
| RELEASE_ID: ${{ steps.latest.outputs.release_id }} | |
| TAG_NAME: ${{ steps.latest.outputs.tag_name }} | |
| PUBLISHED_AT: ${{ steps.latest.outputs.published_at }} | |
| run: | | |
| payload=$(jq -cn \ | |
| --arg repository "seqeralabs/tower-cli" \ | |
| --arg release_id "$RELEASE_ID" \ | |
| --arg tag_name "$TAG_NAME" \ | |
| --arg published_at "$PUBLISHED_AT" \ | |
| '{repository: $repository, release_id: $release_id, tag_name: $tag_name, published_at: $published_at}') | |
| echo "json=$payload" >> "$GITHUB_OUTPUT" | |
| - name: Trigger CLI documentation update | |
| if: steps.check.outputs.dispatch == 'true' | |
| uses: peter-evans/repository-dispatch@28959ce8df70de7be546dd1250a005dd32156697 # ratchet:peter-evans/repository-dispatch@v4.0.1 | |
| with: | |
| token: ${{ github.token }} | |
| event-type: cli-release-published | |
| client-payload: ${{ steps.payload.outputs.json }} |