Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Automatically tag project releases #34261

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions .github/workflows/autotagger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Monorepo Auto-tagger

on:
push:
branches:
- trunk
- prerelease
- '*/branch-*'

jobs:
tag:
name: Tag
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Fetch tags, shallowly and treeless
run: |
git fetch --depth=1 --filter=tree:0 origin 'refs/tags/*:refs/tags/*'

- name: Tag projects
run: |
REF=${GITHUB_REF#refs/heads/}
if [[ "$REF" == */branch-* ]]; then
PROJECTS="$(jq -r --arg P "${REF%%/branch-*}" '.extra["release-branch-prefix"] | if type == "array" then . else [ . ] end | if index( $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

TAGS=()
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
echo " Version $VER ok to tag"
TAGS+=( "$SLUG@$VER" )
else
echo " Not tagging version $VER"
fi
done <<<"$PROJECTS"

if [[ ${#TAGS[@]} -eq 0 ]]; then
echo "::notice::Nothing to tag."
exit 0
fi

export GIT_AUTHOR_NAME=matticbot
export GIT_AUTHOR_EMAIL=matticbot@users.noreply.github.com
export GIT_COMMITTER_NAME=matticbot
export GIT_COMMITTER_EMAIL=matticbot@users.noreply.github.com

echo "Creating tags..."
TOPUSH=()
for T in "${TAGS[@]}"; do
if git tag "$T"; then
TOPUSH+=( "$T" )
fi
done
if [[ ${#TOPUSH[@]} -gt 0 ]]; then
echo "Pushing tags..."
git push origin "${TOPUSH[@]}"
echo "::notice::Created tags: ${TOPUSH[*]}"
else
echo "::notice::No tags needed creation."
fi
Loading