From 8491506ecdbdf85ec83a0509e2f44fe3f90f1024 Mon Sep 17 00:00:00 2001 From: Dori Medini Date: Tue, 17 Dec 2024 16:58:37 +0200 Subject: [PATCH] feat(ci): trigger native_blockifier build directly Signed-off-by: Dori Medini --- .github/workflows/trigger _workflow.yml | 52 ------------- .../workflows/upload_artifacts_workflow.yml | 73 +++++++++++++------ 2 files changed, 52 insertions(+), 73 deletions(-) delete mode 100644 .github/workflows/trigger _workflow.yml diff --git a/.github/workflows/trigger _workflow.yml b/.github/workflows/trigger _workflow.yml deleted file mode 100644 index de9bcdb777..0000000000 --- a/.github/workflows/trigger _workflow.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: Trigger-Workflow - -# This workflow exists to trigger the upload_artifacts workflow on both pull requests and push -# events. It solves the issue of forked PRs not having access to secrets. Since external -# contributors don’t have permission to access secrets, this dummy workflow runs with their -# privileges and triggers the upload_artifacts workflow via the workflow_run event. -# The upload_artifacts workflow runs in the context of the main branch, where it has access to -# the necessary secrets for uploading artifacts, providing a secure solution for managing artifacts -# in forked PRs. - -on: - push: - branches: - - main - - main-v[0-9].** - tags: - - v[0-9].** - - pull_request: - types: - - opened - - reopened - - synchronize - - auto_merge_enabled - - edited - paths: - # Other than code-related changes, all changes related to the native-blockifier build-and-push - # process should trigger the build (e.g., changes to the Dockerfile, build scripts, etc.). - - '.github/workflows/blockifier_ci.yml' - - '.github/workflows/trigger_workflow.yml' - - '.github/workflows/upload_artifacts_workflow.yml' - - 'build_native_in_docker.sh' - - 'Cargo.lock' - - 'Cargo.toml' - - 'crates/blockifier/**' - - 'crates/native_blockifier/**' - - 'scripts/build_native_blockifier.sh' - - 'scripts/dependencies.sh' - - 'scripts/install_build_tools.sh' - - 'scripts/sequencer-ci.Dockerfile' - -# On PR events, cancel existing CI runs on this same PR for this workflow. -concurrency: - group: ${{ github.workflow }}-${{ github.ref }}-${{ github.job }} - cancel-in-progress: ${{ github.event_name == 'pull_request' }} - -jobs: - dummy_job: - runs-on: starkware-ubuntu-latest-small - steps: - - name: Dummy step - run: echo "This is a dummy job to trigger the upload_artifacts workflow." diff --git a/.github/workflows/upload_artifacts_workflow.yml b/.github/workflows/upload_artifacts_workflow.yml index bf7261435a..78bef51fc9 100644 --- a/.github/workflows/upload_artifacts_workflow.yml +++ b/.github/workflows/upload_artifacts_workflow.yml @@ -1,9 +1,39 @@ name: Upload-Artifacts on: - workflow_run: - workflows: [Trigger-Workflow] - types: [completed] + push: + branches: + - main + - main-v[0-9].** + tags: + - v[0-9].** + + pull_request: + types: + - opened + - reopened + - synchronize + - auto_merge_enabled + - edited + paths: + # Other than code-related changes, all changes related to the native-blockifier build-and-push + # process should trigger the build (e.g., changes to the Dockerfile, build scripts, etc.). + - '.github/workflows/blockifier_ci.yml' + - '.github/workflows/upload_artifacts_workflow.yml' + - 'build_native_in_docker.sh' + - 'Cargo.lock' + - 'Cargo.toml' + - 'crates/blockifier/**' + - 'crates/native_blockifier/**' + - 'scripts/build_native_blockifier.sh' + - 'scripts/dependencies.sh' + - 'scripts/install_build_tools.sh' + - 'scripts/sequencer-ci.Dockerfile' + +# On PR events, cancel existing CI runs on this same PR for this workflow. +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.job }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} env: RUSTFLAGS: "-D warnings -C link-arg=-fuse-ld=lld" @@ -12,60 +42,61 @@ jobs: native-blockifier-artifacts-push: runs-on: starkware-ubuntu-latest-medium steps: + - uses: actions/checkout@v4 + + # Commit hash on pull request event would be the head commit of the branch. - name: Get commit hash prefix for PR update + if: ${{ github.event_name == 'pull_request' }} env: - COMMIT_SHA: ${{ github.event.workflow_run.head_commit.id }} - run: | - echo "SHORT_HASH=${COMMIT_SHA:0:7}" >> $GITHUB_ENV - echo "COMMIT_SHA=${COMMIT_SHA}" >> $GITHUB_ENV + COMMIT_SHA: ${{ github.event.pull_request.head.sha }} + run: echo "SHORT_HASH=${COMMIT_SHA:0:7}" >> $GITHUB_ENV - # This workflow is always triggered in `main` branch context, so need to checkout the commit. - - uses: actions/checkout@v4 - with: - ref: ${{ env.COMMIT_SHA }} + # On push event (to main, for example) we should take the commit post-push. + - name: Get commit hash prefix for merge + if: ${{ github.event_name != 'pull_request' }} + env: + COMMIT_SHA: ${{ github.event.after }} + run: echo "SHORT_HASH=${COMMIT_SHA:0:7}" >> $GITHUB_ENV # Set environment variables. - name: Set environment variable env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - pr_number=$(gh pr list --head "${{ github.event.workflow_run.head_branch }}" --json number --jq '.[0].number') - echo "PR_NUMBER=$pr_number" >> $GITHUB_ENV echo "WORKFLOW_LINK=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_ENV # Comment with a link to the workflow (or update existing comment on rerun). - # Required, as this is a triggered workflow, and does not appear on the PR status page. - name: Find Comment - if: env.PR_NUMBER != '' + if: github.event_name == 'pull_request' uses: starkware-libs/find-comment@v3 id: find-comment with: token: ${{ secrets.GITHUB_TOKEN }} - issue-number: ${{ env.PR_NUMBER }} + issue-number: ${{ github.event.pull_request.number }} comment-author: 'github-actions[bot]' body-includes: Artifacts upload workflows - name: Create comment # If the PR number is found and the comment is not found, create a new comment. - if: env.PR_NUMBER != '' && steps.find-comment.outputs.comment-id == '' + if: github.event_name == 'pull_request' && steps.find-comment.outputs.comment-id == '' uses: starkware-libs/create-or-update-comment@v4 with: token: ${{ secrets.GITHUB_TOKEN }} - issue-number: ${{ env.PR_NUMBER }} + issue-number: ${{ github.event.pull_request.number }} body: | Artifacts upload workflows: - * [Started at ${{ github.event.workflow_run.run_started_at }}](${{ env.WORKFLOW_LINK }}) + * [Started at ${{ github.event.pull_request.updated_at }}](${{ env.WORKFLOW_LINK }}) - name: Update comment # If the PR number is found and the comment exists, update it. - if: env.PR_NUMBER != '' && steps.find-comment.outputs.comment-id != '' + if: github.event_name == 'pull_request' && steps.find-comment.outputs.comment-id != '' uses: starkware-libs/create-or-update-comment@v4 with: token: ${{ secrets.GITHUB_TOKEN }} comment-id: ${{ steps.find-comment.outputs.comment-id }} edit-mode: append body: | - * [Started at ${{ github.event.workflow_run.run_started_at }}](${{ env.WORKFLOW_LINK }}) + * [Started at ${{ github.event.pull_request.updated_at }}](${{ env.WORKFLOW_LINK }}) # Build artifact. - uses: ./.github/actions/bootstrap