publish-shared #19
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: publish-shared | |
| on: | |
| workflow_run: | |
| workflows: | |
| - make-all | |
| types: | |
| - completed | |
| workflow_dispatch: | |
| inputs: | |
| source_sha: | |
| description: Full commit SHA from main to rebuild and redeploy; defaults to current main | |
| required: false | |
| type: string | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: publish-symphony-shared | |
| cancel-in-progress: false | |
| env: | |
| DEPLOYMENT_REPOSITORY: activeviam/shared-infrastructure | |
| jobs: | |
| select-source: | |
| if: >- | |
| ${{ | |
| (github.event_name == 'workflow_run' && | |
| github.event.workflow_run.conclusion == 'success' && | |
| github.event.workflow_run.event == 'push' && | |
| github.event.workflow_run.head_branch == 'main' && | |
| github.event.workflow_run.head_repository.full_name == github.repository) || | |
| (github.event_name == 'workflow_dispatch' && | |
| github.ref == 'refs/heads/main') | |
| }} | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| outputs: | |
| source_sha: ${{ steps.source.outputs.source_sha }} | |
| steps: | |
| - name: Checkout main history | |
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | |
| with: | |
| ref: main | |
| fetch-depth: 0 | |
| - name: Select a tested main commit | |
| id: source | |
| env: | |
| EVENT_NAME: ${{ github.event_name }} | |
| MANUAL_SHA: ${{ inputs.source_sha }} | |
| WORKFLOW_SHA: ${{ github.event.workflow_run.head_sha }} | |
| run: | | |
| set -euo pipefail | |
| git fetch --no-tags origin main | |
| if [[ "$EVENT_NAME" == "workflow_run" ]]; then | |
| candidate="$WORKFLOW_SHA" | |
| elif [[ -n "$MANUAL_SHA" ]]; then | |
| candidate="$MANUAL_SHA" | |
| else | |
| candidate="origin/main" | |
| fi | |
| candidate="$(git rev-parse "${candidate}^{commit}")" | |
| if ! git merge-base --is-ancestor "$candidate" origin/main; then | |
| echo "Refusing to publish a commit that is not in origin/main: $candidate" >&2 | |
| exit 1 | |
| fi | |
| echo "source_sha=$candidate" >> "$GITHUB_OUTPUT" | |
| echo "Selected source commit $candidate" | |
| verify-manual: | |
| if: ${{ github.event_name == 'workflow_dispatch' }} | |
| needs: | |
| - select-source | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| defaults: | |
| run: | |
| working-directory: elixir | |
| steps: | |
| - name: Checkout selected source | |
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | |
| with: | |
| ref: ${{ needs.select-source.outputs.source_sha }} | |
| - name: Set up mise tools | |
| uses: jdx/mise-action@e6a8b3978addb5a52f2b4cd9d91eafa7f0ab959d # v4.2.0 | |
| with: | |
| install: true | |
| cache: true | |
| working_directory: elixir | |
| - name: Cache deps and build | |
| uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | |
| with: | |
| path: | | |
| elixir/deps | |
| elixir/_build | |
| key: ${{ runner.os }}-mix-${{ hashFiles('elixir/mix.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-mix- | |
| - name: Re-run the full source gate | |
| run: make all | |
| dispatch-publish: | |
| if: >- | |
| ${{ | |
| always() && | |
| needs.select-source.result == 'success' && | |
| (needs.verify-manual.result == 'success' || | |
| needs.verify-manual.result == 'skipped') | |
| }} | |
| needs: | |
| - select-source | |
| - verify-manual | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| steps: | |
| - name: Mint dispatcher App token | |
| id: app-token | |
| uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3 | |
| with: | |
| client-id: ${{ vars.SYMPHONY_DEPLOY_CLIENT_ID }} | |
| private-key: ${{ secrets.SYMPHONY_DEPLOY_APP_PRIVATE_KEY }} | |
| owner: activeviam | |
| repositories: shared-infrastructure | |
| - name: Request a private publish | |
| env: | |
| GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
| SOURCE_SHA: ${{ needs.select-source.outputs.source_sha }} | |
| run: | | |
| set -euo pipefail | |
| payload="${RUNNER_TEMP}/symphony-publish.json" | |
| jq --null-input \ | |
| --arg source_sha "$SOURCE_SHA" \ | |
| --arg source_repository "$GITHUB_REPOSITORY" \ | |
| '{ | |
| event_type: "symphony-publish", | |
| client_payload: { | |
| source_sha: $source_sha, | |
| source_repository: $source_repository | |
| } | |
| }' > "$payload" | |
| gh api \ | |
| --method POST \ | |
| "repos/${DEPLOYMENT_REPOSITORY}/dispatches" \ | |
| --input "$payload" | |
| echo "Requested private publish of ${GITHUB_REPOSITORY}@${SOURCE_SHA}" |