Skip to content

Commit 4418fd3

Browse files
authored
Workflow to tag flow-api-client versions (#4532)
This PR adds a workflow encoding the steps required to tag a new flow-api-client release. It takes the released version as an optional input, resolving to the latest flow-api-client with the patch increased if no version is provided.
1 parent 8a28958 commit 4418fd3

1 file changed

Lines changed: 110 additions & 0 deletions

File tree

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: flow-api-client-tag
2+
3+
# Manually tags a release of the generated flow-api-client.
4+
#
5+
# The `flow-api-client` workflow keeps the long-lived `flow-api-client` branch in
6+
# sync with the generated proto Go files on every push to `main`. This workflow
7+
# publishes a consumable version by pushing a `flow-api-client/vX.Y.Z` tag that
8+
# points at the current tip of that branch.
9+
#
10+
# NOTE: GitHub Actions cannot dynamically pre-fill a workflow_dispatch input, so
11+
# the version box cannot be seeded with "latest + 1" in the UI. Instead, leave
12+
# the `version` input blank and the workflow auto-increments the patch level of
13+
# the latest existing flow-api-client/vX.Y.Z tag.
14+
15+
on:
16+
workflow_dispatch:
17+
inputs:
18+
version:
19+
description: >-
20+
flow-api-client version to publish (template X.Y.Z, tagged as
21+
flow-api-client/vX.Y.Z). Leave blank to auto-increment the patch level
22+
of the latest existing flow-api-client tag.
23+
Make sure your changes have been merged to the flow-api-client branch before running this workflow.
24+
You can check the history of completed syncs at https://github.com/PeerDB-io/peerdb/actions/workflows/flow-api-client.yml
25+
required: false
26+
type: string
27+
default: ''
28+
29+
concurrency:
30+
group: flow-api-client-tag
31+
cancel-in-progress: false
32+
33+
jobs:
34+
tag:
35+
runs-on: ubuntu-latest
36+
permissions:
37+
contents: write
38+
steps:
39+
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
40+
41+
- name: Fetch flow-api-client branch and existing tags
42+
shell: bash
43+
run: |
44+
set -euo pipefail
45+
# Latest state of the branch we will tag.
46+
git fetch --no-tags origin \
47+
'+refs/heads/flow-api-client:refs/remotes/origin/flow-api-client'
48+
# Only the flow-api-client/* tags (ignores unrelated / malformed tags).
49+
git fetch --no-tags origin \
50+
'+refs/tags/flow-api-client/*:refs/tags/flow-api-client/*'
51+
52+
- name: Resolve version
53+
id: resolve
54+
# Only needed to derive the next version; skipped entirely when an explicit version is given.
55+
if: ${{ inputs.version == '' }}
56+
shell: bash
57+
run: |
58+
set -euo pipefail
59+
60+
latest="$(git tag -l 'flow-api-client/v[0-9]*.[0-9]*.[0-9]*' \
61+
| sed 's|^flow-api-client/v||' \
62+
| grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' \
63+
| sort --version-sort \
64+
| tail -1)"
65+
if [ -z "$latest" ]; then
66+
echo "::error::No existing flow-api-client/vX.Y.Z tag found; provide an explicit version input."
67+
exit 1
68+
fi
69+
70+
IFS=. read -r major minor patch <<< "$latest"
71+
version="${major}.${minor}.$((patch + 1))"
72+
echo "Latest tag flow-api-client/v${latest} -> next flow-api-client/v${version}"
73+
echo "version=${version}" >> "$GITHUB_OUTPUT"
74+
75+
- name: Create and push tag
76+
shell: bash
77+
env:
78+
INPUT_VERSION: ${{ inputs.version }}
79+
RESOLVED_VERSION: ${{ steps.resolve.outputs.version }}
80+
run: |
81+
set -euo pipefail
82+
83+
version="${INPUT_VERSION#v}"
84+
version="${version:-$RESOLVED_VERSION}"
85+
86+
if ! printf '%s' "$version" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
87+
echo "::error::Version '${version}' does not match the X.Y.Z template."
88+
exit 1
89+
fi
90+
91+
tag="flow-api-client/v${version}"
92+
if git rev-parse -q --verify "refs/tags/${tag}" >/dev/null; then
93+
echo "::error::Tag ${tag} already exists."
94+
exit 1
95+
fi
96+
97+
git config user.name "github-actions[bot]"
98+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
99+
100+
target="$(git rev-parse refs/remotes/origin/flow-api-client)"
101+
echo "Tagging flow-api-client tip ${target} as ${tag}"
102+
103+
git tag -a "${tag}" "${target}" -m "${tag}"
104+
git push origin "refs/tags/${tag}"
105+
106+
{
107+
echo "### Published \`${tag}\`"
108+
echo ""
109+
echo "- Branch tip: \`${target}\`"
110+
} >> "$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)