-
Notifications
You must be signed in to change notification settings - Fork 3
112 lines (96 loc) · 3.3 KB
/
build-pyz.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
name: Build PYZ distribution
run-name: ${{ github.event.release.tag_name || inputs.head-ref || github.event.workflow_run.display_title }}
on:
release:
types:
- published
# release published by workflow does not trigger above event;
# rather, we're triggered by this below
workflow_run:
workflows:
- publish
types:
- completed
workflow_dispatch:
inputs:
head-ref:
default: ""
required: false
type: string
description: Non-default changeset to build
jobs:
setup:
runs-on: ubuntu-latest
outputs:
release-sha: ${{ steps.head.outputs.release-sha }}
can-build: ${{ steps.upstream.outputs.can-build }}
steps:
- name: Check upstream success
id: upstream
env:
CONCLUSION: ${{ github.event.workflow_run && github.event.workflow_run.conclusion || 'na' }}
run: |
case "$CONCLUSION" in
success)
echo "upstream publish successful"
echo "can-build=true" >> $GITHUB_OUTPUT
;;
na)
echo "no upstream workflow"
echo "can-build=true" >> $GITHUB_OUTPUT
;;
*)
echo "::notice::upstream publish unsuccessful"
echo "can-build=false" >> $GITHUB_OUTPUT
;;
esac
- name: Check out repository
uses: actions/checkout@v4
if: fromJSON(steps.upstream.outputs.can-build)
with:
# fetch enough that we should feasibly be able to find this changeset
# and its subsequent tag commit (but without fetching *everything*)
ref: ${{ github.event.workflow_run.head_branch }}
fetch-depth: 100
# fetch tags s.t. we can interpret ref inputs on dispatch
fetch-tags: true
- name: Determine HEAD
id: head
if: fromJSON(steps.upstream.outputs.can-build)
env:
HEAD_REF: ${{ inputs.head-ref }}
RUN_SHA: ${{ github.event.workflow_run.head_sha }}
run: |
if [ -n "$HEAD_REF" ]
then
TARGET_REF="${HEAD_REF}^"
else
TARGET_REF="$RUN_SHA"
fi
HEAD="$(git log --format=%H ${TARGET_REF}.. | tail -n 1)"
if [ -z "$HEAD" ]
then
echo "::error::could not find publish workflow changeset following ${TARGET_REF:0:9}"
exit 1
fi
# Though we've fetched plenty of *commits* above, we can't rely on having all *tags*
# So instead we'll query the remote.
TAGS="$(git ls-remote --tags --refs --quiet | grep -E "^${HEAD}\s+" | awk '{print $2}' | awk -F / '{print $3}')"
if [ -z "$TAGS" ]
then
echo "::error::changeset following ${TARGET_REF:0:9} does not appear to be tagged release: ${HEAD:0:9}"
exit 1
fi
echo "publish workflow release SHA: $HEAD:" $TAGS
echo "release-sha=$HEAD" >> $GITHUB_OUTPUT
delegate:
needs: [setup]
uses: internet-equity/fate-pyz/.github/workflows/[email protected]
if: fromJSON(needs.setup.outputs.can-build)
permissions:
contents: write
with:
app-main: netrics
app-alts: netrics.+
app-solo: false
head-sha: ${{ needs.setup.outputs.release-sha }}