|
| 1 | +name: Trigger Package and Publish |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - "att/**" |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + trigger-type: |
| 10 | + description: "How to trigger the target workflow" |
| 11 | + required: true |
| 12 | + type: choice |
| 13 | + options: |
| 14 | + - api |
| 15 | + - workflow-run |
| 16 | + |
| 17 | +jobs: |
| 18 | + trigger: |
| 19 | + runs-on: concordia-linux-cpu4-ram14gi |
| 20 | + env: |
| 21 | + target_owner: "${{ secrets.TARGET_OWNER }}" |
| 22 | + target_name: "${{ secrets.TARGET_NAME }}" |
| 23 | + target_workflow: "${{ secrets.TARGET_WORKFLOW }}" |
| 24 | + event_type: "${{ secrets.TARGET_EVENT_TYPE }}" |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Checkout Repository |
| 28 | + uses: actions/checkout@v6 |
| 29 | + |
| 30 | + - name: Install DNF Config Manager |
| 31 | + run: | |
| 32 | + sudo dnf -y install 'dnf-command(config-manager)' |
| 33 | +
|
| 34 | + - name: Install GitHub CLI |
| 35 | + run: | |
| 36 | + sudo dnf -y config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo |
| 37 | + sudo dnf -y install gh |
| 38 | +
|
| 39 | + - name: Install gettext (for envsubvst) |
| 40 | + run: | |
| 41 | + sudo dnf -y install gettext |
| 42 | +
|
| 43 | + - name: Install YQ |
| 44 | + run: | |
| 45 | + sudo curl -L -o /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 |
| 46 | + sudo chmod a+x /usr/local/bin/yq |
| 47 | +
|
| 48 | + - name: Authenticate GitHub CLI Using Access Token |
| 49 | + run: | |
| 50 | + echo "${{ secrets.TARGET_REPOSITORY_ACCESS_TOKEN }}" | gh auth login --with-token |
| 51 | + gh auth status |
| 52 | +
|
| 53 | + # Triggering workflows via the API is meant to be used by external systems. |
| 54 | + - name: Trigger Workflow in Target Repository (api) |
| 55 | + if: "${{ github.event.inputs.trigger-type == 'api'}}" |
| 56 | + run: | |
| 57 | + event_data=$(cat <<EOM | yq -o json -I 0 '.' |
| 58 | + event_type: "${{ env.event_type }}" |
| 59 | + client_payload: |
| 60 | + reference: |
| 61 | + name: "${{ github.ref_name }}" |
| 62 | + ref: "${{ github.ref }}" |
| 63 | + type: "${{ github.ref_type }}" |
| 64 | + sha: "${{ github.sha }}" |
| 65 | + repository: |
| 66 | + name: "${{ github.repository }}" |
| 67 | + url: "${{ github.repositoryUrl }}" |
| 68 | + run: |
| 69 | + id: "${{ github.run_id }}" |
| 70 | + iteration: "${{ github.run_number }}" |
| 71 | + workflow: |
| 72 | + name: "${{ github.workflow }}" |
| 73 | + ref: "${{ github.workflow_ref }}" |
| 74 | + sha: "${{ github.workflow_sha }}" |
| 75 | + EOM |
| 76 | + ) |
| 77 | + echo "${event_data}" | \ |
| 78 | + gh api --verbose \ |
| 79 | + -X POST \ |
| 80 | + --input - \ |
| 81 | + /repos/${{ env.target_owner }}/${{ env.target_name }}/dispatches \ |
| 82 | + ; |
| 83 | +
|
| 84 | + # Triggering workflows via workflow execution is preferred when within the GitHub ecosystem. |
| 85 | + - name: Trigger Workflow in Target Repository (workflow run) |
| 86 | + if: "${{ github.event.inputs.trigger-type == 'workflow-run' }}" |
| 87 | + run: | |
| 88 | + gh workflow run \ |
| 89 | + ${{ env.target_workflow }} \ |
| 90 | + --repo ${{ env.target_owner }}/${{ env.target_name }} \ |
| 91 | + --ref 4.22 \ |
| 92 | + --field branch-name=${{ github.ref_name }} \ |
| 93 | + ; |
0 commit comments