|
| 1 | +# ================================================================================================== |
| 2 | +# Aspect Workflows Reusable Workflow for GitHub Actions (v5.12.0-alpha0.dev.68.g41b1e2f) |
| 3 | +# |
| 4 | +# https://github.com/marketplace/actions/aspect-workflows?version=5.12.0-alpha0.dev.68.g41b1e2f |
| 5 | +# |
| 6 | +# At this time, GitHub Actions does not allow referencing reusable workflows from public |
| 7 | +# repositories in other organizations. See |
| 8 | +# https://docs.github.com/en/actions/using-workflows/reusing-workflows#access-to-reusable-workflows |
| 9 | +# for more info. |
| 10 | +# |
| 11 | +# Use the Aspect Workflows Reusable Workflow with GitHub Actions by doing one of the following: |
| 12 | +# |
| 13 | +# 1. Vendor this file into the `.github/workflows` folder of your repository and reference it with |
| 14 | +# `uses:` in a workflow file such as `.github/workflows/aspect-workflows.yaml`: |
| 15 | +# |
| 16 | +# ``` |
| 17 | +# name: Aspect Workflows |
| 18 | +# |
| 19 | +# on: |
| 20 | +# push: |
| 21 | +# branches: [main] |
| 22 | +# pull_request: |
| 23 | +# branches: [main] |
| 24 | +# workflow_dispatch: |
| 25 | +# |
| 26 | +# jobs: |
| 27 | +# aspect-workflows: |
| 28 | +# name: Aspect Workflows |
| 29 | +# uses: ./.github/workflows/.aspect-workflows-reusable.yaml |
| 30 | +# ``` |
| 31 | +# |
| 32 | +# 2. Create a fork of https://github.com/aspect-build/workflows-action in your |
| 33 | +# GitHub org and change the `uses` line above to reference the reusable work |
| 34 | +# from your fork: |
| 35 | +# |
| 36 | +# ``` |
| 37 | +# jobs: |
| 38 | +# aspect-workflows: |
| 39 | +# name: Aspect Workflows |
| 40 | +# uses: my-github-org/workflows-action/.github/workflows/.aspect-workflows-reusable.yaml@5.12.0-alpha0.dev.68.g41b1e2f |
| 41 | +# ``` |
| 42 | +# ================================================================================================== |
| 43 | +name: Aspect Workflows Reusable Workflow (v5.12.0-alpha0.dev.68.g41b1e2f) |
| 44 | +on: |
| 45 | + # Makes this workflow reusable, see |
| 46 | + # https://github.blog/2022-02-10-using-reusable-workflows-github-actions |
| 47 | + workflow_call: |
| 48 | + inputs: |
| 49 | + aspect-config: |
| 50 | + description: Path to the Aspect Workflows config.yaml file |
| 51 | + type: string |
| 52 | + default: .aspect/workflows/config.yaml |
| 53 | + delivery-workflow: |
| 54 | + description: The name of the file which contains the delivery workflow |
| 55 | + type: string |
| 56 | + default: aspect-workflows-delivery.yaml |
| 57 | + queue: |
| 58 | + description: The queue / runner pool that the setup step will run on |
| 59 | + type: string |
| 60 | + default: aspect-default |
| 61 | + slack_webhook_url: |
| 62 | + description: 'If set, then a webhook notification will be sent for failing builds on a release branch. Input should match the name of a secret. "secrets: inherit" must also be set' |
| 63 | + type: string |
| 64 | + inherited_secrets: |
| 65 | + description: 'Comma separated list of secrets or regex (Oniguruma) describing secrets to be made available during the build. "secrets: inherit" must also be set. The regex is used by jq internally which uses the Oniguruma regular expression library: https://jqlang.github.io/jq/manual/' |
| 66 | + type: string |
| 67 | +jobs: |
| 68 | + setup: |
| 69 | + runs-on: [self-hosted, aspect-workflows, "${{ inputs.queue }}"] |
| 70 | + steps: |
| 71 | + - uses: actions/checkout@v4 |
| 72 | + - id: rosetta-generate |
| 73 | + run: | |
| 74 | + ROSETTA_RESULT=$( \ |
| 75 | + rosetta steps \ |
| 76 | + --config ${{ inputs.aspect-config }} \ |
| 77 | + --gha_task generate \ |
| 78 | + --gha_json_pretty_print=false \ |
| 79 | + ) |
| 80 | + tee "${GITHUB_OUTPUT}" <<< "json=${ROSETTA_RESULT}" |
| 81 | + outputs: |
| 82 | + cfg: ${{ steps.rosetta-generate.outputs.json }} |
| 83 | + bazel: |
| 84 | + needs: [setup] |
| 85 | + runs-on: ${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].labels }} |
| 86 | + strategy: |
| 87 | + fail-fast: false |
| 88 | + matrix: ${{ fromJson(needs.setup.outputs.cfg).matrix_config }} |
| 89 | + env: |
| 90 | + ASPECT_WORKFLOWS_CONFIG: ${{ inputs.aspect-config }} |
| 91 | + steps: |
| 92 | + - name: Workflows environment |
| 93 | + run: ${{ fromJson(needs.setup.outputs.cfg).platform.directories.WORKFLOWS_BIN_DIR }}/configure_workflows_env |
| 94 | + - name: Clone repo |
| 95 | + uses: actions/checkout@v4 |
| 96 | + with: |
| 97 | + fetch-depth: ${{ !endsWith(matrix.job, 'lint') && 1 || 2 }} |
| 98 | + - name: Agent health check |
| 99 | + # Set RUNNER_TRACKER_ID="" to prevent GitHub Actions from killing the Bazel server started |
| 100 | + # during health check when "Cleaning up orphan processes" in the "Complete job" step. |
| 101 | + # See https://github.com/actions/runner/issues/598. |
| 102 | + run: RUNNER_TRACKING_ID="" && ${{ fromJson(needs.setup.outputs.cfg).platform.directories.WORKFLOWS_BIN_DIR }}/agent_health_check |
| 103 | + timeout-minutes: ${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].health_check_timeout }} |
| 104 | + - name: Process secrets |
| 105 | + id: process_secrets |
| 106 | + if: inputs.inherited_secrets != '' |
| 107 | + run: | |
| 108 | + REQUIRED_SECRETS=$(${{ fromJson(needs.setup.outputs.cfg).platform.directories.WORKFLOWS_BIN_DIR }}/jq -R --compact-output 'gsub("\\s+";"";"g") | split(",")' <<< "${{ inputs.inherited_secrets }}") |
| 109 | + FILTERED_SECRETS=$(${{ fromJson(needs.setup.outputs.cfg).platform.directories.WORKFLOWS_BIN_DIR }}/jq --compact-output --argjson secrets "${REQUIRED_SECRETS}" 'with_entries( select (.key | test($secrets[]) ) )' <<< '''${{ toJson(secrets) }}''' ) |
| 110 | + echo "filtered_secrets=${FILTERED_SECRETS}" | tee ${GITHUB_OUTPUT} |
| 111 | + - name: Prepare archive directories |
| 112 | + run: rm -rf ${{ join(fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].artifact_paths, ' ') }} |
| 113 | + - name: Determine changed files |
| 114 | + uses: tj-actions/changed-files@v42 |
| 115 | + if: endsWith(matrix.job, 'format') |
| 116 | + with: |
| 117 | + json: true |
| 118 | + write_output_files: true |
| 119 | + output_dir: ${{ fromJson(needs.setup.outputs.cfg).platform.directories.ARTIFACTS_DIR }} |
| 120 | + - name: Checkout health |
| 121 | + uses: aspect-build/workflows-action@5.12.0-alpha0.dev.68.g41b1e2f |
| 122 | + timeout-minutes: ${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].checkout_task_timeout }} |
| 123 | + if: fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].has_checkout_task |
| 124 | + with: |
| 125 | + workspace: ${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].workspace }} |
| 126 | + task: checkout |
| 127 | + - name: ${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].name }} |
| 128 | + uses: aspect-build/workflows-action@5.12.0-alpha0.dev.68.g41b1e2f |
| 129 | + env: ${{ inputs.inherited_secrets != '' && fromJson(steps.process_secrets.outputs.filtered_secrets) || fromJson('{}') }} |
| 130 | + timeout-minutes: ${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].timeout_in_minutes }} |
| 131 | + with: |
| 132 | + workspace: ${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].workspace }} |
| 133 | + task: ${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].task }} |
| 134 | + - name: Send notification to Slack |
| 135 | + id: slack |
| 136 | + # oncall cares about branches that do delivery, so key this on whether we produce a delivery manifest |
| 137 | + if: inputs.slack_webhook_url != '' && failure() && fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].generate_manifest |
| 138 | + uses: slackapi/slack-github-action@v1.27.0 |
| 139 | + with: |
| 140 | + payload: | |
| 141 | + { |
| 142 | + "gha_url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
| 143 | + } |
| 144 | + env: |
| 145 | + SLACK_WEBHOOK_URL: ${{ secrets[inputs.slack_webhook_url] }} |
| 146 | + - name: Delivery manifest |
| 147 | + if: fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].generate_manifest |
| 148 | + uses: aspect-build/workflows-action@5.12.0-alpha0.dev.68.g41b1e2f |
| 149 | + timeout-minutes: ${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].delivery_manifest_timeout }} |
| 150 | + with: |
| 151 | + workspace: ${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].workspace }} |
| 152 | + task: delivery_manifest |
| 153 | + args: "--data TARGETS_SOURCE=${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].task }}" |
| 154 | + # Upload all artifacts for the workspace |
| 155 | + - name: Upload artifacts |
| 156 | + # The `always()` condition makes this step run even if a previous step failed. |
| 157 | + # Setting `continue-on-error: true` on previous steps isn't ideal as the UI |
| 158 | + # will flag them as having passed even if they failed. |
| 159 | + if: ${{ always() }} |
| 160 | + uses: actions/upload-artifact@v4 |
| 161 | + with: |
| 162 | + name: ${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].artifact_prefix }}${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].task }}.artifacts |
| 163 | + path: ${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].artifact_upload_pattern }} |
| 164 | + overwrite: true |
| 165 | + # Codecov |
| 166 | + - name: Codecov upload |
| 167 | + # The `always()` condition makes this step run even if a previous step failed. |
| 168 | + # Setting `continue-on-error: true` on previous steps isn't ideal as the UI |
| 169 | + # will flag them as having passed even if they failed. |
| 170 | + if: ${{ always() && fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].codecov_upload }} |
| 171 | + # https://github.com/marketplace/actions/codecov |
| 172 | + uses: codecov/codecov-action@v4 |
| 173 | + with: |
| 174 | + files: bazel-out/_coverage/_coverage_report.dat |
| 175 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 176 | + functionalities: search # Disable searching for coverage reports. If enabled, it gets confused |
| 177 | + # by the bazel convenience symlinks and finds the same coverage report |
| 178 | + # under bazel-out and {workspace}/bazel-out. |
| 179 | + - name: Trigger delivery |
| 180 | + # This uses the following API: https://docs.github.com/en/rest/actions/workflows?apiVersion=2022-11-28#create-a-workflow-dispatch-event |
| 181 | + run: | |
| 182 | + curl \ |
| 183 | + -X POST \ |
| 184 | + -H "Accept: application/vnd.github.v3+json" \ |
| 185 | + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ |
| 186 | + https://api.github.com/repos/${{ github.repository }}/actions/workflows/${{ inputs.delivery-workflow }}/dispatches \ |
| 187 | + -d "{\"ref\":\"${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].branch }}\",\"inputs\":{\"delivery_commit\":\"${GITHUB_SHA}\",\"workspace\":\"${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].workspace }}\"}}" |
| 188 | + shell: bash |
| 189 | + if: fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].delivery |
0 commit comments