Skip to content

Update GitHub actions (major) #1306

Update GitHub actions (major)

Update GitHub actions (major) #1306

name: Test PR Cleanup Action
on:
pull_request:
types: [opened, reopened, synchronize]
jobs:
# Create a cache entry and an artifact when a PR is opened or updated
test-resources:
runs-on: github-ubuntu-latest-s
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
# Create test file and directory for cache
- name: Create test file for cache
run: |
mkdir -p test-cache
echo "Test content for cache" > test-cache/test.txt
- name: Save test cache
uses: actions/cache/save@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
with:
path: ./test-cache
key: test-cache-${{ github.event.pull_request.number }}
- name: Create and upload test artifact
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: test-artifact-${{ github.event.pull_request.number }}
path: test-cache/test.txt
retention-days: 1
test-cleanup:
runs-on: github-ubuntu-latest-s
needs: test-resources
permissions:
actions: write # Required for cache/artifact operations
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Run PR cleanup
uses: ./pr_cleanup
- name: Verify cache cleanup
env:
GH_TOKEN: ${{ github.token }}
run: |
# Try to restore the cache, should fail or be empty
mkdir -p test-cache
PR_NUMBER=${{ github.event.pull_request.number }}
CACHE_REF="refs/pull/$PR_NUMBER/merge"
if gh cache list --repo "$GITHUB_REPOSITORY" --ref "$CACHE_REF" | grep -q "test-cache-$PR_NUMBER"; then
echo "❌ Cache was not cleaned up"
exit 1
else
echo "✅ Cache was successfully cleaned up"
fi
- name: Verify artifact cleanup
env:
GH_TOKEN: ${{ github.token }}
run: |
# Check if artifact exists, should not find it
PR_NUMBER=${{ github.event.pull_request.number }}
ARTIFACT_NAME="test-artifact-$PR_NUMBER"
if gh api -X GET "/repos/$GITHUB_REPOSITORY/actions/artifacts" | grep -q "$ARTIFACT_NAME"; then
echo "❌ Artifact was not cleaned up"
exit 1
else
echo "✅ Artifact was successfully cleaned up"
fi