-
Notifications
You must be signed in to change notification settings - Fork 0
52 lines (39 loc) · 1.61 KB
/
component-release.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
name: Publish a versioned release of an infrastructure component
on:
push:
branches:
- 'main'
jobs:
publish-component:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: publish
shell: bash
env:
PUBLISH_REMOTE : origin
RELEASE_CHANNEL : latest
run: |
git config user.name "$(git log -1 --format=%cn "$GITHUB_REF")"
git config user.email "$(git log -1 --format=%ce "$GITHUB_REF")"
parents=( $(git log -1 --format=%P "$GITHUB_REF") )
if [[ ${#parents[*]} -gt 1 ]]; then
# NOTE: This workflow assumes all merges will have exactly two parents.
# Octopus merges break this assumption and should be avoided.
merge_head_rev=${parents[1]}
release_refs=( $(git show-ref | grep "$merge_head_rev" | awk '{print $2}' | grep "^refs/remotes/$PUBLISH_REMOTE/releases/" || true) )
for ref in "${release_refs[@]}"; do
branch=${ref#refs/remotes/$PUBLISH_REMOTE/}
component=$(dirname "${branch#releases/}")
version=$(basename "${branch#releases/}")
printf 'info: publishing component: %s %s\n' "$component" "$version"
"$GITHUB_WORKSPACE"/.sh/publish-component.sh "$component" "$version" "$RELEASE_CHANNEL"
git push --delete "$PUBLISH_REMOTE" "$branch"
done
printf 'info: done publishing components.\n'
else
printf 'warn: HEAD is not a merge; skipping release\n'
exit 0
fi