-
Notifications
You must be signed in to change notification settings - Fork 8
148 lines (143 loc) · 5.67 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
name: CI/CD
on:
push:
branches:
- master
pull_request:
branches:
- master
workflow_dispatch:
inputs:
is-a-release:
description: Publish release? (Only works on master, and for untagged versions)
type: boolean
permissions:
contents: write
jobs:
test:
name: Run test suite
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
java-version: [ 17 ]
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup JDK
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17
check-latest: true
# The project version extract NEEDS to have the maven wrapper already downloaded.
# So we have a dummy step here just to initialize it.
- name: Download Maven wrapper
run: ./mvnw --version
- name: Run tests
run: ./mvnw test
- name: Upload test results
if: always()
uses: actions/upload-artifact@v3
with:
name: Test artifacts
retention-days: 21
path: |
**/TEST-*
**/hs_err_pid*
# Publishes the test results of 'test'
publish-test-results:
name: Publish tests results
needs: test
if: always()
runs-on: ubuntu-latest
permissions:
checks: write
pull-requests: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v3
with:
path: artifacts
- name: Publish test results
uses: EnricoMi/publish-unit-test-result-action@v2
with:
check_name: Unit Test results
files: artifacts/unit-test-*/**/*.xml
# Builds the projects and attempts to publish a release if the current project version
# does not match any existing tags in the repository.
build-and-release:
name: Publish release
needs: test
if: inputs.is-a-release && github.repository == 'Col-E/LL-Java-Zip' && github.ref == 'refs/heads/master'
strategy:
fail-fast: false
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0 # Required depth for JReleaser
- name: Setup Java JDK
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17
# The project version extract NEEDS to have the maven wrapper already downloaded.
# So we have a dummy step here just to initialize it.
- name: Download Maven wrapper
run: ./mvnw --version
# Set environment variable for the project version: "var_to_set=$(command_to_run)" >> sink
# - For maven: echo "PROJECT_VERSION=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
# - For gradle: echo "PROJECT_VERSION=$(./gradlew properties | grep -Po '(?<=version: ).*')" >> $GITHUB_ENV
- name: Extract project version to environment variable
run: echo "PROJECT_VERSION=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
# Check if a tag exists that matches the current project version.
# Write the existence state to the step output 'tagExists'.
- name: Check the package version has corresponding Git tag
id: tagged
shell: bash
run: |
git show-ref --tags --verify --quiet -- "refs/tags/${{ env.PROJECT_VERSION }}" && echo "tagExists=1" >> $GITHUB_OUTPUT || echo "tagExists=0" >> $GITHUB_OUTPUT
git show-ref --tags --verify --quiet -- "refs/tags/${{ env.PROJECT_VERSION }}" && echo "Tag for current version exists" || echo "Tag for current version does not exist"
# If the tag could not be fetched, show a message and abort the job.
# The wonky if logic is a workaround for: https://github.com/actions/runner/issues/1173
- name: Abort if tag exists, or existence check fails
if: ${{ false && steps.tagged.outputs.tagExists }}
run: |
echo "Output of 'tagged' step: ${{ steps.tagged.outputs.tagExists }}"
echo "Failed to check if tag exists."
echo "PROJECT_VERSION: ${{ env.PROJECT_VERSION }}"
echo "Tags $(git tag | wc -l):"
git tag
git show-ref --tags --verify -- "refs/tags/${{ env.PROJECT_VERSION }}"
exit 1
# Run build to generate the release artifacts.
# Tag does not exist AND trigger was manual. Deploy release artifacts!
- name: Build release artifacts
run: ./mvnw -Dmaven.test.skip=true deploy -Prelease -DaltDeploymentRepository=local::default::file:./target/staging-deploy
# Make release with JReleaser, only running when the project version does not exist as a tag on the repository.
- name: Publish release
uses: jreleaser/release-action@v2
with:
arguments: full-release
env:
JRELEASER_PROJECT_VERSION: ${{ env.PROJECT_VERSION }}
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
JRELEASER_GPG_PASSPHRASE: ${{ secrets.JRELEASER_GPG_PASSPHRASE }}
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.JRELEASER_GPG_PUBLIC_KEY }}
JRELEASER_GPG_SECRET_KEY: ${{ secrets.JRELEASER_GPG_SECRET_KEY }}
JRELEASER_NEXUS2_USERNAME: ${{ secrets.JRELEASER_DEPLOY_MAVEN_NEXUS2_USERNAME }}
JRELEASER_NEXUS2_PASSWORD: ${{ secrets.JRELEASER_DEPLOY_MAVEN_NEXUS2_PASSWORD }}
# Upload JRelease debug log
- name: JReleaser output
uses: actions/upload-artifact@v3
if: always()
with:
name: jreleaser-release
path: |
out/jreleaser/trace.log
out/jreleaser/output.properties