Merge pull request #261 from Cognipeer/fix/github-app-dispatch-write #33
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
| name: Console Community Build | |
| on: | |
| push: | |
| tags: | |
| - 'v[0-9]+.[0-9]+.[0-9]+-community' | |
| permissions: | |
| contents: read | |
| packages: write | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| image_digest: ${{ steps.image.outputs.digest }} | |
| commit_sha: ${{ steps.vars.outputs.commit_sha }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Login to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build & Push to GHCR | |
| id: image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| tags: ghcr.io/cognipeer/console:${{ github.ref_name }} | |
| - name: Capture release identity | |
| id: vars | |
| if: always() | |
| run: echo "commit_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" | |
| sync-console-ee: | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Create release automation token | |
| id: app-token | |
| uses: actions/create-github-app-token@v2 | |
| with: | |
| app-id: ${{ secrets.RELEASE_AUTOMATION_APP_ID }} | |
| private-key: ${{ secrets.RELEASE_AUTOMATION_PRIVATE_KEY }} | |
| owner: Cognipeer | |
| repositories: console-ee | |
| permission-contents: write | |
| permission-metadata: read | |
| - name: Update Console Enterprise compatibility pin | |
| env: | |
| DISPATCH_TOKEN: ${{ steps.app-token.outputs.token }} | |
| COMMUNITY_TAG: ${{ github.ref_name }} | |
| COMMUNITY_SHA: ${{ needs.build.outputs.commit_sha }} | |
| run: | | |
| set -euo pipefail | |
| if [[ -z "${DISPATCH_TOKEN}" ]]; then | |
| echo "::error::GitHub release automation App token is not available." | |
| exit 1 | |
| fi | |
| SEAM_CONTRACT_VERSION=$(grep -oE 'SEAM_CONTRACT_VERSION = [0-9]+' \ | |
| src/enterprise/registry.ts | grep -oE '[0-9]+$') | |
| if [[ -z "${SEAM_CONTRACT_VERSION}" ]]; then | |
| echo "::error::Community registry does not declare SEAM_CONTRACT_VERSION." | |
| exit 1 | |
| fi | |
| PAYLOAD=$(jq -n \ | |
| --arg tag "${COMMUNITY_TAG}" \ | |
| --arg sha "${COMMUNITY_SHA}" \ | |
| --arg repository "${GITHUB_REPOSITORY}" \ | |
| --argjson seamContractVersion "${SEAM_CONTRACT_VERSION}" \ | |
| '{ | |
| event_type: "community-released", | |
| client_payload: { | |
| tag: $tag, | |
| sha: $sha, | |
| repository: $repository, | |
| seamContractVersion: $seamContractVersion | |
| } | |
| }') | |
| curl --fail-with-body --silent --show-error \ | |
| --request POST \ | |
| --header "Authorization: Bearer ${DISPATCH_TOKEN}" \ | |
| --header "Accept: application/vnd.github+json" \ | |
| --header "X-GitHub-Api-Version: 2022-11-28" \ | |
| --data "${PAYLOAD}" \ | |
| https://api.github.com/repos/Cognipeer/console-ee/dispatches | |
| notify-crm: | |
| if: always() && needs.build.result != 'skipped' | |
| environment: production | |
| runs-on: ubuntu-latest | |
| needs: [build, sync-console-ee] | |
| steps: | |
| - name: Report community artifact to CRM | |
| env: | |
| WEBHOOK_URL: ${{ secrets.RELEASE_WEBHOOK_URL }} | |
| WEBHOOK_SECRET: ${{ secrets.RELEASE_WEBHOOK_SECRET }} | |
| BUILD_RESULT: ${{ needs.build.result }} | |
| COMPAT_SYNC_RESULT: ${{ needs.sync-console-ee.result }} | |
| CRM_ENVIRONMENT: artifacts | |
| COMMIT_SHA: ${{ needs.build.outputs.commit_sha || github.sha }} | |
| IMAGE_DIGEST: ${{ needs.build.outputs.image_digest }} | |
| VERSION: ${{ github.ref_name }} | |
| IMAGE_REF: ghcr.io/cognipeer/console:${{ github.ref_name }} | |
| RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
| run: | | |
| set -euo pipefail | |
| if [[ -z "${WEBHOOK_URL}" || -z "${WEBHOOK_SECRET}" ]]; then | |
| echo "::error::RELEASE_WEBHOOK_URL / RELEASE_WEBHOOK_SECRET are required." | |
| exit 1 | |
| fi | |
| STATUS="succeeded" | |
| if [[ "${BUILD_RESULT}" != "success" || "${COMPAT_SYNC_RESULT}" != "success" ]]; then | |
| STATUS="failed" | |
| fi | |
| IMMUTABLE_REF="" | |
| if [[ -n "${IMAGE_DIGEST}" ]]; then | |
| IMMUTABLE_REF="ghcr.io/cognipeer/console@${IMAGE_DIGEST}" | |
| fi | |
| PAYLOAD_FILE="$(mktemp)" | |
| trap 'rm -f "${PAYLOAD_FILE}"' EXIT | |
| jq -n \ | |
| --arg product "console" \ | |
| --arg repo "${GITHUB_REPOSITORY}" \ | |
| --arg targetKey "community" \ | |
| --arg environment "${CRM_ENVIRONMENT}" \ | |
| --arg version "${VERSION}" \ | |
| --arg commitSha "${COMMIT_SHA}" \ | |
| --arg imageRef "${IMAGE_REF}" \ | |
| --arg immutableRef "${IMMUTABLE_REF}" \ | |
| --arg status "${STATUS}" \ | |
| --arg actor "${GITHUB_ACTOR}" \ | |
| --arg runUrl "${RUN_URL}" \ | |
| '{ | |
| product: $product, | |
| repo: $repo, | |
| targetKey: $targetKey, | |
| environment: $environment, | |
| version: $version, | |
| commitSha: $commitSha, | |
| imageRef: $imageRef, | |
| immutableRef: (if $immutableRef == "" then null else $immutableRef end), | |
| status: $status, | |
| actor: $actor, | |
| runUrl: $runUrl | |
| }' > "${PAYLOAD_FILE}" | |
| SIGNATURE="$(openssl dgst -sha256 -hmac "${WEBHOOK_SECRET}" -hex "${PAYLOAD_FILE}" | sed 's/^.* //')" | |
| curl --retry 3 --retry-delay 2 --retry-max-time 30 \ | |
| --fail-with-body --silent --show-error \ | |
| --request POST "${WEBHOOK_URL}" \ | |
| --header "Content-Type: application/json" \ | |
| --header "X-Cognipeer-Signature: sha256=${SIGNATURE}" \ | |
| --data-binary "@${PAYLOAD_FILE}" |