Skip to content

Commit

Permalink
ci: speed up diff ci (#4841)
Browse files Browse the repository at this point in the history
* ci: use commit sha as path to save local artifacts

* ci: use commit sha as path to save local artifacts

* ci: use commit sha as path to save local artifacts

* ci: use commit sha as path to save local artifacts

* ci: use commit sha as path to save local artifacts

* ci: use commit sha as path to save local artifacts

* ci: use commit sha as path to save local artifacts

* ci: use commit sha as path to save local artifacts

* ci: use commit sha as path to save local artifacts

* ci: use commit sha as path to save local artifacts

* ci: use commit sha as path to save local artifacts

---------

Co-authored-by: LingyuCoder <--global>
  • Loading branch information
LingyuCoder authored Dec 1, 2023
1 parent 9def2b1 commit ff20da9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 20 deletions.
10 changes: 5 additions & 5 deletions .github/actions/download-artifact/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ runs:
shell: bash
run: |
set -e
save_dir=$HOME/.cache/runner/${{ github.repository_id }}-${{ github.run_id }}-${{ inputs.name }}
save_dir=$HOME/.cache/runner/${{ github.repository_id }}-${{ github.sha }}-${{ inputs.name }}
# download file
if [ "${{ inputs.link-when-local }}" = "true" ]; then
ln -s $save_dir/* ${{ inputs.path }}
echo "ln -s $save_dir/* ${{ inputs.path }}"
ln -sf $save_dir/* ${{ inputs.path }}
echo "ln -sf $save_dir/* ${{ inputs.path }}"
else
cp -r $save_dir/* ${{ inputs.path }}
echo "cp -r $save_dir/* ${{ inputs.path }}"
cp -rf $save_dir/* ${{ inputs.path }}
echo "cp -rf $save_dir/* ${{ inputs.path }}"
fi
10 changes: 5 additions & 5 deletions .github/actions/upload-artifact/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ runs:
find $cache_dir -type d -maxdepth 1 -mindepth 1 -cmin +180 | xargs rm -rf
# save file
save_dir="$cache_dir/${{ github.repository_id }}-${{ github.run_id }}-${{ inputs.name }}"
save_dir="$cache_dir/${{ github.repository_id }}-${{ github.sha }}-${{ inputs.name }}"
rm -rf $save_dir
mkdir $save_dir
if [ "${{ inputs.mv-when-local }}" = "true" ]; then
mv ${{ inputs.path }} $save_dir
echo "mv ${{ inputs.path }} $save_dir"
mv -f ${{ inputs.path }} $save_dir
echo "mv -f ${{ inputs.path }} $save_dir"
else
cp -r ${{ inputs.path }} $save_dir
echo "cp -r ${{ inputs.path }} $save_dir"
cp -rf ${{ inputs.path }} $save_dir
echo "cp -rf ${{ inputs.path }} $save_dir"
fi
# TODO echo machine name as runner labels
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
runner: ${{ needs.get-runner-labels.outputs.LINUX_RUNNER_LABELS }}
uses: ./.github/workflows/reusable-build.yml
with:
profile: "debug"
ref: refs/pull/${{ github.event.issue.number }}/head
target: ${{ matrix.array.target }}
runner: ${{ matrix.array.runner }}
Expand Down
33 changes: 23 additions & 10 deletions .github/workflows/reusable-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,22 @@ jobs:
echo 'codegen-units = 64' >> Cargo.toml
echo 'incremental = false' >> Cargo.toml
# Linux
- name: Check local cache
id: check_cache
if: ${{ inputs.profile == 'debug' && !startsWith(runner.name, 'GitHub Actions') }}
shell: bash
run: |
set -e
cache_dir=$HOME/.cache/runner/${{ github.repository_id }}-${{ github.sha }}-bindings-${{ inputs.target }}
if [[ -d "$cache_dir" ]]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
# Linux
- name: Build x86_64-unknown-linux-gnu in Docker
if: ${{ inputs.target == 'x86_64-unknown-linux-gnu' }}
if: ${{ inputs.target == 'x86_64-unknown-linux-gnu' && steps.check_cache.outputs.exists != 'true' }}
uses: ./.github/actions/docker-build
with:
image: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
Expand All @@ -107,7 +119,7 @@ jobs:
options: -v $HOME/.cargo:/usr/local/cargo -v $HOME/.rustup:/usr/local/rustup

- name: Build aarch64-unknown-linux-gnu in Docker
if: ${{ inputs.target == 'aarch64-unknown-linux-gnu' }}
if: ${{ inputs.target == 'aarch64-unknown-linux-gnu' && steps.check_cache.outputs.files_exists != 'true' }}
uses: ./.github/actions/docker-build
with:
target: ${{ inputs.target }}
Expand All @@ -116,15 +128,15 @@ jobs:
pre: export JEMALLOC_SYS_WITH_LG_PAGE=16 && export CC_aarch64_unknown_linux_gnu=/usr/aarch64-unknown-linux-gnu/bin/aarch64-unknown-linux-gnu-gcc # for jemallocator to compile

- name: Build x86_64-unknown-linux-musl in Docker
if: ${{ inputs.target == 'x86_64-unknown-linux-musl' }}
if: ${{ inputs.target == 'x86_64-unknown-linux-musl' && steps.check_cache.outputs.files_exists != 'true' }}
uses: ./.github/actions/docker-build
with:
target: ${{ inputs.target }}
image: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
profile: ${{ inputs.profile }}

- name: Build aarch64-unknown-linux-musl in Docker
if: ${{ inputs.target == 'aarch64-unknown-linux-musl' }}
if: ${{ inputs.target == 'aarch64-unknown-linux-musl' && steps.check_cache.outputs.files_exists != 'true' }}
uses: ./.github/actions/docker-build
with:
target: ${{ inputs.target }}
Expand All @@ -141,25 +153,25 @@ jobs:
# Windows

- name: Build i686-pc-windows-msvc
if: ${{ inputs.target == 'i686-pc-windows-msvc' }}
if: ${{ inputs.target == 'i686-pc-windows-msvc' && steps.check_cache.outputs.files_exists != 'true' }}
run: RUST_TARGET=${{ inputs.target }} pnpm build:binding:${{ inputs.profile }}

- name: Build x86_64-pc-windows-msvc
if: ${{ inputs.target == 'x86_64-pc-windows-msvc' }}
if: ${{ inputs.target == 'x86_64-pc-windows-msvc' && steps.check_cache.outputs.files_exists != 'true' }}
run: RUST_TARGET=${{ inputs.target }} pnpm build:binding:${{ inputs.profile }}

- name: Build aarch64-pc-windows-msvc
if: ${{ inputs.target == 'aarch64-pc-windows-msvc' }}
if: ${{ inputs.target == 'aarch64-pc-windows-msvc' && steps.check_cache.outputs.files_exists != 'true' }}
run: RUST_TARGET=${{ inputs.target }} pnpm build:binding:${{ inputs.profile }}

# Mac
- name: Build x86_64-apple-darwin
if: ${{ inputs.target == 'x86_64-apple-darwin' }}
if: ${{ inputs.target == 'x86_64-apple-darwin' && steps.check_cache.outputs.files_exists != 'true' }}
run: |
RUST_TARGET=${{ inputs.target }} pnpm build:binding:${{ inputs.profile }}
- name: Build aarch64-apple-darwin
if: ${{ inputs.target == 'aarch64-apple-darwin' }}
if: ${{ inputs.target == 'aarch64-apple-darwin' && steps.check_cache.outputs.files_exists != 'true' }}
run: |
if [[ "${{ startsWith(runner.name, 'GitHub Actions') }}" == "true" ]]; then
# Github runner
Expand All @@ -173,6 +185,7 @@ jobs:
- name: Upload artifact
id: upload-artifact
uses: ./.github/actions/upload-artifact
if: ${{ steps.check_cache.outputs.exists != 'true' }}
with:
name: bindings-${{ inputs.target }}
path: crates/node_binding/*.node
Expand Down

0 comments on commit ff20da9

Please sign in to comment.