Bump peter-evans/create-pull-request from 6 to 7
[yosql.git] / .github / workflows / release.yml
blob90caa7487d2f2a8da675f35efb01ae8942b4ed11
1 name: Automated Release
2 on:
3   schedule:
4     - cron: 25 3 * * WED
5   workflow_dispatch:
6 env:
7   JAVA_VERSION: 17
8   JAVA_PACKAGE: jdk
9   JAVA_ARCH: x64
10   JAVA_DISTRO: temurin
11 jobs:
12   prepare:
13     name: Prepare Release
14     runs-on: ubuntu-latest
15     outputs:
16       commit_count: ${{ steps.commits.outputs.count }}
17       previous_version: ${{ steps.last_release.outputs.version }}
18       release_version: ${{ steps.release.outputs.version }}
19     steps:
20       - id: checkout
21         name: Clone Git Repository
22         uses: actions/checkout@v4
23         with:
24           fetch-depth: 0
25       - id: last_release
26         name: Fetch last release info
27         run: echo "tag=$(gh release view --json tagName --jq '.tagName')" >> $GITHUB_OUTPUT
28         env:
29           GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30       - id: commits
31         name: Count Commits
32         run: echo "count=$(git rev-list --count ${{ steps.last_release.outputs.tag }}..HEAD) -- pom.xml yosql-codegen yosql-internals yosql-models yosql-tooling" >> $GITHUB_OUTPUT
33       - id: release
34         name: Create Release Version
35         if: steps.commits.outputs.count > 0
36         run: echo "version=$(date +'%Y.%-m.%-d')" >> $GITHUB_OUTPUT
37       - id: timestamp
38         name: Build Timestamp
39         if: steps.commits.outputs.count > 0
40         run: echo "iso8601=$(date --utc --iso-8601=seconds)" >> $GITHUB_OUTPUT
41   maven:
42     name: Build Maven Tooling
43     needs: prepare
44     runs-on: ubuntu-latest
45     steps:
46       - id: checkout
47         name: Clone Git Repository
48         if: needs.prepare.outputs.commit_count > 0
49         uses: actions/checkout@v4
50       - id: java
51         name: Setup Java
52         if: needs.prepare.outputs.commit_count > 0
53         uses: actions/setup-java@v4
54         with:
55           java-version: ${{ env.JAVA_VERSION }}
56           java-package: ${{ env.JAVA_PACKAGE }}
57           architecture: ${{ env.JAVA_ARCH }}
58           distribution: ${{ env.JAVA_DISTRO }}
59           server-id: ossrh
60           server-username: MAVEN_CENTRAL_USERNAME
61           server-password: MAVEN_CENTRAL_TOKEN
62           cache: maven
63       - id: gpg
64         name: GPG Key
65         if: needs.prepare.outputs.commit_count > 0
66         uses: timheuer/base64-to-file@v1.2
67         with:
68           fileName: signing.key.asc
69           fileDir: ${{ github.workspace}}
70           encodedString: ${{ secrets.GPG_SECRET_KEY_BASE64 }}
71       - name: Set release version
72         if: needs.prepare.outputs.commit_count > 0
73         run: mvn --batch-mode versions:set --define newVersion=${{ needs.prepare.outputs.release_version }} --define generateBackupPoms=false
74       - id: deploy-maven-tooling
75         name: Deploy Maven Tooling
76         if: needs.prepare.outputs.commit_count > 0
77         run: MAVEN_OPTS="--add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.text=ALL-UNNAMED --add-opens=java.desktop/java.awt.font=ALL-UNNAMED" mvn --batch-mode --activate-profiles release --projects yosql-tooling/yosql-tooling-maven --also-make install deploy --define pgp.secretkey=keyfile:signing.key.asc --define pgp.passphrase=literal:${{ secrets.GPG_SECRET_KEY_PASSWORD }}
78         env:
79           MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
80           MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN }}
81   gradle:
82     name: Build Gradle Tooling
83     needs: prepare
84     runs-on: ubuntu-latest
85     steps:
86       - id: checkout
87         name: Clone Git Repository
88         if: needs.prepare.outputs.commit_count > 0
89         uses: actions/checkout@v4
90       - id: java
91         name: Setup Java
92         if: needs.prepare.outputs.commit_count > 0
93         uses: actions/setup-java@v4
94         with:
95           java-version: ${{ env.JAVA_VERSION }}
96           java-package: ${{ env.JAVA_PACKAGE }}
97           architecture: ${{ env.JAVA_ARCH }}
98           distribution: ${{ env.JAVA_DISTRO }}
99           cache: maven
100       - name: Set release version
101         if: needs.prepare.outputs.commit_count > 0
102         run: mvn --batch-mode versions:set --define newVersion=${{ needs.prepare.outputs.release_version }} --define generateBackupPoms=false
103       - id: install-maven-tooling
104         name: Install Maven Tooling
105         if: needs.prepare.outputs.commit_count > 0
106         run: mvn --batch-mode install
107       - id: build-gradle
108         name: Build Gradle Tooling
109         if: needs.prepare.outputs.commit_count > 0
110         run: cd ./yosql-examples/yosql-examples-gradle/ && ./gradlew build -Pversion=${{ needs.prepare.outputs.release_version }}
111       - id: deploy-gradle
112         name: Deploy Gradle Tooling
113         if: needs.prepare.outputs.commit_count > 0
114         run: cd ./yosql-tooling/yosql-tooling-gradle/ && ./gradlew publishPlugins -Pversion=${{ needs.prepare.outputs.release_version }} -Pgradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }} -Pgradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }}
115   ant:
116     name: Build Ant Tooling
117     needs: prepare
118     runs-on: ubuntu-latest
119     steps:
120       - id: checkout
121         name: Clone Git Repository
122         if: needs.prepare.outputs.commit_count > 0
123         uses: actions/checkout@v4
124       - id: java
125         name: Setup Java
126         if: needs.prepare.outputs.commit_count > 0
127         uses: actions/setup-java@v4
128         with:
129           java-version: ${{ env.JAVA_VERSION }}
130           java-package: ${{ env.JAVA_PACKAGE }}
131           architecture: ${{ env.JAVA_ARCH }}
132           distribution: ${{ env.JAVA_DISTRO }}
133           cache: maven
134       - id: gpg
135         name: GPG Key
136         if: needs.prepare.outputs.commit_count > 0
137         uses: timheuer/base64-to-file@v1.2
138         with:
139           fileName: signing.key.asc
140           fileDir: ${{ github.workspace}}
141           encodedString: ${{ secrets.GPG_SECRET_KEY_BASE64 }}
142       - name: Set release version
143         if: needs.prepare.outputs.commit_count > 0
144         run: mvn --batch-mode versions:set --define newVersion=${{ needs.prepare.outputs.release_version }} --define generateBackupPoms=false
145       - id: build-ant-tooling
146         name: Build Ant Tooling
147         if: needs.prepare.outputs.commit_count > 0
148         run: mvn --batch-mode --activate-profiles release --projects yosql-tooling/yosql-tooling-ant --also-make install --define pgp.secretkey=keyfile:signing.key.asc --define pgp.passphrase=literal:${{ secrets.GPG_SECRET_KEY_PASSWORD }}
149       - id: upload-ant-tooling
150         name: Upload Ant Tooling Artifact
151         if: needs.prepare.outputs.commit_count > 0
152         uses: actions/upload-artifact@v4
153         with:
154           name: yosql-tooling-ant
155           path: ./yosql-tooling/yosql-tooling-ant/target/yosql-tooling-ant-*-dist*
156   cli:
157     name: Build CLI Tooling on ${{ matrix.os }}
158     needs: prepare
159     runs-on: ${{ matrix.os }}
160     strategy:
161       matrix:
162         os:
163           - ubuntu-latest
164           - macos-latest
165           - windows-latest
166     steps:
167       - id: checkout
168         name: Clone Git Repository
169         if: needs.prepare.outputs.commit_count > 0
170         uses: actions/checkout@v4
171       - id: graal
172         name: Setup GraalVM
173         if: needs.prepare.outputs.commit_count > 0
174         uses: graalvm/setup-graalvm@v1
175         with:
176           distribution: graalvm
177           java-version: ${{ env.JAVA_VERSION }}
178           github-token: ${{ secrets.GITHUB_TOKEN }}
179           cache: maven
180       - id: gpg
181         name: GPG Key
182         if: needs.prepare.outputs.commit_count > 0
183         uses: timheuer/base64-to-file@v1
184         with:
185           fileName: signing.key.asc
186           fileDir: ${{ github.workspace}}
187           encodedString: ${{ secrets.GPG_SECRET_KEY_BASE64 }}
188       - name: Set release version
189         if: needs.prepare.outputs.commit_count > 0
190         run: mvn --batch-mode --define newVersion=${{ needs.prepare.outputs.release_version }} --define generateBackupPoms=false versions:set
191       - id: build-cli-tooling
192         name: Build CLI Tooling
193         if: needs.prepare.outputs.commit_count > 0
194         run: mvn --batch-mode --activate-profiles release --projects yosql-tooling/yosql-tooling-cli --also-make install --define skipNativeBuild=false --define pgp.secretkey=keyfile:signing.key.asc --define pgp.passphrase=literal:${{ secrets.GPG_SECRET_KEY_PASSWORD }}
195       - id: upload-jvm-cli-tooling
196         name: Upload JVM CLI Tooling
197         if: needs.prepare.outputs.commit_count > 0 && runner.os == 'Linux'
198         uses: actions/upload-artifact@v4
199         with:
200           name: yosql-tooling-cli-jvm
201           path: ./yosql-tooling/yosql-tooling-cli/target/yosql-tooling-cli-*-jvm*
202       - id: upload-linux-cli-tooling
203         name: Upload Linux CLI Tooling
204         if: needs.prepare.outputs.commit_count > 0 && runner.os == 'Linux'
205         uses: actions/upload-artifact@v4
206         with:
207           name: yosql-tooling-cli-linux
208           path: ./yosql-tooling/yosql-tooling-cli/target/yosql-tooling-cli-*-linux*
209       - id: upload-mac-cli-tooling
210         name: Upload Mac OSX CLI Tooling
211         if: needs.prepare.outputs.commit_count > 0 && runner.os == 'macOS'
212         uses: actions/upload-artifact@v4
213         with:
214           name: yosql-tooling-cli-mac
215           path: ./yosql-tooling/yosql-tooling-cli/target/yosql-tooling-cli-*-mac*
216       - id: upload-windows-cli-tooling
217         name: Upload Windows CLI Tooling
218         if: needs.prepare.outputs.commit_count > 0 && runner.os == 'Windows'
219         uses: actions/upload-artifact@v4
220         with:
221           name: yosql-tooling-cli-windows
222           path: ./yosql-tooling/yosql-tooling-cli/target/yosql-tooling-cli-*-windows*
223   release:
224     name: GitHub Release
225     needs: [prepare, maven, gradle, ant, cli]
226     runs-on: ubuntu-latest
227     permissions:
228       contents: write
229     steps:
230       - id: checkout
231         name: Clone Git Repository
232         if: needs.prepare.outputs.commit_count > 0
233         uses: actions/checkout@v4
234         with:
235           fetch-depth: 0
236       - id: download
237         name: Download Artifacts
238         if: needs.prepare.outputs.commit_count > 0
239         uses: actions/download-artifact@v4
240         with:
241           path: artifacts
242       - id: create_release
243         name: Create Release
244         if: needs.prepare.outputs.commit_count > 0
245         uses: softprops/action-gh-release@v2
246         with:
247           tag_name: ${{ needs.prepare.outputs.release_version }}
248           token: ${{ secrets.GITHUB_TOKEN }}
249           draft: false
250           prerelease: false
251           generate_release_notes: true
252           files: |
253             artifacts/yosql-tooling-ant/yosql-tooling-ant-${{ needs.prepare.outputs.release_version }}-dist.zip
254             artifacts/yosql-tooling-ant/yosql-tooling-ant-${{ needs.prepare.outputs.release_version }}-dist.zip.asc
255             artifacts/yosql-tooling-ant/yosql-tooling-ant-${{ needs.prepare.outputs.release_version }}-dist.zip.sha512
256             artifacts/yosql-tooling-cli-jvm/yosql-tooling-cli-${{ needs.prepare.outputs.release_version }}-jvm.zip
257             artifacts/yosql-tooling-cli-jvm/yosql-tooling-cli-${{ needs.prepare.outputs.release_version }}-jvm.zip.asc
258             artifacts/yosql-tooling-cli-jvm/yosql-tooling-cli-${{ needs.prepare.outputs.release_version }}-jvm.zip.sha512
259             artifacts/yosql-tooling-cli-linux/yosql-tooling-cli-${{ needs.prepare.outputs.release_version }}-linux.zip
260             artifacts/yosql-tooling-cli-linux/yosql-tooling-cli-${{ needs.prepare.outputs.release_version }}-linux.zip.asc
261             artifacts/yosql-tooling-cli-linux/yosql-tooling-cli-${{ needs.prepare.outputs.release_version }}-linux.zip.sha512
262             artifacts/yosql-tooling-cli-mac/yosql-tooling-cli-${{ needs.prepare.outputs.release_version }}-mac.zip
263             artifacts/yosql-tooling-cli-mac/yosql-tooling-cli-${{ needs.prepare.outputs.release_version }}-mac.zip.asc
264             artifacts/yosql-tooling-cli-mac/yosql-tooling-cli-${{ needs.prepare.outputs.release_version }}-mac.zip.sha512
265             artifacts/yosql-tooling-cli-linux/yosql-tooling-cli-${{ needs.prepare.outputs.release_version }}-windows.zip
266             artifacts/yosql-tooling-cli-linux/yosql-tooling-cli-${{ needs.prepare.outputs.release_version }}-windows.zip.asc
267             artifacts/yosql-tooling-cli-linux/yosql-tooling-cli-${{ needs.prepare.outputs.release_version }}-windows.zip.sha512