Repository navigation
151 lines (139 loc) · 5.89 KB
/
Copy pathcreate-test-caches.yml
File metadata and controls
151 lines (139 loc) · 5.89 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
name: "Create: Test Caches"
run-name: "Create: Test Caches [${{ github.ref_name }}]"
################################################################################################################################
# GitHub caches are scoped to branches, with a fallback mechanism:
# 1. A branch by default can only see caches created on that branch
# 2. Failing that, a branch can opt-in to accessing the base branch cache
# 3. If the base branch cache is missing, the opt-in check will fall through to the default branch cache (`main`)
#
# So we build caches on `main` after each push, since our branches typically target `main` as base.
#
# This allows any and all PR branches that ultimately derive from `main` to re-use these caches for faster
# CI workflows, via an intentionally broad `restore-keys` fallback in the actions/cache GitHub action.
#
# The broad cache restore will find the most recently created (newest) caches in `main`.
#
# If the branch has updated cargo crates, or the cache is slightly stale, that's OK.
# The cargo build process will notice the mismatched versions (or new deps) automatically
# and build them on-the-fly. This allows slightly stale caches to still be very useful.
#
# NOTE:
# This job ONLY runs if a GitHub Action variable is set: ENABLE_CI_WORKFLOWS = true
################################################################################################################################
on:
workflow_dispatch: # Allows manual triggering / seeding
inputs:
btc-version:
description: 'The version of the bitcoin binary to use for tests'
required: false
type: string
btc-version-sha:
description: 'The SHA of the binary to verify before executing the tests. Find these in the official SHA256SUMS file for each release. Example: https://bitcoincore.org/bin/bitcoin-core-31.1/SHA256SUMS'
required: false
type: string
push:
branches:
- main
permissions:
contents: read
# Configure concurrency
# - cache will exist longer than workflow execution so other runners have access.
# - when multiple pushes to `main` happen in a short time, cancel
# the current run and start the new one with the most recent code.
concurrency:
group: create-caches
cancel-in-progress: true
jobs:
# Check if CI is enabled
check-ci:
name: "Check: CI Enabled"
uses: ./.github/workflows/__check-ci.yml
############################################################################
### Global Variables Setup
###
### Bridges global env variables to the jobs context so they are safely
### accessible by downstream reusable workflows.
### Also defines default runs-on anchor.
############################################################################
setup-env:
name: "Setup: Global Variables"
needs:
- check-ci
if: needs.check-ci.outputs.enabled == 'true'
runs-on: &shared_config ubuntu-latest
outputs:
btc-version: ${{ steps.btc-version.outputs.version }}
btc-version-sha: ${{ steps.btc-version.outputs.sha }}
steps:
# Checkout the code
# - only .github is required for this job
- name: Checkout the latest code
uses: $/.github/wrappers/checkout
with:
ref: ${{ github.event.pull_request.head.sha || github.ref }}
sparse-checkout: |
.github
# Resolve target bitcoin version
- name: Resolve Target Bitcoin Version
id: btc-version
uses: ./.github/actions/bitcoin-version
with:
btc-version: ${{ inputs.btc-version }}
btc-version-sha: ${{ inputs.btc-version-sha }}
#######################################################################################################################
### Create Reusable Caches for Tests
###
### Caches are created from `main` branch when a GitHub Action variable is set: ENABLE_CI_WORKFLOWS = true
### When run on `main`, this workflow creates canonical re-usable caches for future CI runs.
### When manually dispatched from another branch, any created caches will be scoped to that branch.
#######################################################################################################################
cache-bitcoin-binary:
name: "Create: Bitcoin Binary Cache"
needs:
- setup-env
runs-on: *shared_config
steps:
# Checkout the code
# - only .github is required for this job
- name: Checkout the latest code
uses: $/.github/wrappers/checkout
with:
ref: ${{ github.event.pull_request.head.sha || github.ref }}
sparse-checkout: |
.github
# Check cache for bitcoin binary
# We don't need multiple caches of the same Bitcoin binary, so skip create if one already exists
- name: Check Bitcoin Cache
id: bitcoin
uses: ./.github/actions/cache/bitcoin
with:
action: check
btc-version: ${{ needs.setup-env.outputs.btc-version }}
btc-version-sha: ${{ needs.setup-env.outputs.btc-version-sha }}
# Only create when a binary doesn't already exist
- name: Create Bitcoin Cache
if: >-
!steps.bitcoin.outputs.cache-matched-key
uses: ./.github/actions/cache/bitcoin
with:
action: create
btc-version: ${{ needs.setup-env.outputs.btc-version }}
btc-version-sha: ${{ needs.setup-env.outputs.btc-version-sha }}
cache-cargo:
name: "Create: Cargo Cache"
needs:
- setup-env
runs-on: *shared_config
steps:
# Checkout the code
# - only .github is required for this job
- name: Checkout the latest code
uses: $/.github/wrappers/checkout
with:
ref: ${{ github.event.pull_request.head.sha || github.ref }}
sparse-checkout: |
.github
- name: Create Cargo Cache
uses: ./.github/actions/cache/cargo
with:
action: create