-
Notifications
You must be signed in to change notification settings - Fork 0
feat(ci): add build provenance attestation #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e159819
226d0b6
8e591bd
5276ac4
051287e
2796c12
59cec53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,24 +13,34 @@ on: | |
| commit: | ||
| description: "Git commit hash" | ||
| required: true | ||
| branch: | ||
| description: "Git branch" | ||
| required: true | ||
| directory: | ||
| description: "Directory to deploy" | ||
| required: false | ||
| default: "." | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| notify: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: ${{github.event.inputs.appId}} | ||
| run: echo run identifier ${{ github.run_id }} | ||
|
|
||
| deploy: | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| worker-script: ${{ steps.get-script.outputs.worker-script-filename }} | ||
|
|
||
| env: | ||
| wranglerVersion: "3.68.0" | ||
| outDir: "codius-dist" | ||
|
|
||
| steps: | ||
| - name: ${{github.event.inputs.appId}} | ||
| run: echo run identifier ${{ github.run_id }} | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
|
|
@@ -44,7 +54,7 @@ jobs: | |
| file_path="${directory:+${directory}/}pnpm-lock.yaml" | ||
| if [ -f "$file_path" ]; then | ||
| echo "PNPM lock file found" | ||
| echo "::set-output name=setup_pnpm::true" | ||
| echo "setup_pnpm=true" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
|
||
| - name: Setup Node.js | ||
|
|
@@ -71,8 +81,8 @@ jobs: | |
| id: check-custom-build | ||
| working-directory: ${{ github.event.inputs.directory }} | ||
| run: | | ||
| CUSTOM_BUILD=$(docker run -i ghcr.io/pelletier/go-toml:v2 tomljson < wrangler.toml | jq -e '.build' > /dev/null && echo "true" || echo "false") | ||
| echo "CUSTOM_BUILD=${CUSTOM_BUILD}" >> "$GITHUB_OUTPUT" | ||
| custom_build=$(docker run -i ghcr.io/pelletier/go-toml:v2 tomljson < wrangler.toml | jq -e '.build' > /dev/null && echo "true" || echo "false") | ||
| echo "custom-build=${custom_build}" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Bundle/Build Worker | ||
| uses: cloudflare/wrangler-action@v3 | ||
|
|
@@ -81,7 +91,7 @@ jobs: | |
| workingDirectory: ${{ github.event.inputs.directory }} | ||
| command: deploy --dry-run ${{ env.OUT_DIR }} --name=${{ github.event.inputs.appId }} --dispatch-namespace ${{ github.event.inputs.dispatchNamespace }} | ||
| env: | ||
| OUT_DIR: ${{ steps.check-custom-build.outputs.CUSTOM_BUILD == 'false' && format('--outdir={0}', env.outDir) || '' }} | ||
| OUT_DIR: ${{ steps.check-custom-build.outputs.custom-build == 'false' && format('--outdir={0}', env.outDir) || '' }} | ||
|
|
||
| - name: Determine worker entry script | ||
| id: get-script | ||
|
|
@@ -90,7 +100,7 @@ jobs: | |
| wrangler_main=$(docker run -i ghcr.io/pelletier/go-toml:v2 tomljson < wrangler.toml | jq -r '.main') | ||
| echo "wrangler_main: $wrangler_main" | ||
|
|
||
| if [ "${{ steps.check-custom-build.outputs.CUSTOM_BUILD }}" == "false" ]; then | ||
| if [ "${{ steps.check-custom-build.outputs.custom-build }}" == "false" ]; then | ||
| trimmed_wrangler_main=$(echo ${wrangler_main} | sed 's|^\./||') | ||
| echo "Custom build is false; looking for the bundled script in ${outDir} containing // ${trimmed_wrangler_main}" | ||
| worker_script=$(grep -rl "// ${trimmed_wrangler_main}" "${{ env.outDir }}" | head -n 1) | ||
|
|
@@ -101,11 +111,17 @@ jobs: | |
| fi | ||
|
|
||
| if [ -z "$worker_script" ]; then | ||
| echo "Error: WORKER_SCRIPT is empty!" | ||
| echo "Error: Unable to find worker script!" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "WORKER_SCRIPT=${worker_script}" >> "$GITHUB_OUTPUT" | ||
| echo "worker-script=${worker_script}" >> "$GITHUB_OUTPUT" | ||
| echo "worker-script-filename=$(basename $worker_script)" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: ${{ github.event.inputs.appId }} | ||
| path: ${{ github.event.inputs.directory }}/${{ steps.get-script.outputs.worker-script }} | ||
|
|
||
| - name: Deploy Worker | ||
| uses: cloudflare/wrangler-action@v3 | ||
|
|
@@ -114,4 +130,36 @@ jobs: | |
| accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | ||
| wranglerVersion: ${{ env.wranglerVersion }} | ||
| workingDirectory: ${{ github.event.inputs.directory }} | ||
| command: deploy --no-bundle --name=${{ github.event.inputs.appId }} --dispatch-namespace ${{ github.event.inputs.dispatchNamespace }} ${{ steps.get-script.outputs.WORKER_SCRIPT }} | ||
| command: deploy --no-bundle --name=${{ github.event.inputs.appId }} --dispatch-namespace ${{ github.event.inputs.dispatchNamespace }} ${{ steps.get-script.outputs.worker-script }} | ||
|
|
||
| attest: | ||
| needs: deploy | ||
| runs-on: ubuntu-latest | ||
|
|
||
| permissions: | ||
| id-token: write | ||
| attestations: write | ||
|
|
||
| steps: | ||
| - name: Download worker script | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: ${{ github.event.inputs.appId }} | ||
|
|
||
| - uses: actions/attest-build-provenance/predicate@d58ddf9f241cd8163408934540d01c3335864d64 # predicate@1.1.2 | ||
| id: generate-build-provenance-predicate | ||
|
|
||
| - name: Update Predicate JSON | ||
| id: update-predicate | ||
| run: | | ||
| uri="git+https://github.com/${{ github.event.inputs.repo }}@refs/heads/${{ github.event.inputs.branch }}" | ||
| resolved_dependencies=$(jq -n --arg uri "$uri" --arg commit "${{ github.event.inputs.commit }}" --arg path "${{ github.event.inputs.directory }}" '[{"uri": $uri, "digest": {"gitCommit": $commit}, "path": $path}]') | ||
| predicate=$(echo '${{ steps.generate-build-provenance-predicate.outputs.predicate }}' | jq -c '.buildDefinition.externalParameters.resolvedDependencies = $resolved_dependencies' --argjson resolved_dependencies "$resolved_dependencies") | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Overriding the existing which appears to originate in Specifying the worker's repo in an added It can be found by parsing the attestation file: |
||
| echo "predicate=$predicate" >> $GITHUB_OUTPUT | ||
|
|
||
| - uses: actions/attest@2da0b136720d14f01f4dbeeafd1d5a4d76cbe21d # v1.4.0 | ||
| id: attest | ||
| with: | ||
| subject-path: ${{ needs.deploy.outputs.worker-script }} | ||
| predicate-type: ${{ steps.generate-build-provenance-predicate.outputs.predicate-type }} | ||
| predicate: ${{ steps.update-predicate.outputs.predicate }} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| CREATE INDEX `idx_apps_github_workflow_run_id` ON `apps` (`github_workflow_run_id`);--> statement-breakpoint | ||
| ALTER TABLE `apps` DROP COLUMN `github_workflow_job_id`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making this a separate job creates a second set of webhook events
codius-workers/packages/codius-astro/src/pages/webhooks/github/workflow-job.ts
Line 11 in 84c9cd5
codius-workers/packages/codius-astro/src/pages/webhooks/github/workflow-job.ts
Line 27 in 84c9cd5