diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 91f3c0b0242..88db7840aa5 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -53,6 +53,14 @@ jobs: shell: bash run: | echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" + echo "build-key=${{ runner.os }}-${{github.workflow}}-${{ matrix.build_type }}-${{ matrix.c_compiler }}" >> "$GITHUB_OUTPUT" + + # Only download workspace artifacts on pull requests. CI builds should start from a fresh state. + - uses: actions/download-artifact@v3 + if: ${{ github.event_name == 'pull_request' }} + with: + name: workspace-${{ steps.strings.outputs.build-key }} + path: ${{ github.workspace }} - name: Install Ubuntu build dependencies if: matrix.os == 'ubuntu-latest' @@ -94,3 +102,10 @@ jobs: run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} env: SCCACHE_GHA_ENABLED: "true" + + # Always upload workspace artifacts. Eventually only do this for pushes to main. + - uses: actions/upload-artifact@v3 + with: + name: workspace-${{ steps.strings.outputs.build-key }} + path: ${{ github.workspace }} + retention-days: 7 diff --git a/.github/workflows/gn.yml b/.github/workflows/gn.yml index cc0fbf1c8e6..3a5816002d7 100644 --- a/.github/workflows/gn.yml +++ b/.github/workflows/gn.yml @@ -34,6 +34,21 @@ jobs: - uses: actions/checkout@v3 + - name: Set reusable strings + # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. + id: strings + shell: bash + run: | + echo "build-output-dir=out/build" >> "$GITHUB_OUTPUT" + echo "build-key=${{ runner.os }}-${{github.workflow}}" >> "$GITHUB_OUTPUT" + + # Only download workspace artifacts on pull requests. CI builds should start from a fresh state. + - uses: actions/download-artifact@v3 + if: ${{ github.event_name == 'pull_request' }} + with: + name: workspace-${{ steps.strings.outputs.build-key }} + path: ${{ github.workspace }} + - name: Set up checkout run: | cp ./scripts/standalone.gclient .gclient @@ -49,21 +64,28 @@ jobs: - name: Generate build files shell: bash run: | - mkdir -p out/build - cat << EOF >> out/build/args.gn + mkdir -p ${{ steps.strings.outputs.build-output-dir }} + cat << EOF >> ${{ steps.strings.outputs.build-output-dir }}/args.gn cc_wrapper="sccache" is_debug=false is_component_build=true is_clang=true EOF - gn gen out/build + gn gen ${{ steps.strings.outputs.build-output-dir }} env: SCCACHE_GHA_ENABLED: "true" DEPOT_TOOLS_WIN_TOOLCHAIN: 0 - name: Build - run: autoninja -C out/build + run: autoninja -C ${{ steps.strings.outputs.build-output-dir }} env: SCCACHE_GHA_ENABLED: "true" DEPOT_TOOLS_WIN_TOOLCHAIN: 0 + + # Always upload workspace artifacts. Eventually only do this for pushes to main. + - uses: actions/upload-artifact@v3 + with: + name: workspace-${{ steps.strings.outputs.build-key }} + path: ${{ github.workspace }} + retention-days: 7