filter labels
[yosql.git] / .github / workflows / release.yml
blob24407577438645a6957ba5a0375b916d91edd9ca
1 name: Perform Release
2 on:
3   schedule:
4     - cron:  "25 3 * * SUN"
5   workflow_dispatch:
6 env:
7   JAVA_VERSION: 16
8   JAVA_PACKAGE: jdk
9   JAVA_ARCH: x64
10   JAVA_DISTRO: adopt
11   PROJECT_URL: yosql.projects.metio.wtf
12 jobs:
13   prepare:
14     name: Prepare Release
15     runs-on: ubuntu-latest
16     outputs:
17       commit_count: ${{ steps.commits.outputs.count }}
18       release_version: ${{ steps.release.outputs.version }}
19       previous_version: ${{ steps.previous.outputs.version }}
20       changelog: ${{ steps.changelog.outputs.content }}
21       release_url: ${{ steps.create_release.outputs.upload_url }}
22     steps:
23       - id: checkout
24         name: Clone Git Repository
25         uses: actions/checkout@v2
26         with:
27           fetch-depth: 0 # required in order to get all tags
28       - id: commits
29         name: Count Commits
30         run: echo "::set-output name=count::$(git rev-list --count HEAD --since='last Sunday' -- yosql-codegen yosql-converters yosql-dao yosql-internals yosql-logging yosql-models yosql-testing yosql-tooling)"
31       - id: release
32         name: Create Release Version
33         if: steps.commits.outputs.count > 0
34         run: echo "::set-output name=version::$(date +'%Y.%-m.%-d')"
35       - id: previous
36         name: Get Last Release
37         if: steps.commits.outputs.count > 0
38         run: echo "::set-output name=version::$(git describe --abbrev=0 --tags)"
39       - id: generate_changelog
40         name: Generate Changelog
41         if: steps.commits.outputs.count > 0
42         uses: heinrichreimer/github-changelog-generator-action@v2.2
43         with:
44           token: ${{ secrets.GITHUB_TOKEN }}
45           unreleased: true
46           issues: true
47           issuesWoLabels: true
48           excludeLabels: "Resolved :: Duplicate,Resolved :: Invalid,Resolved :: Wontfix"
49           pullRequests: true
50           prWoLabels: true
51           filterByMilestone: false
52           futureRelease: ${{ steps.release.outputs.version }}
53           sinceTag: ${{ steps.previous.outputs.version }}
54           stripGeneratorNotice: true
55           stripHeaders: true
56       - name: Check Changelog Existence
57         id: check_changelog
58         uses: andstor/file-existence-action@v1
59         with:
60           files: "CHANGELOG.md"
61       - name: Create Empty Changelog
62         id: empty_changelog
63         uses: 1arp/create-a-file-action@0.2
64         if: steps.check_changelog.outputs.files_exists == 'false'
65         with:
66           file: CHANGELOG.md
67           content: |
68             no user facing changes
69       - name: Read Changelog
70         id: changelog
71         uses: juliangruber/read-file-action@v1
72         with:
73           path: ./CHANGELOG.md
74       - id: create_release
75         name: Create Release
76         if: steps.commits.outputs.count > 0
77         uses: actions/create-release@v1
78         env:
79           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
80         with:
81           tag_name: ${{ steps.release.outputs.version }}
82           release_name: ${{ steps.release.outputs.version }}
83           draft: false
84           prerelease: false
85           body: |
86             # YoSQL
87             Write more SQL! Take a look at the [website](https://${{ env.PROJECT_URL }}/) for detailed information. **This release requires at least Java ${{ env.JAVA_VERSION }}**.
88             ## Changes
89             ${{ steps.changelog.outputs.content }}
90   deploy:
91     name: Deploy Artifacts
92     runs-on: ubuntu-latest
93     needs: prepare
94     steps:
95       - id: checkout
96         name: Clone Git Repository
97         uses: actions/checkout@v2
98         if: needs.prepare.outputs.commit_count > 0
99       - id: java
100         name: Setup Java
101         uses: actions/setup-java@v2
102         if: needs.prepare.outputs.commit_count > 0
103         with:
104           java-version: ${{ env.JAVA_VERSION }}
105           java-package: ${{ env.JAVA_PACKAGE }}
106           architecture: ${{ env.JAVA_ARCH }}
107           distribution: ${{ env.JAVA_DISTRO }}
108           server-id: ossrh
109           server-username: MAVEN_CENTRAL_USERNAME
110           server-password: MAVEN_CENTRAL_TOKEN
111       - id: cache
112         name: Cache Maven Repository
113         uses: actions/cache@v2.1.5
114         if: needs.prepare.outputs.commit_count > 0
115         with:
116           path: ~/.m2/repository
117           key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
118           restore-keys: |
119             ${{ runner.os }}-maven-
120       - id: gpg
121         name: GPG Key
122         run: echo "${{ secrets.GPG_SECRET_KEY_BASE64 }}" | base64 --decode > $GITHUB_WORKSPACE/signing.key.asc
123       - name: Set release version
124         run: mvn --batch-mode versions:set -DnewVersion=${{ needs.prepare.outputs.release_version }} -DgenerateBackupPoms=false
125         if: needs.prepare.outputs.commit_count > 0
126       - id: deploy-maven
127         name: Deploy Maven Artifacts
128         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 install deploy --activate-profiles release install deploy -Dpgp.secretkey=keyfile:$GITHUB_WORKSPACE/signing.key.asc -Dpgp.passphrase=literal:${{ secrets.GPG_SECRET_KEY_PASSWORD }}
129         if: needs.prepare.outputs.commit_count > 0
130         env:
131           MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
132           MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN }}
133       - id: deploy-gradle
134         name: Deploy Gradle Plugin
135         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 }}
136         if: needs.prepare.outputs.commit_count > 0
137   benchmarks:
138     name: Run Benchmarks
139     runs-on: ubuntu-latest
140     needs: [deploy]
141     strategy:
142       matrix:
143         benchmark: [codegen, jdbc]
144     steps:
145       - id: checkout
146         name: Clone Git Repository
147         uses: actions/checkout@v2
148         if: needs.prepare.outputs.commit_count > 0
149       - id: java
150         name: Setup Java
151         uses: actions/setup-java@v2
152         if: needs.prepare.outputs.commit_count > 0
153         with:
154           java-version: ${{ env.JAVA_VERSION }}
155           java-package: ${{ env.JAVA_PACKAGE }}
156           architecture: ${{ env.JAVA_ARCH }}
157           distribution: ${{ env.JAVA_DISTRO }}
158       - id: cache
159         name: Cache Maven Repository
160         uses: actions/cache@v2.1.5
161         if: needs.prepare.outputs.commit_count > 0
162         with:
163           path: ~/.m2/repository
164           key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
165           restore-keys: |
166             ${{ runner.os }}-maven-
167       - id: run-benchmark
168         name: Run Benchmark [${{ matrix.benchmark }}]
169         run: mvn --batch-mode --projects yosql-benchmarks/yosql-benchmarks-${{ matrix.benchmark }} --also-make --activate-profiles benchmarks verify -Dorg.slf4j.simpleLogger.log.yosql=warn -DskipTests 2>&1 1> build.log
170         if: needs.prepare.outputs.commit_count > 0
171         env:
172           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
173       - id: upload-benchmark
174         name: Upload Benchmark Results
175         uses: actions/upload-artifact@v2
176         if: needs.prepare.outputs.commit_count > 0
177         with:
178           name: benchmark-${{ matrix.benchmark }}
179           path: ./yosql-benchmarks/yosql-benchmarks-${{ matrix.benchmark }}/target/benchmark/yosql-benchmarks-${{ matrix.benchmark }}.json
180   results:
181     name: Publish Results
182     runs-on: ubuntu-latest
183     needs: [benchmarks]
184     steps:
185       - id: checkout
186         name: Clone Git Repository
187         uses: actions/checkout@v2
188         if: needs.prepare.outputs.commit_count > 0
189       - id: download
190         name: Download Benchmarks Results
191         uses: actions/download-artifact@v2
192         if: needs.prepare.outputs.commit_count > 0
193       - id: copy-codegen-results
194         name: Copy Codegen Results
195         run: cp ./benchmark-codegen/yosql-benchmarks-codegen.json ./yosql-website/content/benchmarks/releases/yosql-benchmarks-codegen-${{ needs.prepare.outputs.release_version }}.json
196         if: needs.prepare.outputs.commit_count > 0
197       - id: copy-jdbc-results
198         name: Copy JDBC Results
199         run: cp ./benchmark-jdbc/yosql-benchmarks-jdbc.json ./yosql-website/content/benchmarks/releases/yosql-benchmarks-jdbc-${{ needs.prepare.outputs.release_version }}.json
200         if: needs.prepare.outputs.commit_count > 0
201       - id: push
202         name: Push Benchmarks
203         uses: stefanzweifel/git-auto-commit-action@v4
204         if: needs.prepare.outputs.commit_count > 0
205         with:
206           commit_message: Add benchmark results for ${{ needs.prepare.outputs.release_version }}
207           file_pattern: "*.json"
208   announce:
209     name: Send Announcements
210     needs: [deploy]
211     runs-on: ubuntu-latest
212     steps:
213       - id: email
214         name: Send Mail
215         uses: dawidd6/action-send-mail@v2
216         if: needs.prepare.outputs.commit_count > 0
217         with:
218           server_address: ${{ secrets.MAIL_SERVER }}
219           server_port: ${{ secrets.MAIL_PORT }}
220           username: ${{ secrets.MAIL_USERNAME }}
221           password: ${{ secrets.MAIL_PASSWORD }}
222           to: ${{ secrets.MAIL_TO }}
223           from: ${{ secrets.MAIL_SENDER }}
224           subject: release ${{ needs.prepare.outputs.release_version }}
225           body: See https://github.com/metio/yosql/releases/tag/${{ needs.prepare.outputs.release_version }} for details.
226       - id: matrix
227         name: Send Matrix Message
228         uses: s3krit/matrix-message-action@v0.0.3
229         if: needs.prepare.outputs.commit_count > 0
230         with:
231           access_token: ${{ secrets.MATRIX_ACCESS_TOKEN }}
232           room_id: ${{ secrets.MATRIX_ROOM_ID }}
233           server: ${{ secrets.MATRIX_SERVER }}
234           message: release ${{ needs.prepare.outputs.release_version }} published - see https://github.com/metio/yosql/releases/tag/${{ needs.prepare.outputs.release_version }} for details