diff --git a/.github/workflows/deploy-main.yml b/.github/workflows/deploy-main.yml index ea52ec4800..dce1caefdd 100644 --- a/.github/workflows/deploy-main.yml +++ b/.github/workflows/deploy-main.yml @@ -51,8 +51,6 @@ jobs: cancel-in-progress: true uses: ./.github/workflows/workflow-build.yml if: github.repository == 'lynx-family/lynx-stack' - with: - runs-on: lynx-ubuntu-24.04-xlarge secrets: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} benchmark: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f523427d93..852079166c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -50,8 +50,6 @@ jobs: uses: ./.github/workflows/workflow-build.yml secrets: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - with: - runs-on: lynx-ubuntu-24.04-xlarge benchmark: needs: build uses: ./.github/workflows/workflow-bench.yml diff --git a/.github/workflows/workflow-build.yml b/.github/workflows/workflow-build.yml index 7523010ee2..e2ee627bcf 100644 --- a/.github/workflows/workflow-build.yml +++ b/.github/workflows/workflow-build.yml @@ -3,16 +3,62 @@ on: secrets: CODECOV_TOKEN: required: false - inputs: - runs-on: - required: true - type: string env: CI: 1 TURBO_TELEMETRY_DISABLED: 1 jobs: + get-merge-base: + runs-on: lynx-ubuntu-24.04-medium + env: + # We have 3 cases: + # 1. Pull request + # 2. Merge group + # 3. Push (deploy on main branch) + BASE_REF: ${{ github.base_ref || github.event.merge_group.base_ref || github.event.push.base_ref }} + HEAD_REF: ${{ github.head_ref || github.event.merge_group.head_ref || github.ref }} + outputs: + merge-base: ${{ steps.merge-base.outputs.merge-base }} + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ env.HEAD_REF }} + repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }} + # Set up common variables for git operations + - name: Setup git refs + id: git-refs + run: | + # Strip refs/heads/ prefix if it exists + BASE_REF_CLEAN=${BASE_REF#refs/heads/} + HEAD_REF_CLEAN=${HEAD_REF#refs/heads/} + echo "base-ref=$BASE_REF_CLEAN" >> $GITHUB_OUTPUT + echo "head-ref=$HEAD_REF_CLEAN" >> $GITHUB_OUTPUT + # Modified from https://github.com/rmacklin/fetch-through-merge-base + - name: Fetch + env: + CLEAN_BASE_REF: ${{ steps.git-refs.outputs.base-ref }} + CLEAN_HEAD_REF: ${{ steps.git-refs.outputs.head-ref }} + run: | + git fetch --progress --depth=1 origin "+refs/heads/$CLEAN_BASE_REF:refs/heads/$CLEAN_BASE_REF" + MAX_ATTEMPTS=10 + ATTEMPT=0 + while [ -z "$( git merge-base "refs/heads/$CLEAN_BASE_REF" "$CLEAN_HEAD_REF" )" ] && [ "$ATTEMPT" -lt "$MAX_ATTEMPTS" ]; do + git fetch -q --deepen=10 origin "refs/heads/$CLEAN_BASE_REF" "$CLEAN_HEAD_REF" + ATTEMPT=$((ATTEMPT + 1)) + done + if [ "$ATTEMPT" -ge "$MAX_ATTEMPTS" ]; then + echo "Failed to determine merge base after $MAX_ATTEMPTS attempts." >&2 + exit 1 + fi + - name: Get merge base + id: merge-base + env: + CLEAN_BASE_REF: ${{ steps.git-refs.outputs.base-ref }} + CLEAN_HEAD_REF: ${{ steps.git-refs.outputs.head-ref }} + run: | + echo "merge-base=$(git merge-base "origin/$CLEAN_BASE_REF" "$CLEAN_HEAD_REF" || git rev-parse origin/"$CLEAN_BASE_REF")" >> $GITHUB_OUTPUT build-all: - runs-on: ${{ inputs.runs-on }} + runs-on: lynx-ubuntu-24.04-xlarge + needs: get-merge-base steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 @@ -25,8 +71,15 @@ jobs: key: turbo-v3-${{ hashFiles('**/packages/**/src/**/*.rs') }}-${{ github.sha }} # We can restore caches from # 1. Runs in the same PR - # 2. Previous PRs + # 2. Previous commit from base branch + # 2.1 Use the merge base + # 2.2 Use the base SHA + # 3. Any cache restore-keys: | + turbo-pull-request-${{ github.event.pull_request.number || 'non-exists' }}-${{ github.run_number }} + turbo-pull-request-${{ github.event.pull_request.number || 'non-exists' }}- + turbo-v3-${{ hashFiles('**/packages/**/src/**/*.rs') }}-${{ needs.get-merge-base.outputs.merge-base }} + turbo-v3-${{ hashFiles('**/packages/**/src/**/*.rs') }}-${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha || github.event.push.before }} turbo-v3-${{ hashFiles('**/packages/**/src/**/*.rs') }}- - name: Install run: | @@ -40,6 +93,15 @@ jobs: env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} continue-on-error: true + - name: Upload turbo summary + if: runner.debug == '1' + uses: actions/upload-artifact@v4 + with: + name: turbo-summary-${{ github.sha }} + path: .turbo/runs/*.json + retention-days: 1 + overwrite: true + include-hidden-files: true - name: Setup Rust and retry build if failed if: steps.build.outcome == 'failure' uses: actions-rust-lang/setup-rust-toolchain@v1 @@ -52,3 +114,9 @@ jobs: pnpm turbo build --summarize env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + - name: Save turbo cache + if: github.event_name == 'pull_request' + uses: lynx-infra/cache/save@558d7c999f9f97ac02ed7e711503bb81d82ff8ee + with: + path: .turbo + key: turbo-pull-request-${{ github.event.pull_request.number }}-${{ github.run_number }}-${{ github.run_attempt }} diff --git a/.github/workflows/workflow-test.yml b/.github/workflows/workflow-test.yml index a619dbf3b5..902dfd37b7 100644 --- a/.github/workflows/workflow-test.yml +++ b/.github/workflows/workflow-test.yml @@ -48,16 +48,6 @@ jobs: - name: Build run: | pnpm turbo build --summarize - - name: Upload Turbo Summary - if: ${{ failure() }} - uses: actions/upload-artifact@v4 - with: - name: turbo-summary-${{ github.ref }} - path: .turbo/runs - if-no-files-found: error - retention-days: 1 - overwrite: true - include-hidden-files: true - uses: ./.github/actions/setup-playwright if: ${{ inputs.is-web }} with: