|
| 1 | +name: model_signing benchmarks |
| 2 | +on: |
| 3 | + issue_comment: |
| 4 | + types: [created] |
| 5 | + workflow_dispatch: |
| 6 | + |
| 7 | +permissions: {} |
| 8 | + |
| 9 | +jobs: |
| 10 | + publish-benchmark-container: |
| 11 | + if: ${{ github.event_name == 'workflow_dispatch' }} || ${{ (github.event.issue.pull_request) && (startsWith(github.event.comment.body, '/bench')) }} |
| 12 | + runs-on: [ubuntu-latest] |
| 13 | + permissions: |
| 14 | + packages: write |
| 15 | + outputs: |
| 16 | + head: ${{ steps.config.outputs.head }} |
| 17 | + steps: |
| 18 | + - name: Validate and configure benchmark |
| 19 | + id: config |
| 20 | + env: |
| 21 | + COMMENT_BODY: ${{ github.event.comment.body }} |
| 22 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 23 | + with: |
| 24 | + script: | |
| 25 | + if (context.eventName === 'workflow_dispatch') { |
| 26 | + core.setOutput('head', context.sha) |
| 27 | + return |
| 28 | + } |
| 29 | +
|
| 30 | + const allowedAssociations = ["COLLABORATOR", "MEMBER", "OWNER"]; |
| 31 | + authorAssociation = '${{ github.event.comment.author_association }}' |
| 32 | + if (!allowedAssociations.includes(authorAssociation)) { |
| 33 | + core.setFailed("You don't have access to run the benchmarks"); |
| 34 | + return |
| 35 | + } |
| 36 | +
|
| 37 | + const response = await github.rest.pulls.get({ |
| 38 | + owner: context.repo.owner, |
| 39 | + repo: context.repo.repo, |
| 40 | + pull_number: context.issue.number, |
| 41 | + }) |
| 42 | +
|
| 43 | + // avoid race condition between comment and fetching PR head sha |
| 44 | + const commentTime = new Date('${{ github.event.comment.created_at }}'); |
| 45 | + const prTime = new Date(response.data.head.repo.pushed_at) |
| 46 | + if (prTime >= commentTime) { |
| 47 | + core.setFailed("The PR may have been updated since the benchmark request, " + |
| 48 | + "please review any changes and relaunch if safe."); |
| 49 | + return |
| 50 | + } |
| 51 | +
|
| 52 | + core.setOutput('head', response.data.head.sha) |
| 53 | +
|
| 54 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 55 | + with: |
| 56 | + ref: ${{ steps.config.outputs.head }} |
| 57 | + |
| 58 | + - name: Build Image |
| 59 | + id: build_image |
| 60 | + uses: redhat-actions/buildah-build@7a95fa7ee0f02d552a32753e7414641a04307056 # v2.13 |
| 61 | + with: |
| 62 | + containerfiles: | |
| 63 | + ./benchmarks/Containerfile |
| 64 | + image: ghcr.io/sigstore/model-transparency-benchmarks |
| 65 | + tags: "latest ${{ steps.config.outputs.head }}" |
| 66 | + archs: amd64 |
| 67 | + oci: false |
| 68 | + |
| 69 | + - name: Login to GitHub Container Registry |
| 70 | + uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0 |
| 71 | + id: registry_login |
| 72 | + with: |
| 73 | + registry: ghcr.io |
| 74 | + username: ${{ github.actor }} |
| 75 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 76 | + |
| 77 | + - name: Push To GHCR |
| 78 | + uses: redhat-actions/push-to-registry@5ed88d269cf581ea9ef6dd6806d01562096bee9c # v2.8 |
| 79 | + id: push |
| 80 | + with: |
| 81 | + image: ${{ steps.build_image.outputs.image }} |
| 82 | + tags: ${{ steps.build_image.outputs.tags }} |
| 83 | + registry: ghcr.io |
| 84 | + submit-cloud-batch: |
| 85 | + needs: publish-benchmark-container |
| 86 | + runs-on: ubuntu-latest |
| 87 | + permissions: |
| 88 | + id-token: 'write' |
| 89 | + env: |
| 90 | + TAG: ${{needs.publish-benchmark-container.outputs.head}} |
| 91 | + steps: |
| 92 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 93 | + with: |
| 94 | + ref: ${{needs.publish-benchmark-container.outputs.head}} |
| 95 | + - uses: google-github-actions/auth@ba79af03959ebeac9769e648f473a284504d9193 # v2.1.10 |
| 96 | + with: |
| 97 | + workload_identity_provider: projects/306323169285/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider |
| 98 | + service_account: 'model-transparency-gha@sigstore-infra-playground.iam.gserviceaccount.com' |
| 99 | + - run: | |
| 100 | + gcloud batch jobs submit \ |
| 101 | + --job-prefix=bench \ |
| 102 | + --project sigstore-infra-playground \ |
| 103 | + --location us-central1 \ |
| 104 | + --config - <<EOF |
| 105 | + $(envsubst '$TAG' < benchmarks/cloud_batch.json) |
| 106 | + EOF |
0 commit comments