-
Notifications
You must be signed in to change notification settings - Fork 1
82 lines (71 loc) · 2.68 KB
/
Copy pathexample-cache-artifacts.yml
File metadata and controls
82 lines (71 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
name: 'Example: cache artifacts'
# Save and restore a tarball between jobs using B2 instead of actions/cache.
# Useful when you outgrow GH's per-org cache limit, want shared caches across
# workflows, or need TTL/lifecycle controls only B2 provides.
on:
workflow_dispatch:
push:
branches: [main]
pull_request:
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
cache:
name: cache
if: github.event_name == 'workflow_dispatch' || github.event_name == 'push' || (github.event.pull_request.head.repo.fork == false && github.actor != 'dependabot[bot]')
runs-on: ubuntu-latest
# We hardcode `Linux` rather than `${{ runner.os }}` because the `runner`
# context isn't allowed in job-level `env:` (only at step level). This job
# always runs on `ubuntu-latest` so the value is fixed anyway.
env:
CACHE_KEY: cache/Linux/example-${{ github.run_id }}.tar.gz
steps:
- uses: actions/checkout@9f698171ed81b15d1823a05fc7211befd50c8ae0 # v6.0.3
with:
persist-credentials: false
- name: Build a synthetic cache payload
run: |
mkdir -p _cache
dd if=/dev/urandom of=_cache/blob bs=1024 count=128
tar -czf payload.tar.gz _cache
- name: Save cache to B2
id: save
uses: ./
with:
action: upload
application-key-id: ${{ secrets.B2_APPLICATION_KEY_ID }}
application-key: ${{ secrets.B2_APPLICATION_KEY }}
bucket: ${{ secrets.B2_TEST_BUCKET }}
source: payload.tar.gz
destination: ${{ env.CACHE_KEY }}
- name: Wipe local copy
run: rm -rf _cache payload.tar.gz
- name: Restore cache from B2
uses: ./
with:
action: download
application-key-id: ${{ secrets.B2_APPLICATION_KEY_ID }}
application-key: ${{ secrets.B2_APPLICATION_KEY }}
bucket: ${{ secrets.B2_TEST_BUCKET }}
source: ${{ env.CACHE_KEY }}
destination: payload.restored.tar.gz
- name: Verify cache integrity
env:
SAVED_FILE_ID: ${{ steps.save.outputs.file-id }}
SAVED_SHA1: ${{ steps.save.outputs.content-sha1 }}
run: |
tar -tzf payload.restored.tar.gz | grep _cache/blob
echo "Saved file-id: $SAVED_FILE_ID"
echo "SHA-1: $SAVED_SHA1"
- name: Cleanup
if: always()
uses: ./
with:
action: delete
application-key-id: ${{ secrets.B2_APPLICATION_KEY_ID }}
application-key: ${{ secrets.B2_APPLICATION_KEY }}
bucket: ${{ secrets.B2_TEST_BUCKET }}
source: ${{ env.CACHE_KEY }}