Repository navigation
108 lines (98 loc) · 4.08 KB
/
Copy pathautotagger.yml
File metadata and controls
108 lines (98 loc) · 4.08 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
name: Monorepo Auto-tagger
on:
push:
branches:
- trunk
- prerelease
- '*/branch-*'
concurrency:
group: autotagger-${{ case( contains( github.ref, '/branch-' ), github.ref, 'unprefixed' ) }}
queue: max
permissions:
# read: actions/checkout
# write: `git push`
contents: write
jobs:
tag:
name: Tag
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Fetch tags, shallowly and blobless
run: |
git fetch --depth=1 --filter=blob:none origin 'refs/tags/*:refs/tags/*'
- name: Tag projects
env:
GIT_AUTHOR_NAME: matticbot
GIT_AUTHOR_EMAIL: 'matticbot@users.noreply.github.com'
GIT_COMMITTER_NAME: matticbot
GIT_COMMITTER_EMAIL: 'matticbot@users.noreply.github.com'
run: |
REF=${GITHUB_REF#refs/heads/}
if [[ "$REF" == */branch-* ]]; then
PROJECTS="$(jq -r --arg P "${REF%%/branch-*}" 'if .extra["release-branch-prefix"] == $P then input_filename | match( "^projects/([^/]+/[^/]+)/composer.json$" ).captures[0].string else empty end' projects/*/*/composer.json)"
if [[ -n "$PROJECTS" ]]; then
echo "Branch $REF seems to be a release branch, checking matching projects."
else
echo "::notice::Branch $REF seems to be a release branch, but nothing uses that prefix so not checking any projects."
exit 0
fi
else
PROJECTS="$(jq -r 'if .extra["release-branch-prefix"] then empty else input_filename | match( "^projects/([^/]+/[^/]+)/composer.json$" ).captures[0].string end' projects/*/*/composer.json)"
if [[ -n "$PROJECTS" ]]; then
echo "Branch $REF is not a release branch, checking only projects without a release-branch-prefix."
else
echo "::notice::Branch $REF is not a release branch, but somehow no projects lack a release-branch-prefix?"
exit 0
fi
fi
EXIT=0
TOPUSH=()
while IFS= read -r SLUG; do
echo "Checking $SLUG..."
cd "$GITHUB_WORKSPACE/projects/$SLUG"
CHANGES_DIR=$(jq -r '.extra.changelogger["changes-dir"] // "changelog"' composer.json)
if [[ ! -d "$CHANGES_DIR" || -n "$(ls -- "$CHANGES_DIR")" ]]; then
echo " Project $SLUG has changes in projects/$SLUG/$CHANGES_DIR/, not tagging."
continue
fi
VER=$(sed -nEe 's/^## \[?([^]]*)\]? - .*/\1/;T;p;q' CHANGELOG.md || true)
echo " Version from changelog is ${VER:-<unknown>}"
if [[ "$VER" =~ ^[0-9]+(\.[0-9]+)+$ ]]; then
if [[ -n "$( git tag -l "$SLUG@$VER" )" ]]; then
echo " Version $VER is already tagged"
else
echo " Version $VER ok to tag"
if git tag "$SLUG@$VER"; then
TOPUSH+=( "$SLUG@$VER" )
else
echo " \`git tag $SLUG@$VER\` failed"
EXIT=1
fi
fi
else
echo " Not tagging version $VER"
fi
done <<<"$PROJECTS"
if [[ ${#TOPUSH[@]} -gt 0 ]]; then
echo "Pushing tags..."
# GitHub has a limit on the number of tags that can be updated in a single push. So do them in batches.
# See https://github.blog/changelog/2022-06-15-block-potentially-destructive-git-pushes/
DONE=()
while [[ ${#TOPUSH[@]} -gt 0 ]]; do
BATCH=( "${TOPUSH[@]:0:5}" )
if git push origin "${BATCH[@]}"; then
DONE+=( "${BATCH[@]}" )
else
echo "::error::Failed to create tags: ${BATCH[*]}"
EXIT=1
fi
TOPUSH=( "${TOPUSH[@]:5}" )
done
if [[ ${#DONE[@]} -gt 0 ]]; then
echo "::notice::Created tags: ${DONE[*]}"
fi
else
echo "::notice::No tags needed creation."
fi
exit $EXIT