-
Notifications
You must be signed in to change notification settings - Fork 242
114 lines (100 loc) · 4.53 KB
/
Copy pathversion-updates.yml
File metadata and controls
114 lines (100 loc) · 4.53 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
name: Release Follow-up Version Updates
on:
workflow_run:
workflows:
- Release from GitHub Release
types:
- completed
permissions:
contents: write
pull-requests: write
jobs:
create_pr:
name: Create Pull Request
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Set up Git
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
echo "BRANCH=version-updts" >> $GITHUB_ENV
- name: Build PR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git checkout -b $BRANCH
# Derive released version from the latest GitHub release tag (canonical source of truth)
RELEASE_TAG=$(gh release list --limit 1 --json tagName -q '.[0].tagName')
echo "Release tag: $RELEASE_TAG"
RELEASED_VERSION="${RELEASE_TAG#v}"
echo "Released version: $RELEASED_VERSION"
RELEASE_BODY=$(gh release view "$RELEASE_TAG" --json body -q '.body' || { echo "WARNING: could not fetch release notes for tag '$RELEASE_TAG'; using placeholder." >&2; echo "Release notes coming soon."; })
TODAY=$(date +"%d-%m-%Y")
# Maven version bump to next snapshot
./mvnw build-helper:parse-version versions:set -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.nextMinorVersion}.0-SNAPSHOT
git add pom.xml
# Get the next version
NEXT_VERSION=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout | sed 's/-SNAPSHOT$//')
echo $NEXT_VERSION
# Replace version in README.md
sed -i -E 's/([>:])2\.[0-9]+\.[0-9]+/\1'"$RELEASED_VERSION"'/g' README.md
# Replace snapshot version in README.md
sed -i -E 's/[0-9]+\.[0-9]+\.[0-9]+-SNAPSHOT/'"$NEXT_VERSION"-SNAPSHOT'/g' README.md
git add README.md
# Generate Providers Documentation
echo "Generating providers documentation..."
./mvnw compile test-compile exec:java \
-Dexec.mainClass="net.datafaker.script.ProvidersDocsGenerator" \
-Dexec.classpathScope=test \
-q
# Copy generated file to docs directory
GENERATED_FILE="target/test-classes/providers.md"
TARGET_DOCS_FILE="docs/documentation/providers.md"
if [ -f "$GENERATED_FILE" ]; then
cp "$GENERATED_FILE" "$TARGET_DOCS_FILE"
git add "$TARGET_DOCS_FILE"
echo "Successfully generated and staged providers.md"
else
echo "ERROR: providers.md was not generated at $GENERATED_FILE"
exit 1
fi
# Release notes using template + cleanup
RELEASE_MD="docs/releases/${RELEASED_VERSION}.md"
if [ -f "$RELEASE_MD" ]; then
echo "ERROR: $RELEASE_MD already exists; refusing to overwrite."
exit 1
fi
RELEASE_BODY_FILE=$(mktemp)
echo "$RELEASE_BODY" > "$RELEASE_BODY_FILE"
./mvnw test-compile exec:java \
-Dexec.mainClass="net.datafaker.script.ReleaseNotesGenerator" \
-Dexec.classpathScope=test \
-Dexec.args="${RELEASED_VERSION} ${TODAY} docs/releases/.RELEASE-template.md ${RELEASE_MD} ${RELEASE_BODY_FILE}" \
-q
rm -f "$RELEASE_BODY_FILE"
git add "$RELEASE_MD"
# Snapshot using template
SNAPSHOT_MD="docs/releases/${NEXT_VERSION}-SNAPSHOT.md"
if [ -f "$SNAPSHOT_MD" ]; then
echo "ERROR: $SNAPSHOT_MD already exists; refusing to overwrite."
exit 1
fi
cp docs/releases/.SNAPSHOT-template.md "$SNAPSHOT_MD"
sed -i "s/X\.Y\.Z-SNAPSHOT/${NEXT_VERSION}-SNAPSHOT/" "$SNAPSHOT_MD"
sed -i "s/dd-mm-yyyy/$TODAY/" "$SNAPSHOT_MD"
git add "$SNAPSHOT_MD"
# Update mkdocs.yml version metadata and Releases navigation
sed -i '/datafaker:/,/^[^ ]/{s/^\( *version: \).*/\1'"$RELEASED_VERSION"'/}' mkdocs.yml
sed -i '/datafaker:/,/^[^ ]/{s/^\( *snapshot: \).*/\1'"${NEXT_VERSION}-SNAPSHOT"'/}' mkdocs.yml
./mvnw test-compile exec:java \
-Dexec.mainClass="net.datafaker.script.MkdocsReleaseNavUpdater" \
-Dexec.classpathScope=test \
-Dexec.args="${RELEASED_VERSION} ${NEXT_VERSION}-SNAPSHOT mkdocs.yml" \
-q
git add mkdocs.yml
git commit -m "Released Datafaker $RELEASED_VERSION" \
-m "Updates versions, providers docs, release notes and MkDocs config." --signoff
git push --set-upstream origin $BRANCH --force
gh pr create --fill