Skip to content

Commit 922cd87

Browse files
authored
feat: add shared workflows (#143)
1 parent 9e1624d commit 922cd87

File tree

4 files changed

+90
-58
lines changed

4 files changed

+90
-58
lines changed

.github/workflows/cd.yml

Lines changed: 35 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- main
7+
workflow_dispatch:
78

89
permissions:
910
contents: write
@@ -14,50 +15,27 @@ jobs:
1415
# ====================================================
1516
# Versioning and Release
1617
# ====================================================
17-
versioning:
18-
name: versioning
19-
runs-on: ubuntu-latest
20-
outputs:
21-
new_release_version: ${{ steps.set-outputs.outputs.version }}
22-
new_release_published: ${{ steps.set-outputs.outputs.published }}
23-
steps:
24-
- name: Checkout
25-
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
26-
with:
27-
fetch-depth: 0
28-
29-
- name: Check existing release
30-
id: check-release
31-
run: |
32-
CURRENT_SHA=$(git rev-parse HEAD)
33-
EXISTING_TAG=$(git tag --points-at $CURRENT_SHA | grep '^v' | head -1)
34-
if [ -n "$EXISTING_TAG" ]; then
35-
echo "existing_tag=$EXISTING_TAG" >> $GITHUB_OUTPUT
36-
echo "existing_version=${EXISTING_TAG#v}" >> $GITHUB_OUTPUT
37-
echo "has_existing=true" >> $GITHUB_OUTPUT
38-
else
39-
echo "has_existing=false" >> $GITHUB_OUTPUT
40-
fi
41-
42-
- id: release
43-
name: Release
44-
if: steps.check-release.outputs.has_existing == 'false'
45-
uses: cycjimmy/semantic-release-action@b12c8f6015dc215fe37bc154d4ad456dd3833c90 # v6.0.0
46-
env:
47-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48-
49-
- name: Set outputs
50-
id: set-outputs
51-
run: |
52-
if [ "${{ steps.check-release.outputs.has_existing }}" == "true" ]; then
53-
echo "version=${{ steps.check-release.outputs.existing_version }}" >> $GITHUB_OUTPUT
54-
echo "published=true" >> $GITHUB_OUTPUT
55-
echo "Using existing release: ${{ steps.check-release.outputs.existing_version }}"
56-
else
57-
echo "version=${{ steps.release.outputs.new_release_version }}" >> $GITHUB_OUTPUT
58-
echo "published=${{ steps.release.outputs.new_release_published }}" >> $GITHUB_OUTPUT
59-
echo "New release: ${{ steps.release.outputs.new_release_version }}"
60-
fi
18+
semantic-release:
19+
name: semantic-release
20+
uses: ./.github/workflows/shared-semantic-release.yml
21+
with:
22+
allowed_workflow_dispatch_branches: '["main"]'
23+
fail_on_invalid_workflow_dispatch_ref: true
24+
25+
zerv-versioning:
26+
needs: semantic-release
27+
if: needs.semantic-release.outputs.is_valid_semantic_release == 'true'
28+
uses: ./.github/workflows/shared-zerv-versioning.yml
29+
30+
create-version-prefix-tags:
31+
needs: zerv-versioning
32+
uses: ./.github/workflows/shared-create-tags.yml
33+
with:
34+
tags: >-
35+
[
36+
"${{ fromJson(needs.zerv-versioning.outputs.versions).v_semver_major }}",
37+
"${{ fromJson(needs.zerv-versioning.outputs.versions).v_semver_major_minor }}"
38+
]
6139
6240
# ====================================================
6341
# Test and Lint
@@ -77,8 +55,8 @@ jobs:
7755
release-bin:
7856
name: release-bin-github-${{ matrix.name }}
7957
runs-on: ${{ matrix.os }}
80-
needs: versioning
81-
if: needs.versioning.outputs.new_release_published == 'true'
58+
needs: semantic-release
59+
if: needs.semantic-release.outputs.published == 'true'
8260
strategy:
8361
fail-fast: false
8462
matrix:
@@ -130,14 +108,15 @@ jobs:
130108
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
131109
132110
- name: Update Cargo.toml version
111+
shell: bash
133112
run: |
134-
echo "Updating version to ${{ needs.versioning.outputs.new_release_version }}"
113+
VERSION="${{ needs.semantic-release.outputs.version }}"
114+
echo "Updating version to $VERSION"
135115
if [[ "$RUNNER_OS" == "macOS" ]]; then
136-
sed -i '' "s/^version = \".*\"/version = \"${{ needs.versioning.outputs.new_release_version }}\"/" Cargo.toml
116+
sed -i '' "s/^version = \".*\"/version = \"$VERSION\"/" Cargo.toml
137117
else
138-
sed -i "s/^version = \".*\"/version = \"${{ needs.versioning.outputs.new_release_version }}\"/" Cargo.toml
118+
sed -i "s/^version = \".*\"/version = \"$VERSION\"/" Cargo.toml
139119
fi
140-
shell: bash
141120
142121
- name: Build binary
143122
run: cargo build --release --target ${{ matrix.target }}
@@ -148,14 +127,14 @@ jobs:
148127
repo_token: ${{ secrets.GITHUB_TOKEN }}
149128
file: target/${{ matrix.target }}/release/${{ matrix.artifact_name }}
150129
asset_name: ${{ matrix.asset_name }}
151-
tag: v${{ needs.versioning.outputs.new_release_version }}
130+
tag: v${{ needs.semantic-release.outputs.version }}
152131
overwrite: true
153132

154133
release-crates:
155134
name: release-crates
156135
runs-on: ubuntu-latest
157-
needs: [versioning, release-bin]
158-
if: needs.versioning.outputs.new_release_published == 'true'
136+
needs: [semantic-release, release-bin]
137+
if: needs.semantic-release.outputs.published == 'true'
159138
steps:
160139
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
161140

@@ -165,8 +144,9 @@ jobs:
165144

166145
- name: Update Cargo.toml version
167146
run: |
168-
echo "Updating version to ${{ needs.versioning.outputs.new_release_version }}"
169-
sed -i "s/^version = \".*\"/version = \"${{ needs.versioning.outputs.new_release_version }}\"/" Cargo.toml
147+
VERSION="${{ needs.semantic-release.outputs.version }}"
148+
echo "Updating version to $VERSION"
149+
sed -i "s/^version = \".*\"/version = \"$VERSION\"/" Cargo.toml
170150
171151
- name: Release to crates.io
172152
run: |
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: create-tags
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
tags:
7+
description: 'JSON array of tags to create (e.g., ["v1", "v1.2"])'
8+
required: true
9+
type: string
10+
11+
permissions:
12+
contents: write
13+
14+
jobs:
15+
create-tags:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Create or move tags and push
22+
run: |
23+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
24+
git config --local user.name "github-actions[bot]"
25+
26+
# Parse JSON array of tags
27+
TAGS='${{ inputs.tags }}'
28+
echo "Creating tags: $TAGS"
29+
30+
# Create and push each tag
31+
echo "$TAGS" | jq -r '.[]' | while read -r tag; do
32+
git tag -fa "$tag" -m "$tag"
33+
git push origin "$tag" --force
34+
echo " - $tag"
35+
done
36+
37+
echo "All tags created/moved and pushed successfully"
38+
39+
- name: Verify tags
40+
run: |
41+
echo "Verifying tags on current commit..."
42+
git fetch --tags
43+
git tag --points-at HEAD

.github/workflows/shared-lock.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ jobs:
130130
shell: bash
131131
run: |
132132
echo "Waiting for lock to propagate..."
133-
sleep 1
133+
sleep 2
134134
135135
# Recheck lock state after lock
136136
- name: Get lock state for recheck

.github/workflows/shared-zerv-versioning.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,21 @@ on:
4545
type: string
4646
required: false
4747
description: "JSON object mapping output names to zerv output formats"
48-
default: '{"semver": "semver", "pep440": "pep440"}'
48+
default: >-
49+
{
50+
"semver": "semver",
51+
"pep440": "pep440"
52+
}
4953
output_templates:
5054
type: string
5155
required: false
5256
description: "JSON object mapping output names to zerv output templates (without quotes)"
53-
default: '{"docker_tag": "{{ semver_obj.docker }}"}'
57+
default: >-
58+
{
59+
"docker_tag": "{{ semver_obj.docker }}",
60+
"v_semver_major": "v{{ major }}",
61+
"v_semver_major_minor": "v{{ major }}.{{ minor }}"
62+
}
5463
custom_outputs:
5564
type: string
5665
required: false

0 commit comments

Comments
 (0)