Skip to content

Commit

Permalink
ci(ga): cleanup caches after uploading to npm
Browse files Browse the repository at this point in the history
  • Loading branch information
Dwlad90 committed Dec 21, 2024
1 parent ce90094 commit af4794d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 26 deletions.
37 changes: 17 additions & 20 deletions .github/workflows/cleanup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,32 @@ jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Cleanup
- name: 🧹 Cleanup
shell: bash
run: |
if [ "${{ github.event_name }}" = "push" ]; then
BRANCH_REF="refs/heads/develop"
PR_REF="refs/pull/${{ github.event.pull_request.number }}/merge"
sleep 100
BRANCH_REF="refs/heads/${{ github.ref_name }}"
echo "Cleaning develop branch caches (excluding benchmarks)..."
cacheKeys=$(gh cache list --ref $BRANCH_REF --limit 100 --json key,id --jq '.[] | select(.key | contains("-benchmark") | not) | .id')
for key in $cacheKeys; do
echo "Cache \"$key will\" will be deleted"
gh cache delete $key
done
echo "Cleaning PR caches (excluding benchmarks)..."
prCacheKeys=$(gh cache list --ref $PR_REF --limit 100 --json key,id --jq '.[] | select(.key | contains("-benchmark") | not) | .id')
for key in $prCacheKeys; do
echo "Cache \"$key will\" will be deleted"
gh cache delete $key
done
cacheKeys=$(gh cache list --ref $BRANCH_REF --limit 100 --json key,id --jq '.[] | select(.key | contains("-benchmark") | not) | .id')
else
BRANCH_REF="refs/pull/${{ github.event.pull_request.number }}/merge"
sleep 30
PR_REF="refs/pull/${{ github.event.pull_request.number }}/merge"
echo "Cleaning PR caches (excluding benchmarks)..."
cacheKeys=$(gh cache list --ref $BRANCH_REF --limit 100 --json key,id --jq '.[] | select(.key | contains("-benchmark") | not) | .id')
for key in $cacheKeys; do
echo "Cache \"$key will\" will be deleted"
gh cache delete $key
done
cacheKeys=$(gh cache list --ref $PR_REF --limit 100 --json key,id --jq '.[] | select(.key | contains("-benchmark") | not) | .id')
fi
for key in $cacheKeys; do
echo "Cache \"$key will\" will be deleted"
gh cache delete $key
done
echo "Cache cleanup completed"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
48 changes: 42 additions & 6 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ jobs:
target: aarch64-unknown-linux-gnu
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64
build: pnpm run --filter @stylexswc/rs-compiler build --target aarch64-unknown-linux-gnu
name: stable - ${{ matrix.settings.target }} - node@18
node:
- '20'
name: 🛠️ Build - ${{ matrix.settings.target }} - node@${{ matrix.settings.target }}
runs-on: ${{ matrix.settings.host }}
steps:
- name: Enable long path support
Expand Down Expand Up @@ -80,7 +82,7 @@ jobs:
path: crates/stylex-rs-compiler/dist/${{ env.APP_NAME }}.*.node
if-no-files-found: error
test-macOS-windows-binding:
name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
name: 🧪 Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
needs:
- build
strategy:
Expand Down Expand Up @@ -126,7 +128,7 @@ jobs:
- name: Test bindings
run: pnpm run --filter @stylexswc/rs-compiler test
test-linux-x64-gnu-binding:
name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
name: 🧪 Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
needs:
- build
strategy:
Expand Down Expand Up @@ -162,7 +164,7 @@ jobs:
pnpm run --filter @stylexswc/rs-compiler test
"
test-linux-x64-musl-binding:
name: Test bindings on x86_64-unknown-linux-musl - node@${{ matrix.node }}
name: 🧪 Test bindings on x86_64-unknown-linux-musl - node@${{ matrix.node }}
needs:
- build
strategy:
Expand Down Expand Up @@ -198,7 +200,7 @@ jobs:
pnpm run --filter @stylexswc/rs-compiler test
"
benchmark:
name: Benchmark on ${{ matrix.settings.target }} - node@${{ matrix.node }}
name: 📊 Benchmark on ${{ matrix.settings.target }} - node@${{ matrix.node }}
needs:
- build
strategy:
Expand Down Expand Up @@ -268,7 +270,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish:
name: Publish
name: 📦 Publish
runs-on: ubuntu-latest
needs:
- build
Expand Down Expand Up @@ -306,3 +308,37 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_CONFIG_PROVENANCE: true
cleanup:
if: always()
needs: [publish]
runs-on: ubuntu-latest
steps:
- name: 🧹 Cleanup Caches
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Wait for cache propagation
sleep 10
echo "🔍 Listing caches..."
# Get cache keys excluding benchmarks
cacheKeys=$(gh cache list \
--ref "${{ github.ref }}" \
--limit 100 \
--json key,id \
--jq '.[] | select(.key | contains("-benchmark") | not) | .id')
if [ -z "$cacheKeys" ]; then
echo "ℹ️ No caches found to clean"
exit 0
fi
# Delete each cache
echo "🗑️ Deleting caches..."
for key in $cacheKeys; do
echo "Deleting cache: $key"
gh cache delete "$key" --confirm
done
echo "✅ Cache cleanup completed"

0 comments on commit af4794d

Please sign in to comment.