-
Notifications
You must be signed in to change notification settings - Fork 97
129 lines (113 loc) · 4.94 KB
/
Copy pathpublish.yml
File metadata and controls
129 lines (113 loc) · 4.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: publish
on:
push:
branches:
- 'dev'
tags:
- 'writer-framework-[0-9]+.[0-9]+.[0-9]+'
workflow_dispatch:
inputs:
commit_sha:
description: 'Commit SHA to publish'
required: true
version:
description: 'Version to publish (optional, overrides calculated version)'
required: false
concurrency:
group: publish-writer-framework
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
version: ${{ steps.set_version.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
ref: ${{ github.event.inputs.commit_sha || github.ref_name }}
- name: Set up Python
uses: actions/setup-python@v5
with:
cache: 'poetry'
- name: Install dependencies
run: pip install poetry requests packaging semver
- name: Determine next RC version
id: bump_version
if: github.ref_name == 'dev'
run: |
python - <<'EOF'
import os, re, requests, subprocess, semver, packaging.version
data = requests.get(f"https://pypi.org/pypi/writer/json", timeout=10).json()
releases = sorted(
(v for v in data["releases"] if not packaging.version.parse(v).is_prerelease),
key=packaging.version.parse
)
latest = releases[-1]
print("Latest stable:", latest)
log = subprocess.check_output(
["git", "log", f"writer-framework-{latest}..HEAD", "--pretty=%s"],
text=True
)
base = semver.VersionInfo.parse(latest)
new_version = base.bump_minor() if re.search(r"^feat:", log, re.M) else base.bump_patch()
rc_prefix = str(new_version)
rc_versions = [v for v in data["releases"] if v.startswith(rc_prefix) and "rc" in v]
rc_numbers = [int(re.search(r"rc(\d+)", v).group(1)) for v in rc_versions]
rc_num = max(rc_numbers) + 1 if rc_numbers else 1
final = f"{rc_prefix}rc{rc_num}"
print("Next RC:", final)
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
f.write(f"version={final}\n")
EOF
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "22.x"
cache: npm
- name: Determine final version
id: set_version
run: |
# Determine version based on workflow inputs or tags
if [ -n "${{ github.event.inputs.version }}" ]; then
VERSION="${{ github.event.inputs.version }}"
elif [ "${GITHUB_REF_NAME}" = "dev" ]; then
VERSION="${{ steps.bump_version.outputs.version }}"
elif [[ "$GITHUB_REF" == refs/tags/* ]]; then
TAG_NAME="${GITHUB_REF#refs/tags/}"
VERSION="${TAG_NAME#writer-framework-}"
else
echo "Unable to determine version"
exit 1
fi
echo "Final version: $VERSION"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Update version before publishing
run: |
poetry version ${{ steps.set_version.outputs.version }}
poetry install --with build
WRITER_FRAMEWORK_VERSION=${{ steps.set_version.outputs.version }} poetry run alfred install.ci
WRITER_FRAMEWORK_VERSION=${{ steps.set_version.outputs.version }} poetry run alfred publish.pypi
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
- name: Create and push tag for RC (only dev)
if: github.ref_name == 'dev'
run: |
TAG="writer-framework-${{ steps.bump_version.outputs.version }}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "$TAG" -m "Release $TAG"
git push origin "$TAG"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
trigger-agent-manager:
needs: build
if: github.ref_name == 'dev'
uses: ./.github/workflows/trigger-workflow.yml
with:
event_type: framework_updated
extra_payload: '{"tag": "writer-framework-${{ needs.build.outputs.version }}", "version": "${{ needs.build.outputs.version }}"}'
secrets:
AGENT_MANAGER_PAT: ${{ secrets.AGENT_MANAGER_PAT }}