-
Notifications
You must be signed in to change notification settings - Fork 1
115 lines (110 loc) · 4.58 KB
/
Copy pathpre-release.yml
File metadata and controls
115 lines (110 loc) · 4.58 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
name: Draft release pull request
on:
pull_request:
types: [closed]
branches:
- main
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
jobs:
generate-changelog:
name: Create a PR to update version and release notes
if: github.event.pull_request.merged == true
permissions:
contents: write
actions: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Needed to get all tags for changelog generation
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: 3.12
cache: pip
- name: Install build tool
run: python -m pip install hatch
- name: Determine Version Bump from PR Labels
id: version
run: |
BUMP="patch"
LABELS='${{ toJSON(github.event.pull_request.labels.*.name) }}'
echo "Checking labels: $LABELS"
if echo "$LABELS" | grep -q "semver:major"; then
BUMP="major"
elif echo "$LABELS" | grep -q "semver:minor"; then
BUMP="minor"
elif echo "$LABELS" | grep -q "semver:alpha"; then
BUMP="alpha"
elif echo "$LABELS" | grep -q "semver:beta"; then
BUMP="beta"
elif echo "$LABELS" | grep -q "semver:preview"; then
BUMP="preview"
elif echo "$LABELS" | grep -q "semver:dev"; then
BUMP="dev"
fi
echo "Version bump determined: $BUMP"
echo "level=${BUMP}" >> $GITHUB_OUTPUT
- name: Bump version
run: hatch version ${{ steps.version.outputs.level }}
- name: Generate release notes
if: steps.version.outputs.level == 'major' || steps.version.outputs.level == 'minor' || steps.version.outputs.level == 'patch' || steps.version.outputs.level == 'beta'
id: changelog
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# This will be empty if there are no releases yet
PREVIOUS_VERSION=$(gh release view --json tagName --jq .tagName 2>/dev/null || echo "")
NEXT_VERSION="v$(hatch version)"
echo "## $NEXT_VERSION ($(date -I))" > changelog.md
# Build arguments for the API call
ARGS=("--method" "POST" "-H" "Accept: application/vnd.github.v3+json" "/repos/jorgesolebur/CumulusCI_AzureDevOps/releases/generate-notes" "-f" "target_commitish=main" "-f" "tag_name=$NEXT_VERSION")
if [ -n "$PREVIOUS_VERSION" ]; then
echo "Generating notes between $PREVIOUS_VERSION and $NEXT_VERSION"
ARGS+=("-f" "previous_tag_name=$PREVIOUS_VERSION")
else
echo "No previous release found. Generating notes for the first release."
fi
gh api "${ARGS[@]}" --jq '.body' |
sed -e 's_\(https.*\/\)\([0-9]*\)$_[#\2](\1\2)_' \
-e 's_by @\(.*\) in_by [@\1](https://github.com/\1) in_' >> changelog.md
python utility/update-history.py
- name: Lint history
if: steps.version.outputs.level == 'major' || steps.version.outputs.level == 'minor' || steps.version.outputs.level == 'patch' || steps.version.outputs.level == 'beta'
run: |
npm install prettier
npx prettier --write docs/history.md
- name: Commit version and changelog
run: |
BRANCH_NAME="release-$(hatch version)"
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
git switch -c "$BRANCH_NAME"
git add docs/history.md cumulusci_ado/__about__.py
git commit -m "Update changelog (automated)"
# Delete the remote branch if it exists, ignoring errors if it doesn't.
git push origin --delete "$BRANCH_NAME" || true
# Push the new branch.
git push origin "$BRANCH_NAME"
- name: Create and Merge Release PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_URL=$(gh pr create --title "Release v$(hatch version)" --fill --label 'auto-pr')
if [ -n "$PR_URL" ]; then
echo "Created PR: $PR_URL"
gh pr merge "$PR_URL" --merge --delete-branch
echo "PR merged and branch deleted."
else
echo "PR creation failed."
exit 1
fi
- name: Call Release Workflow
uses: benc-uk/workflow-dispatch@v1
with:
workflow: "Publish and release CumulusCI_AzureDevOps"
token: ${{ secrets.GITHUB_TOKEN }}
ref: main