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