Skip to content

Commit 31a4216

Browse files
authored
Merge pull request #6 from jorgesolebur/feature/setupPreReleasePreview
Feature/setup pre release preview
2 parents 73dfa2f + 4ace7fb commit 31a4216

6 files changed

Lines changed: 217 additions & 10 deletions

File tree

.github/workflows/pr-labeler.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Add Default PR Label
2+
3+
on:
4+
pull_request:
5+
types: [opened]
6+
7+
jobs:
8+
add-label:
9+
name: Add default semver label
10+
runs-on: ubuntu-latest
11+
permissions:
12+
pull-requests: write
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Add semver:dev label if no other semver label exists
16+
env:
17+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18+
PR_NUMBER: ${{ github.event.pull_request.number }}
19+
run: |
20+
LABELS=$(gh pr view "$PR_NUMBER" --json labels --jq '.labels.[].name' 2>/dev/null || echo "")
21+
if ! echo "$LABELS" | grep -q "semver:"; then
22+
echo "No semver label found. Adding semver:dev."
23+
gh pr edit "$PR_NUMBER" --add-label "semver:dev"
24+
else
25+
echo "A semver label is already present. Skipping."
26+
fi

.github/workflows/pre-release.yml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: Draft release pull request
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- main
8+
9+
concurrency:
10+
group: ${{ github.workflow }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
generate-changelog:
15+
name: Create a PR to update version and release notes
16+
if: github.event.pull_request.merged == true
17+
permissions:
18+
contents: write
19+
actions: write
20+
pull-requests: write
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0 # Needed to get all tags for changelog generation
26+
- name: Set up Python 3.12
27+
uses: actions/setup-python@v4
28+
with:
29+
python-version: 3.12
30+
cache: pip
31+
- name: Install build tool
32+
run: python -m pip install hatch
33+
- name: Determine Version Bump from PR Labels
34+
id: version
35+
run: |
36+
BUMP="patch"
37+
LABELS='${{ toJSON(github.event.pull_request.labels.*.name) }}'
38+
echo "Checking labels: $LABELS"
39+
if echo "$LABELS" | grep -q "semver:major"; then
40+
BUMP="major"
41+
elif echo "$LABELS" | grep -q "semver:minor"; then
42+
BUMP="minor"
43+
elif echo "$LABELS" | grep -q "semver:alpha"; then
44+
BUMP="alpha"
45+
elif echo "$LABELS" | grep -q "semver:beta"; then
46+
BUMP="beta"
47+
elif echo "$LABELS" | grep -q "semver:preview"; then
48+
BUMP="preview"
49+
elif echo "$LABELS" | grep -q "semver:dev"; then
50+
BUMP="dev"
51+
fi
52+
echo "Version bump determined: $BUMP"
53+
echo "level=${BUMP}" >> $GITHUB_OUTPUT
54+
- name: Bump version
55+
run: hatch version ${{ steps.version.outputs.level }}
56+
- name: Generate release notes
57+
if: steps.version.outputs.level == 'major' || steps.version.outputs.level == 'minor' || steps.version.outputs.level == 'patch' || steps.version.outputs.level == 'beta'
58+
id: changelog
59+
env:
60+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
run: |
62+
# This will be empty if there are no releases yet
63+
PREVIOUS_VERSION=$(gh release view --json tagName --jq .tagName 2>/dev/null || echo "")
64+
NEXT_VERSION="v$(hatch version)"
65+
echo "## $NEXT_VERSION ($(date -I))" > changelog.md
66+
67+
# Build arguments for the API call
68+
ARGS=("--method" "POST" "-H" "Accept: application/vnd.github.v3+json" "/repos/SFDO-Tooling/CumulusCI/releases/generate-notes" "-f" "target_commitish=main" "-f" "tag_name=$NEXT_VERSION")
69+
if [ -n "$PREVIOUS_VERSION" ]; then
70+
echo "Generating notes between $PREVIOUS_VERSION and $NEXT_VERSION"
71+
ARGS+=("-f" "previous_tag_name=$PREVIOUS_VERSION")
72+
else
73+
echo "No previous release found. Generating notes for the first release."
74+
fi
75+
76+
gh api "${ARGS[@]}" --jq '.body' |
77+
sed -e 's_\(https.*\/\)\([0-9]*\)$_[#\2](\1\2)_' \
78+
-e 's_by @\(.*\) in_by [@\1](https://github.com/\1) in_' >> changelog.md
79+
python utility/update-history.py
80+
- name: Lint history
81+
if: steps.version.outputs.level == 'major' || steps.version.outputs.level == 'minor' || steps.version.outputs.level == 'patch' || steps.version.outputs.level == 'beta'
82+
run: |
83+
npm install prettier
84+
npx prettier --write docs/history.md
85+
- name: Commit version and changelog
86+
run: |
87+
BRANCH_NAME="release-$(hatch version)"
88+
git config user.name github-actions[bot]
89+
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
90+
git switch -c "$BRANCH_NAME"
91+
git add docs/history.md cumulusci/__about__.py
92+
git commit -m "Update changelog (automated)"
93+
# Delete the remote branch if it exists, ignoring errors if it doesn't.
94+
git push origin --delete "$BRANCH_NAME" || true
95+
# Push the new branch.
96+
git push origin "$BRANCH_NAME"
97+
- name: Create and Merge Release PR
98+
env:
99+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
100+
run: |
101+
PR_URL=$(gh pr create --title "Release v$(hatch version)" --fill --label 'auto-pr')
102+
if [ -n "$PR_URL" ]; then
103+
echo "Created PR: $PR_URL"
104+
gh pr merge "$PR_URL" --merge --delete-branch
105+
echo "PR merged and branch deleted."
106+
else
107+
echo "PR creation failed."
108+
exit 1
109+
fi
110+
- name: Call Release Workflow
111+
uses: benc-uk/workflow-dispatch@v1
112+
with:
113+
workflow: "Publish and release CumulusCI"
114+
token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yml

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,59 @@
1-
name: Publish and release cumulusci-plus-azure-devops
1+
name: Publish and release CumulusCI
22

33
on:
4+
workflow_dispatch:
45
push:
56
branches:
67
- main
78
paths:
8-
- cumulusci_ado/__about__.py
9+
- cumulusci/__about__.py
910

1011
concurrency: publishing
1112

1213
jobs:
1314
publish-to-pypi:
1415
name: Publish new release to PyPI
16+
permissions:
17+
contents: write
1518
runs-on: ubuntu-latest
1619
steps:
17-
- uses: actions/checkout@v4
18-
- name: Set up Python
20+
- uses: actions/checkout@main
21+
- name: Set up Python 3.12
1922
uses: actions/setup-python@v4
2023
with:
21-
python-version: "3.12"
24+
python-version: 3.12
25+
cache: pip
2226
- name: Install build tools
23-
run: pip install hatch
24-
- name: Build package
27+
run: python -m pip install hatch tomli tomli-w
28+
- name: Check version type
29+
id: version_check
30+
run: |
31+
VERSION=$(hatch version)
32+
echo "Current version: $VERSION"
33+
IS_PUBLISHABLE="false"
34+
# Publish only stable and preview releases, which do not contain letters like a,b,d or "rc".
35+
if ! [[ "$VERSION" =~ [abd] ]] && ! [[ "$VERSION" =~ "rc" ]]; then
36+
IS_PUBLISHABLE="true"
37+
fi
38+
echo "publishable=${IS_PUBLISHABLE}" >> $GITHUB_OUTPUT
39+
- name: Build source tarball and binary wheel
40+
if: steps.version_check.outputs.publishable == 'true'
2541
run: hatch build -c
26-
- name: Publish to PyPI
42+
- name: Upload to PyPI
43+
if: steps.version_check.outputs.publishable == 'true'
44+
run: hatch publish
2745
env:
2846
HATCH_INDEX_USER: "__token__"
2947
HATCH_INDEX_AUTH: ${{ secrets.PYPI_TOKEN }}
30-
# HATCH_INDEX_REPO: ${{ vars.PYPI_REPO }} # Uncomment if you have a specific repository
31-
run: hatch publish
48+
- name: Create release
49+
if: steps.version_check.outputs.publishable == 'true'
50+
env:
51+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
run: |
53+
VERSION="$(hatch version)"
54+
awk '/<!-- latest-start -->/,/<!-- latest-stop -->/' docs/history.md > changelog.md
55+
gh release create "v$VERSION" \
56+
dist/*.whl \
57+
dist/*.tar.gz \
58+
--notes-file changelog.md \
59+
--title $VERSION

docs/history.md

Whitespace-only changes.

utility/generate-release-notes.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import os
2+
3+
import click
4+
5+
6+
@click.command()
7+
@click.option("--prev", required=True, help="Previous version tag")
8+
@click.option("--next", required=True, help="Next version tag")
9+
def main(prev, next):
10+
os.system("git fetch")
11+
cmd = (
12+
'gh api --method POST -H "Accept: application/vnd.github.v3+json" '
13+
+ "/repos/SFDO-Tooling/CumulusCI/releases/generate-notes"
14+
+ f" -f tag_name='{next}' "
15+
+ "-f target_commitish='main' "
16+
+ f"-f previous_tag_name='{prev}' --jq .body "
17+
+ "| pandoc -f gfm -t rst"
18+
)
19+
print(cmd)
20+
os.system(cmd)
21+
22+
23+
if __name__ == "__main__":
24+
main()

utility/update-history.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
Update the history file.
3+
"""
4+
from pathlib import Path
5+
6+
START_MARKER = "<!-- latest-start -->"
7+
STOP_MARKER = "<!-- latest-stop -->"
8+
9+
history = Path("docs/history.md").read_text()
10+
latest = Path("changelog.md").read_text()
11+
updated = history.replace(f"{STOP_MARKER}\n\n", "").replace(
12+
f"{START_MARKER}\n\n", f"{START_MARKER}\n\n{latest}\n\n{STOP_MARKER}\n\n"
13+
)
14+
15+
Path("docs/history.md").write_text(updated)

0 commit comments

Comments
 (0)