Skip to content

Commit c75cd30

Browse files
authored
Create nightly-build.yml (#90)
1 parent 0087ead commit c75cd30

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

.github/workflows/nightly-build.yml

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Nightly Pre-Release
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *'
6+
workflow_dispatch:
7+
8+
jobs:
9+
prerelease:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: 📦 Checkout Code
14+
uses: actions/checkout@v4
15+
16+
- name: Get latest nightly pre-release commit SHA
17+
id: get_latest_nightly_commit
18+
run: |
19+
latest_nightly_commit=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases | jq -r '[.[] | select(.prerelease == true)] | first | .target_commitish')
20+
echo "latest_nightly_commit=${latest_nightly_commit}" >> $GITHUB_ENV
21+
22+
- name: Fallback to latest release if latest nightly commit is not found
23+
if: env.latest_nightly_commit == null
24+
run: |
25+
latest_release=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name)
26+
echo "latest_nightly_commit=${latest_release}" >> $GITHUB_ENV
27+
28+
- name: Check for changes with previous nightly pre-release
29+
id: check_changes
30+
run: |
31+
git fetch --tags
32+
if git diff --quiet ${{ env.latest_nightly_commit }}..HEAD; then
33+
echo "No changes detected"
34+
echo "changes=false" >> $GITHUB_ENV
35+
else
36+
echo "Changes detected"
37+
echo "changes=true" >> $GITHUB_ENV
38+
fi
39+
40+
- name: 🚀 Set up JDK 17
41+
if: env.changes == 'true'
42+
uses: actions/setup-java@v4
43+
with:
44+
java-version: '17'
45+
distribution: 'temurin'
46+
cache: maven
47+
48+
- name: Get current version from pom.xml
49+
if: env.changes == 'true'
50+
id: get_version
51+
run: |
52+
current_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
53+
echo "current_version=${current_version}" >> $GITHUB_ENV
54+
55+
- name: Set nightly version variable
56+
if: env.changes == 'true'
57+
run: |
58+
nightly_version=${{ env.current_version }}+nightly.$(date +'%Y%m%d').$(git rev-parse --short HEAD)
59+
echo "nightly_version=${nightly_version}" >> $GITHUB_ENV
60+
61+
- name: Set nightly version
62+
if: env.changes == 'true'
63+
run: |
64+
mvn versions:set -DnewVersion=${{ env.nightly_version }} -DgenerateBackupPoms=false
65+
66+
- name: 🛠 Build with Maven
67+
if: env.changes == 'true'
68+
run: mvn -B package --file pom.xml
69+
70+
- name: Get latest release tag
71+
if: env.changes == 'true'
72+
id: get_latest_release
73+
run: |
74+
latest_release=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name)
75+
echo "latest_release=${latest_release}" >> $GITHUB_ENV
76+
77+
- name: Generate changelog since last release
78+
if: env.changes == 'true'
79+
id: changelog
80+
uses: requarks/changelog-action@v1
81+
with:
82+
token: ${{ github.token }}
83+
fromTag: ${{ github.ref_name }}
84+
toTag: ${{ env.latest_release }}
85+
includeInvalidCommits: true
86+
87+
- name: 🚀 Create pre-release
88+
if: env.changes == 'true'
89+
uses: softprops/action-gh-release@v2
90+
with:
91+
files: |
92+
target/*.jar
93+
target/*.deb
94+
tag_name: v${{ env.nightly_version }}
95+
name: Nightly v${{ env.nightly_version }}
96+
prerelease: true
97+
body: ${{ steps.changelog.outputs.changes }}

0 commit comments

Comments
 (0)