Skip to content

Commit 0183d5c

Browse files
committed
feat: use commitizen to control versions of this repository
In addition, automatically track the major/0.x series as a branch, allowing downstream use of SemVer for this repository. Also create GitHub releases on new tags. NOTE: workflows must be in workflow folder, so these "private" workflows meant to maintain the repository, instead of being consumed by other repositories, have a preceding underscore in their name.
1 parent ff6ce24 commit 0183d5c

5 files changed

Lines changed: 186 additions & 1 deletion

File tree

.cz.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[tool.commitizen]
2+
name = "cz_conventional_commits"
3+
tag_format = "v$version"
4+
version_scheme = "semver"
5+
version = "0.3.2"
6+
update_changelog_on_bump = true
7+
major_version_zero = true

.github/workflows/_bump-call.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# This is NOT a reusable workflow, and is not part of the public API.
2+
#
3+
# This workflow is triggered by a push to the main branch or manually via
4+
# workflow_dispatch. It runs the bump version job to update the package
5+
# version in the repository. The job will only run if the last commit message
6+
# does not start with 'bump:'. This is to prevent accidental bumps when the
7+
# commit message is not intended to trigger a version bump.
8+
#
9+
# * The bumped version is pushed to the repository.
10+
# * The workflow uses a service token for authentication.
11+
# * The concurrency group ensures that only one bump job runs at a time for the
12+
# same branch.
13+
# * The workflow runs on the main branch.
14+
name: Bump Version
15+
16+
on:
17+
push:
18+
branches: [ main ]
19+
workflow_dispatch:
20+
21+
permissions:
22+
contents: write # needed to push commits/tags
23+
id-token: write # needed if your reusable workflow exchanges OIDC tokens
24+
25+
concurrency:
26+
group: bump-${{ github.workflow }}-${{ github.ref_name }}
27+
cancel-in-progress: true
28+
29+
jobs:
30+
bump:
31+
# Only run when:
32+
# • There was a push to main and the head commit message doesn't start
33+
# with 'bump:'
34+
# • OR this is a manual dispatch
35+
if: >
36+
(github.event_name == 'push' &&
37+
github.ref == 'refs/heads/main' &&
38+
!startsWith(github.event.head_commit.message, 'bump:')) ||
39+
(github.event_name == 'workflow_dispatch' &&
40+
github.ref == 'refs/heads/main')
41+
uses: ./.github/workflows/bump-version.yml
42+
with:
43+
default-branch: main
44+
secrets:
45+
repo-token: ${{ secrets.SERVICE_TOKEN }}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# This is NOT a reusable workflow, and is not part of the public API.
2+
#
3+
# This workflow is triggered by a push to a version tag (e.g. v1.2.3) or
4+
# manually via workflow_dispatch. It moves the commit pointed to by the tag to
5+
# a major branch (e.g. v1, v2, etc.). For v0.x.y releases, it creates branches
6+
# like v0.x (e.g. v0.3 for v0.3.5). If the major branch already exists, it
7+
# will reset it to the commit of the tag. If it does not exist, it will create
8+
# the branch at the commit of the tag.
9+
name: "Move/update major branch"
10+
11+
on:
12+
push:
13+
tags:
14+
- 'v[0-9]+\.[0-9]+\.[0-9]+'
15+
workflow_dispatch:
16+
inputs:
17+
tag:
18+
description: "Tag to process (e.g. v3.2.1 creates v3 branch, v0.3.5 creates v0.3 branch)"
19+
required: true
20+
21+
permissions:
22+
contents: write
23+
24+
concurrency:
25+
group: move-major-branch
26+
cancel-in-progress: false
27+
28+
jobs:
29+
move-major-branch:
30+
runs-on: ubuntu-latest
31+
steps:
32+
# 1) Check out repo so we can move branches
33+
- name: Check out repository
34+
uses: actions/checkout@v4
35+
with:
36+
fetch-depth: 0
37+
token: ${{ secrets.SERVICE_TOKEN }}
38+
39+
# 2) Work out which tag & commit we’re supposed to handle
40+
- name: Determine tag & commit
41+
id: vars
42+
run: |
43+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
44+
TAG="${{ inputs.tag }}"
45+
# Make sure the tag exists locally
46+
if ! git rev-parse -q --verify "refs/tags/${TAG}" >/dev/null; then
47+
echo "::error::Tag '${TAG}' not found in origin; did you push it?"
48+
exit 1
49+
fi
50+
COMMIT=$(git rev-parse "refs/tags/${TAG}^{commit}")
51+
else
52+
TAG="${GITHUB_REF#refs/tags/}"
53+
COMMIT="${GITHUB_SHA}"
54+
fi
55+
56+
# Extract the target branch based on semver, handling v0.x.y specially
57+
if [[ "${TAG}" =~ ^v0\. ]]; then
58+
# For v0.x.y releases, use v0.x as the target branch
59+
TARGET_BRANCH=$(echo "${TAG}" | cut -d. -f1,2) # e.g. v0.3.5 -> v0.3
60+
else
61+
# For v1.x.y and above, use just the major version
62+
TARGET_BRANCH="${TAG%%.*}" # e.g. v1.2.3 -> v1
63+
fi
64+
65+
echo "tag=${TAG}" >>"$GITHUB_OUTPUT"
66+
echo "commit=${COMMIT}" >>"$GITHUB_OUTPUT"
67+
echo "target_branch=${TARGET_BRANCH}" >>"$GITHUB_OUTPUT"
68+
69+
70+
# 3) Fast‑forward or create the major branch
71+
- name: Move or create major branch
72+
env:
73+
TARGET_BRANCH: ${{ steps.vars.outputs.target_branch }}
74+
COMMIT: ${{ steps.vars.outputs.commit }}
75+
run: |
76+
set -euo pipefail
77+
78+
git config user.name "github-actions[bot]"
79+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
80+
81+
if git ls-remote --exit-code --heads origin "$TARGET_BRANCH" >/dev/null; then
82+
echo "Resetting branch $TARGET_BRANCH to $COMMIT"
83+
git branch -f "$TARGET_BRANCH" "$COMMIT"
84+
else
85+
echo "Creating new branch $TARGET_BRANCH at $COMMIT"
86+
git branch "$TARGET_BRANCH" "$COMMIT"
87+
fi
88+
git push origin "$COMMIT:refs/heads/$TARGET_BRANCH" --force-with-lease

.github/workflows/_publish.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# This is NOT a reusable workflow, and is not part of the public API.
2+
#
3+
# This workflow is triggered by a push to a version tag (e.g. v1.2.3) or
4+
# manually via workflow_dispatch. It creates a GitHub release and uploads the
5+
# built artifacts.
6+
# * The concurrency group ensures that only one release job runs at a time.
7+
name: "Release"
8+
9+
on:
10+
push:
11+
tags:
12+
- 'v[0-9]+\.[0-9]+\.[0-9]+' # semver tags
13+
workflow_dispatch:
14+
15+
permissions:
16+
contents: write # create release + upload assets
17+
18+
concurrency:
19+
group: release
20+
cancel-in-progress: false # let releases finish
21+
22+
jobs:
23+
Release:
24+
runs-on: ubuntu-latest
25+
# only run on a tag push, or on a manual dispatch *where* the user has
26+
# selected a tag ref (i.e. github.ref starts with refs/tags/)
27+
if: startsWith(github.ref, 'refs/tags/')
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
with:
32+
# on push this is already the tag ref; on dispatch you must choose
33+
# the tag in the UI so github.ref is the tag
34+
ref: ${{ github.ref }}
35+
fetch-depth: 0
36+
- name: Create GitHub release
37+
uses: softprops/action-gh-release@v2
38+
with:
39+
tag_name: ${{ github.ref_name }}
40+
name: Release ${{ github.ref_name }}
41+
generate_release_notes: true
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ aind-github-actions
55

66
## This repository is for workflows that may be reused in other workflows and repositories.
77

8-
GitHub actions workflows are found in .github/workflows.
8+
GitHub actions workflows are found in .github/workflows. Any workflows that have
9+
an underscore at the start of their name are NOT part of the API, and are
10+
internal to this repository.
911

1012
Example calling workflows are in `examples/`
1113

0 commit comments

Comments
 (0)