Skip to content

Commit 93cf052

Browse files
Add CD pipeline
1 parent 146c72a commit 93cf052

4 files changed

Lines changed: 122 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: release
2+
on: workflow_dispatch
3+
4+
permissions:
5+
actions: none
6+
checks: none
7+
contents: write
8+
deployments: none
9+
issues: none
10+
packages: none
11+
pull-requests: none
12+
repository-projects: none
13+
security-events: none
14+
statuses: none
15+
16+
jobs:
17+
release:
18+
environment: Release
19+
runs-on: ubuntu-22.04
20+
steps:
21+
- uses: actions/checkout@v4
22+
with:
23+
# Ref is required for post release version increment commit
24+
ref: ${{ github.event.ref }}
25+
- uses: actions/setup-java@v4
26+
with:
27+
distribution: temurin
28+
java-version: 17
29+
30+
- run: python ./ci-scripts/getVersion.py
31+
id: getVersion
32+
33+
- run: ./gradlew publishPlugins --validate-only
34+
env:
35+
GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PUBLISH_KEY }}
36+
GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PUBLISH_SECRET }}
37+
38+
- run: ./gradlew publishPlugins
39+
env:
40+
GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PUBLISH_KEY }}
41+
GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PUBLISH_SECRET }}
42+
43+
- name: Create GitHub Release
44+
uses: ncipollo/release-action@v1
45+
with:
46+
token: ${{ secrets.GITHUB_TOKEN }}
47+
tag: "v${{ steps.getVersion.outputs.version }}"
48+
name: "${{ github.event.repository.name }} v${{ steps.getVersion.outputs.version }}"
49+
bodyFile: "UpcomingReleaseNotes.md"
50+
51+
- run: python ./ci-scripts/incrementVersion.py
52+
id: postReleaseVersionIncrement
53+
54+
- uses: stefanzweifel/git-auto-commit-action@v5
55+
with:
56+
commit_message: "Post release version increment to ${{ steps.postReleaseVersionIncrement.outputs.newVersion }} (from ${{ steps.postReleaseVersionIncrement.outputs.oldVersion }})"
57+
file_pattern: build.gradle.kts
58+
59+
- run: echo -n > UpcomingReleaseNotes.md
60+
- uses: stefanzweifel/git-auto-commit-action@v5
61+
with:
62+
commit_message: "Post release truncation of UpcomingReleaseNotes.md"
63+
file_pattern: UpcomingReleaseNotes.md

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ bin/
3535

3636
### Mac OS ###
3737
.DS_Store
38+
__pycache__

ci-scripts/getVersion.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python3
2+
import os
3+
from pathlib import Path
4+
5+
6+
def get_version():
7+
script_path = Path(__file__).resolve().parent
8+
with open(script_path.parent / "build.gradle.kts", "r") as f:
9+
for line in f.readlines():
10+
prefix = "version = \""
11+
if line.startswith(prefix):
12+
return line.strip()[len(prefix):].strip("\"")
13+
14+
15+
def main():
16+
version = get_version()
17+
print(version)
18+
gh_output = os.environ.get('GITHUB_OUTPUT')
19+
if gh_output:
20+
with open(gh_output, 'w') as out:
21+
print("version=" + version, file=out)
22+
23+
24+
if __name__ == "__main__":
25+
main()

ci-scripts/incrementVersion.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python3
2+
import os
3+
from pathlib import Path
4+
5+
from getVersion import get_version
6+
7+
8+
def main():
9+
oldversion = get_version()
10+
print("old version:", oldversion)
11+
12+
version = oldversion.split(".")
13+
version[len(version)-1] = str(int(version[len(version)-1]) + 1)
14+
15+
newversion = ".".join(version)
16+
print("new version:", newversion)
17+
18+
gh_output = os.environ.get('GITHUB_OUTPUT')
19+
if gh_output:
20+
with open(gh_output, 'w') as out:
21+
print("oldVersion=" + oldversion, file=out)
22+
print("newVersion=" + newversion, file=out)
23+
24+
build_gradle_kts = Path(__file__).resolve().parent.parent / "build.gradle.kts"
25+
r = build_gradle_kts.open('r')
26+
updated_script = r.read().replace("version = \"{}\"".format(oldversion), "version = \"{}\"".format(newversion))
27+
r.close()
28+
with open(build_gradle_kts, 'w') as w:
29+
w.write(updated_script)
30+
31+
32+
if __name__ == "__main__":
33+
main()

0 commit comments

Comments
 (0)