Use jq to create JSON for GitHub API request #11
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: Deploy to Beta | |
| on: | |
| push: | |
| branches: | |
| - v2.0.0 | |
| concurrency: | |
| group: "deploy-beta" | |
| cancel-in-progress: false | |
| permissions: | |
| contents: read | |
| jobs: | |
| build-and-dispatch: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| artifact-url: ${{ steps.get-artifact.outputs.url }} | |
| zip-name: ${{ steps.set-zip-name.outputs.zip_name }} | |
| steps: | |
| - name: Checkout source repo | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: v2.0.0 | |
| - name: Determine subfolder and zip name | |
| id: set-zip-name | |
| run: | | |
| SUBFOLDER="${{ github.event.repository.name }}" | |
| ZIP_NAME="$(echo "${SUBFOLDER}" | tr '[:upper:]' '[:lower:]')-build.zip" | |
| echo "Subfolder: ${SUBFOLDER}" | |
| echo "Zip name: ${ZIP_NAME}" | |
| echo "subfolder=${SUBFOLDER}" >> "$GITHUB_OUTPUT" | |
| echo "zip_name=${ZIP_NAME}" >> "$GITHUB_OUTPUT" | |
| - name: Use Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| - name: Install dependencies | |
| working-directory: Build | |
| run: npm i | |
| - name: Build | |
| working-directory: Build | |
| run: npm run build | |
| - name: Zip build artifacts | |
| run: | | |
| ZIP_NAME="${{ steps.set-zip-name.outputs.zip_name }}" | |
| echo "Creating zip: ${ZIP_NAME}" | |
| zip -r "${ZIP_NAME}" Build/dist | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ steps.set-zip-name.outputs.zip_name }} | |
| path: ${{ steps.set-zip-name.outputs.zip_name }} | |
| retention-days: 1 | |
| - name: Get artifact download URL | |
| id: get-artifact | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const zipName = process.env.ZIP_NAME; | |
| const { owner, repo } = context.repo; | |
| const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
| owner, | |
| repo, | |
| run_id: context.runId | |
| }); | |
| const artifact = artifacts.data.artifacts.find(a => a.name === zipName); | |
| if (!artifact) { | |
| core.setFailed(`Artifact with name ${zipName} not found`); | |
| return; | |
| } | |
| core.setOutput('url', artifact.archive_download_url); | |
| env: | |
| ZIP_NAME: ${{ steps.set-zip-name.outputs.zip_name }} | |
| - name: Dispatch to beta repo | |
| run: | | |
| set -euo pipefail | |
| BETA_REPO="${{ github.repository_owner }}/beta" | |
| SUBFOLDER="${{ steps.set-zip-name.outputs.subfolder }}" | |
| ARTIFACT_URL="${{ steps.get-artifact.outputs.url }}" | |
| ZIP_NAME="${{ steps.set-zip-name.outputs.zip_name }}" | |
| echo "Dispatching to: ${BETA_REPO}" | |
| echo "With:" | |
| echo " subfolder: ${SUBFOLDER}" | |
| echo " artifact_url: ${ARTIFACT_URL}" | |
| echo " zip_name: ${ZIP_NAME}" | |
| JSON=$(jq -n \ | |
| --arg event_type "deploy-build" \ | |
| --arg source_repo "${{ github.repository }}" \ | |
| --arg artifact_url "$ARTIFACT_URL" \ | |
| --arg token "${{ secrets.GITHUB_TOKEN }}" \ | |
| --arg subfolder "$SUBFOLDER" \ | |
| --arg zip_name "$ZIP_NAME" \ | |
| '{event_type: $event_type, client_payload: {source_repo: $source_repo, artifact_url: $artifact_url, token: $token, subfolder: $subfolder, zip_name: $zip_name}}' \ | |
| ) | |
| curl -X POST \ | |
| -H "Authorization: token ${{ secrets.BETA_PAT_TOKEN }}" \ | |
| -H "Accept: application/vnd.github+json" \ | |
| https://api.github.com/repos/${BETA_REPO}/dispatches \ | |
| -d "$JSON" |