Skip to content

Commit b8f0db6

Browse files
authored
ci: Use custom script to release workflows/actions independently (#144)
1 parent fbf1c55 commit b8f0db6

6 files changed

Lines changed: 176 additions & 175 deletions

File tree

.github/release-please-config.json

Lines changed: 0 additions & 66 deletions
This file was deleted.

.github/release-please-manifest.json

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Decide whether the given component needs a new semver tag.
4+
#
5+
# Reads:
6+
# COMPONENT - component name (e.g. reusable-workflow-1)
7+
# INCLUDE_PATH - path filter passed to `git log -- <path>`
8+
#
9+
# Writes (when GITHUB_OUTPUT is set, i.e. running under GitHub Actions):
10+
# release=true|false
11+
# tag=<component>/v<new-version> (only when release=true)
12+
# version=<new-version> (only when release=true)
13+
14+
set -euo pipefail
15+
16+
: "${COMPONENT:?COMPONENT must be set}"
17+
: "${INCLUDE_PATH:?INCLUDE_PATH must be set}"
18+
19+
if [ ! -e "$INCLUDE_PATH" ]; then
20+
echo "INCLUDE_PATH '$INCLUDE_PATH' does not exist" >&2
21+
exit 1
22+
fi
23+
24+
emit() {
25+
if [ -n "${GITHUB_OUTPUT:-}" ]; then
26+
echo "$1" >> "$GITHUB_OUTPUT"
27+
fi
28+
}
29+
30+
LATEST_TAG=$(git tag -l "${COMPONENT}/v[0-9]*.[0-9]*.[0-9]*" --sort=-v:refname | head -n1 || true)
31+
if [ -z "$LATEST_TAG" ]; then
32+
CURRENT_VER="0.0.0"
33+
RANGE="HEAD"
34+
BUMP="minor"
35+
echo "No previous tag found for ${COMPONENT}, treating as new component (initial release will be at least 0.1.0)"
36+
else
37+
CURRENT_VER="${LATEST_TAG#"${COMPONENT}"/v}"
38+
RANGE="${LATEST_TAG}..HEAD"
39+
echo "Current version: ${CURRENT_VER} (from tag ${LATEST_TAG})"
40+
fi
41+
42+
mapfile -t SUBJECTS < <(git log "$RANGE" --first-parent --format='%s' -- "$INCLUDE_PATH")
43+
echo "Found ${#SUBJECTS[@]} commits affecting ${INCLUDE_PATH} since ${LATEST_TAG:-<initial>}"
44+
45+
BUMP="${BUMP:-}"
46+
for subject in "${SUBJECTS[@]}"; do
47+
[ -z "$subject" ] && continue
48+
echo " - ${subject}"
49+
if echo "$subject" | grep -qE '^[a-zA-Z]+(\([^)]+\))?!:'; then
50+
echo " → BREAKING CHANGE found in: ${subject}"
51+
echo " → Major bump triggered by: ${subject}"
52+
BUMP="major"
53+
break
54+
fi
55+
TYPE=$(echo "$subject" | sed -E 's/^([a-zA-Z]+).*/\1/')
56+
case "$TYPE" in
57+
feat)
58+
if [ "$BUMP" != "minor" ]; then
59+
echo " → Minor bump triggered by: ${subject}"
60+
BUMP="minor"
61+
fi
62+
;;
63+
fix|perf|chore|docs|refactor|revert)
64+
[ -z "$BUMP" ] && BUMP="patch"
65+
;;
66+
esac
67+
done
68+
69+
if [ -z "$BUMP" ]; then
70+
echo "No release needed for ${COMPONENT} (latest=${LATEST_TAG})"
71+
emit "release=false"
72+
exit 0
73+
fi
74+
75+
IFS='.' read -r MAJ MIN PAT <<< "$CURRENT_VER"
76+
case "$BUMP" in
77+
major) NEW_VER="$((MAJ+1)).0.0" ;;
78+
minor) NEW_VER="${MAJ}.$((MIN+1)).0" ;;
79+
patch) NEW_VER="${MAJ}.${MIN}.$((PAT+1))" ;;
80+
esac
81+
NEW_TAG="${COMPONENT}/v${NEW_VER}"
82+
echo "Will release ${NEW_TAG} from ${LATEST_TAG:-<initial>} (bump=${BUMP})"
83+
emit "release=true"
84+
emit "tag=${NEW_TAG}"
85+
emit "version=${NEW_VER}"

.github/workflows/release-please.yaml

Lines changed: 0 additions & 52 deletions
This file was deleted.

.github/workflows/release.yaml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Release workflows/actions
2+
3+
on:
4+
push:
5+
branches: [main]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
11+
concurrency:
12+
group: release-${{ github.ref }}
13+
cancel-in-progress: false
14+
15+
jobs:
16+
release:
17+
name: Release ${{ matrix.component.name }}
18+
runs-on: ubuntu-latest
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
component:
23+
- { name: build_container_image, path: .github/workflows/build_container_image.yml }
24+
- { name: build_node_package, path: .github/workflows/build_node_package.yml }
25+
- { name: build_node_package_with_pgsql, path: .github/workflows/build_node_package_with_pgsql.yml }
26+
- { name: deploy_container_image, path: .github/workflows/deploy_container_image.yml }
27+
- { name: deploy_helm_chart, path: .github/workflows/deploy_helm_chart.yml }
28+
- { name: merge_multiarch_images, path: .github/workflows/merge_multiarch_images.yml }
29+
- { name: publish_node_package, path: .github/workflows/publish_node_package.yml }
30+
- { name: sast_scan, path: .github/workflows/sast_scan.yaml }
31+
- { name: npm_test, path: actions/npm_test }
32+
- { name: scan_container_image, path: actions/scan_container_image }
33+
- { name: update-nr-flows, path: actions/update-nr-flows }
34+
steps:
35+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
36+
with:
37+
fetch-depth: 0
38+
fetch-tags: true
39+
40+
- name: Compute next version
41+
id: compute-next-version
42+
env:
43+
COMPONENT: ${{ matrix.component.name }}
44+
INCLUDE_PATH: ${{ matrix.component.path }}
45+
run: bash .github/scripts/compute-next-version.sh
46+
47+
- name: Tag
48+
if: steps.compute-next-version.outputs.release == 'true'
49+
env:
50+
TAG: ${{ steps.compute-next-version.outputs.tag }}
51+
COMPONENT: ${{ matrix.component.name }}
52+
VERSION: ${{ steps.compute-next-version.outputs.version }}
53+
run: |
54+
set -euo pipefail
55+
git config user.name 'github-actions[bot]'
56+
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
57+
58+
MAJOR="${VERSION%%.*}"
59+
REST="${VERSION#*.}"
60+
MINOR="${REST%%.*}"
61+
62+
git tag -a "$TAG" -m "$TAG"
63+
git push origin "$TAG"
64+
65+
git tag -f "${COMPONENT}/v${MAJOR}"
66+
git tag -f "${COMPONENT}/v${MAJOR}.${MINOR}"
67+
git push origin -f "${COMPONENT}/v${MAJOR}" "${COMPONENT}/v${MAJOR}.${MINOR}"

0 commit comments

Comments
 (0)