Skip to content

Commit

Permalink
feat: upload and download rust artifical from lynx
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind committed Dec 4, 2024
1 parent 9373585 commit ae3400c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 41 deletions.
48 changes: 27 additions & 21 deletions .github/actions/download-artifact/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,49 @@ name: Download Artifact
description: Download file to local or artifact to quickly share files between jobs

inputs:
type:
description: "Use github or local or lynx cache"
required: true
type: string
choices:
- github
- local
- lynx
name:
description: "Artifact name"
default: "artifact"
path:
description: "Destination path"
required: true
try-local-cache:
description: "Try use local cache to save artifact"
default: false
required: false
type: boolean
link-when-local:
description: "Link file instead of copy file"
default: false
type: boolean
required: false

runs:
using: composite
steps:
- name: Download artifact
- name: Download artifact from github
uses: actions/[email protected]
if: ${{ startsWith(runner.name, 'GitHub Actions') || inputs.try-local-cache == 'false' }}
if: ${{ inputs.type == 'github' }}
with:
name: ${{ inputs.name }}
path: ${{ inputs.path }}
- name: Download local
if: ${{ !startsWith(runner.name, 'GitHub Actions') && inputs.try-local-cache == 'true' }}
- name: Download artifact from local
if: ${{ inputs.type == 'local' }}
shell: bash
run: |
set -e
save_dir=$HOME/.cache/runner/${{ github.repository_id }}-${{ github.sha }}-${{ inputs.name }}
# download file
if [ "${{ inputs.link-when-local }}" = "true" ]; then
ln -sf $save_dir/* ${{ inputs.path }}
echo "ln -sf $save_dir/* ${{ inputs.path }}"
else
cp -rf $save_dir/* ${{ inputs.path }}
echo "cp -rf $save_dir/* ${{ inputs.path }}"
fi
ln -sf $save_dir/* ${{ inputs.path }}
echo "ln -sf $save_dir/* ${{ inputs.path }}"
- name: Download artifact from lynx
if: ${{ inputs.type == 'lynx' }}
uses: lynx-infra/cache/restore@main
with:
path: ${{ inputs.path }}
key: rust-artifact-${{ github.repository_id }}-${{ github.sha }}-${{ inputs.name }}
restore-keys: |
rust-artifact-${{ github.repository_id }}-${{ github.sha }}-${{ inputs.name }}
env:
ACCESS_KEY: ${{ inputs.tos-access-key }}
SECRET_KEY: ${{ inputs.tos-secret-key }}
BUCKET_NAME: ${{ inputs.tos-bucket-name }}
REGION: ${{ inputs.tos-region }}
26 changes: 12 additions & 14 deletions .github/actions/upload-artifact/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ inputs:
- github
- local
- lynx
mv-when-local:
description: "Move file instead of copy file"
default: false
type: boolean
required: false

outputs:
runner-labels:
Expand All @@ -41,11 +36,18 @@ runs:
overwrite: true

- name: Upload artifact
uses: lynx-infra/cache@main
uses: lynx-infra/cache/save@main
if: ${{ inputs.type == 'lynx' }}
with:
name: ${{ inputs.name }}
path: ${{ inputs.path }}
key: rust-artifact-${{ github.repository_id }}-${{ github.sha }}-${{ inputs.name }}
restore-keys: |
rust-artifact-${{ github.repository_id }}-${{ github.sha }}-${{ inputs.name }}
env:
ACCESS_KEY: ${{ inputs.tos-access-key }}
SECRET_KEY: ${{ inputs.tos-secret-key }}
BUCKET_NAME: ${{ inputs.tos-bucket-name }}
REGION: ${{ inputs.tos-region }}

- name: Upload local
id: upload-local
Expand All @@ -64,13 +66,9 @@ runs:
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 -f ${{ inputs.path }} $save_dir
echo "mv -f ${{ inputs.path }} $save_dir"
else
cp -rf ${{ inputs.path }} $save_dir
echo "cp -rf ${{ inputs.path }} $save_dir"
fi
mv -f ${{ inputs.path }} $save_dir
echo "mv -f ${{ inputs.path }} $save_dir"
# TODO echo machine name as runner labels
# echo "runner_labels=\"$(uname -n)\"" >> "$GITHUB_OUTPUT"
Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/reusable-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,9 @@ jobs:
uses: ./.github/actions/upload-artifact
if: ${{ steps.check_cache.outputs.exists != 'true' && !inputs.skipable }}
with:
type: ${{ inputs.cache-type }}
name: bindings-${{ inputs.target }}
path: crates/node_binding/*.node
try-local-cache: ${{ inputs.profile == 'debug' }}
mv-when-local: true

e2e:
name: E2E Testing
Expand All @@ -251,10 +250,9 @@ jobs:
- name: Download bindings
uses: ./.github/actions/download-artifact
with:
type: ${{ inputs.cache-type }}
name: bindings-${{ inputs.target }}
path: crates/node_binding/
try-local-cache: ${{ inputs.profile == 'debug' }}
link-when-local: true

- name: Setup Pnpm
uses: ./.github/actions/pnpm-cache
Expand Down Expand Up @@ -309,10 +307,9 @@ jobs:
if: ${{ !inputs.skipable }}
uses: ./.github/actions/download-artifact
with:
type: ${{ inputs.cache-type }}
name: bindings-${{ inputs.target }}
path: crates/node_binding/
try-local-cache: ${{ inputs.profile == 'debug' }}
link-when-local: true

- name: Show restored binding
if: ${{ !inputs.skipable }}
Expand Down

0 comments on commit ae3400c

Please sign in to comment.