-
Notifications
You must be signed in to change notification settings - Fork 8
168 lines (147 loc) · 5.44 KB
/
setup-variables.yml
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
---
permissions: read-all
on:
workflow_call:
# Map the workflow outputs to job outputs
outputs:
last_release_ref:
description: "Ref to last release"
value: ${{ jobs.configure.outputs.last_release_ref }}
test_ref:
description: "Ref in test repo to be used"
value: ${{ jobs.configure.outputs.test_ref }}
tools_ref:
description: "Ref in tools repo to be used"
value: ${{ jobs.configure.outputs.tools_ref }}
lib_version:
description: "Lib version in lib repo to be used"
value: ${{ jobs.configure.outputs.lib_version }}
# This workflow configures variables that are useful for other jobs. Other
# jobs that depend on this one can access the variables via
# needs.<job-name>.outputs.<variable-name>
jobs:
configure:
runs-on: [self-hosted, linux]
outputs:
last_release_ref: ${{ env.last_release_ref }}
test_ref: ${{ env.test_ref }}
tools_ref: ${{ env.tools_ref }}
lib_version: ${{env.lib_version}}
env:
last_release_ref: ''
test_ref: ''
tools_ref: ''
lib_version: ''
steps:
- name: Cleanup workspace (Linux)
if: always() && runner.os == 'Linux'
run: sudo rm -rf ..?* .[!.]* *
# Get ref of last release.
- name: Checkout PR branch and all history
uses: actions/checkout@v4
with:
path: source
fetch-depth: 0
ref: '${{ github.event.pull_request.head.sha }}'
- name: Get lib version
run: |
cd source
# Extract the version from version.txt and store it in a variable
echo "lib_version=$(cat version.txt)" >> $GITHUB_ENV
- name: Get ref of last release
id: run
run: |
cd source
echo "last_release_ref=$(git describe --abbrev=0 --tags --match=v*)" \
>> $GITHUB_ENV
# Get ref of test to be used. If this is a pull request prefer a branch
# of the same name as the branch being merged into otherwise try to use a
# branch of the same name otherwise use main
- name: Checkout tests from base_ref
if: github.base_ref
id: check-tests-from-base_ref
uses: actions/checkout@v4
continue-on-error: true
with:
repository: ${{ vars.TEST_REPO }}
token: ${{ secrets.TEST_REPO_TOKEN }}
path: tests
fetch-depth: 0
ref: ${{ github.base_ref }}
- name: Use tests from base_ref
if: steps.check-tests-from-base_ref.outcome == 'success'
id: use-tests-from-base_ref
run: |
echo "test_ref=${{ github.base_ref }}" >> $GITHUB_ENV
- name: Checkout tests from ref_name
if: steps.check-tests-from-base_ref.outcome != 'success'
id: check-tests-from-ref_name
uses: actions/checkout@v4
continue-on-error: true
with:
repository: ${{ vars.TEST_REPO }}
token: ${{ secrets.TEST_REPO_TOKEN }}
path: tests
fetch-depth: 0
ref: ${{ github.ref_name }}
- name: Use tests from ref_name
if: steps.check-tests-from-ref_name.outcome == 'success'
id: use-tests-from-ref_name
run: |
echo "test_ref=${{ github.ref_name }}" >> $GITHUB_ENV
- name: Use tests from default
if: >
steps.check-tests-from-base_ref.outcome != 'success'
&& steps.check-tests-from-ref_name.outcome != 'success'
run: |
echo "test_ref=main" >> $GITHUB_ENV
# Get ref of tools to be used. If this is a pull request prefer a branch
# of the same name as the branch being merged into otherwise try to use a
# branch of the same name otherwise use main
- name: Checkout tools from base_ref
if: github.base_ref
id: check-tools-from-base_ref
uses: actions/checkout@v4
continue-on-error: true
with:
repository: ${{ vars.TOOLS_REPO }}
token: ${{ secrets.TOOLS_REPO_TOKEN }}
path: tools
fetch-depth: 0
ref: ${{ github.base_ref }}
- name: Use tools from base_ref
if: steps.check-tools-from-base_ref.outcome == 'success'
id: use-tools-from-base_ref
run: |
echo "tools_ref=${{ github.base_ref }}" >> $GITHUB_ENV
- name: Checkout tools from ref_name
if: steps.check-tools-from-base_ref.outcome != 'success'
id: check-tools-from-ref_name
uses: actions/checkout@v4
continue-on-error: true
with:
repository: ${{ vars.TOOLS_REPO }}
token: ${{ secrets.TOOLS_REPO_TOKEN }}
path: tools
fetch-depth: 0
ref: ${{ github.ref_name }}
- name: Use tools from ref_name
if: steps.check-tools-from-ref_name.outcome == 'success'
id: use-tools-from-ref_name
run: |
echo "tools_ref=${{ github.ref_name }}" >> $GITHUB_ENV
- name: Use tools from default
if: >
steps.check-tools-from-base_ref.outcome != 'success'
&& steps.check-tools-from-ref_name.outcome != 'success'
run: |
echo "tools_ref=main" >> $GITHUB_ENV
- name: Report
if: always()
run: |
echo "last_release_ref=${{ env.last_release_ref }}"
echo "test_ref=${{ env.test_ref }}"
echo "tools_ref=${{ env.tools_ref }}"
- name: Cleanup workspace (Linux)
if: always() && runner.os == 'Linux'
run: sudo rm -rf ..?* .[!.]* *