Skip to content

Commit e54e7ed

Browse files
committed
Update CI script
1 parent 172c123 commit e54e7ed

File tree

2 files changed

+83
-95
lines changed

2 files changed

+83
-95
lines changed

.github/workflows/build.yml

Lines changed: 83 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,84 @@
1-
name: CI
1+
name: CI/CD
22

33
on:
4-
workflow_dispatch:
54
push:
65
branches:
76
- master
87
pull_request:
98
branches:
109
- master
10+
workflow_dispatch:
11+
inputs:
12+
is-a-release:
13+
description: Publish release? (Only works on master, and for untagged versions)
14+
type: boolean
1115

12-
permissions:
13-
checks: write
14-
contents: write
15-
pull-requests: write
16+
permissions: {}
1617

1718
jobs:
18-
build:
19+
test:
20+
name: Run test suite
1921
strategy:
2022
fail-fast: false
2123
matrix:
22-
# Alternative for testing on multiple platforms. Ubuntu runs the quickest with the latest JVM.
23-
# os: [ubuntu-latest, windows-latest, macos-latest]
24-
# java-version: [11, 17]
2524
os: [ ubuntu-latest ]
2625
java-version: [ 17 ]
27-
runs-on: ${{ matrix.os }}
26+
runs-on: ubuntu-latest
27+
timeout-minutes: 10
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v3
31+
- name: Setup JDK
32+
uses: actions/setup-java@v3
33+
with:
34+
distribution: temurin
35+
java-version: [ 17 ]
36+
check-latest: true
37+
# The project version extract NEEDS to have the maven wrapper already downloaded.
38+
# So we have a dummy step here just to initialize it.
39+
- name: Download Maven wrapper
40+
run: ./mvnw --version
41+
- name: Run tests
42+
run: ./mvnw test
43+
- name: Upload test results
44+
if: always()
45+
uses: actions/upload-artifact@v3
46+
with:
47+
name: Test artifacts
48+
retention-days: 21
49+
path: |
50+
**/TEST-*
51+
**/hs_err_pid*
52+
53+
# Publishes the test results of 'test'
54+
publish-test-results:
55+
name: Publish tests results
56+
needs: test
57+
if: always()
58+
runs-on: ubuntu-latest
59+
permissions:
60+
checks: write
61+
pull-requests: write
62+
steps:
63+
- name: Download artifacts
64+
uses: actions/download-artifact@v3
65+
with:
66+
path: artifacts
67+
- name: Publish test results
68+
uses: EnricoMi/publish-unit-test-result-action@v2
69+
with:
70+
check_name: Unit Test results
71+
files: artifacts/unit-test-*/**/*.xml
72+
73+
# Builds the projects and attempts to publish a release if the current project version
74+
# does not match any existing tags in the repository.
75+
build-and-release:
76+
name: Publish release
77+
needs: test
78+
if: inputs.is-a-release && github.repository == 'Col-E/LL-Java-Zip' && github.ref == 'refs/heads/master'
79+
strategy:
80+
fail-fast: false
81+
runs-on: ubuntu-latest
2882
timeout-minutes: 10
2983
steps:
3084
- name: Checkout
@@ -34,52 +88,38 @@ jobs:
3488
- name: Setup Java JDK
3589
uses: actions/setup-java@v3
3690
with:
37-
distribution: adopt-hotspot
38-
java-version: ${{ matrix.java-version }}
39-
91+
distribution: temurin
92+
java-version: 17
4093
# The project version extract NEEDS to have the maven wrapper already downloaded.
4194
# So we have a dummy step here just to initialize it.
42-
- name: Download maven wrapper
95+
- name: Download Maven wrapper
4396
run: ./mvnw --version
44-
4597
# Set environment variable for the project version: "var_to_set=$(command_to_run)" >> sink
4698
# - For maven: echo "PROJECT_VERSION=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
4799
# - For gradle: echo "PROJECT_VERSION=$(./gradlew properties | grep -Po '(?<=version: ).*')" >> $GITHUB_ENV
48100
- name: Extract project version to environment variable
49101
run: echo "PROJECT_VERSION=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
50-
51102
# Check if a tag exists that matches the current project version.
52103
# Write the existence state to the step output 'tagExists'.
53-
- name: 'Check: package version has corresponding git tag'
104+
- name: Check the package version has corresponding Git tag
54105
id: tagged
55106
shell: bash
56107
run: git show-ref --tags --verify --quiet -- "refs/tags/${{ env.PROJECT_VERSION }}" && echo "tagExists=1" >> $GITHUB_OUTPUT || echo "tagExists=0" >> $GITHUB_OUTPUT
57-
58-
# Run build.
59-
# Either the tag exists, or the trigger was not a manual one.
60-
# Without explicit intent we do not want to publish a release.
61-
- name: Build
62-
if: steps.tagged.outputs.tagExists == 1 || github.event_name != 'workflow_dispatch'
63-
run: ./mvnw test
108+
# If the tag could not be fetched, show a message and abort the job.
109+
- name: If tag version has a problem
110+
if: steps.tagged.outputs.tagExists
111+
run: |
112+
echo "The tag version has a problem."
113+
echo "PROJECT_VERSION: ${{ env.PROJECT_VERSION }}"
114+
echo "Tags $(git tag | wc -l):"
115+
git tag
116+
exit 1
117+
# Run build to generate the release artifacts.
64118
# Tag does not exist AND trigger was manual. Deploy release artifacts!
65-
- name: Build release
66-
if: steps.tagged.outputs.tagExists == 0 && github.event_name == 'workflow_dispatch'
67-
run: ./mvnw deploy -Prelease -DaltDeploymentRepository=local::default::file:./target/staging-deploy
68-
69-
# Upload test results
70-
- name: Upload Test Results
71-
uses: actions/[email protected]
72-
if: always()
73-
with:
74-
name: Event File
75-
retention-days: 21
76-
path: |
77-
**/TEST-*
78-
**/hs_err_pid*
79-
119+
- name: Build release artifacts
120+
run: ./mvnw -Dmaven.test.skip=true deploy -Prelease -DaltDeploymentRepository=local::default::file:./target/staging-deploy
80121
# Make release with JReleaser, only running when the project version does not exist as a tag on the repository.
81-
- name: Release
82-
if: steps.tagged.outputs.tagExists == 0 && github.event_name == 'workflow_dispatch'
122+
- name: Publish release
83123
uses: jreleaser/release-action@v2
84124
with:
85125
arguments: full-release
@@ -91,25 +131,11 @@ jobs:
91131
JRELEASER_GPG_SECRET_KEY: ${{ secrets.JRELEASER_GPG_SECRET_KEY }}
92132
JRELEASER_NEXUS2_USERNAME: ${{ secrets.JRELEASER_DEPLOY_MAVEN_NEXUS2_USERNAME }}
93133
JRELEASER_NEXUS2_PASSWORD: ${{ secrets.JRELEASER_DEPLOY_MAVEN_NEXUS2_PASSWORD }}
94-
95134
# Upload JRelease debug log
96135
- name: JReleaser output
97-
if: steps.tagged.outputs.tagExists == 0
98136
uses: actions/upload-artifact@v3
99137
with:
100138
name: jreleaser-release
101139
path: |
102140
out/jreleaser/trace.log
103-
out/jreleaser/output.properties
104-
105-
# Taken from: https://github.com/EnricoMi/publish-unit-test-result-action/blob/v1.20/README.md#support-fork-repositories-and-dependabot-branches
106-
# - Required for test-results to be published
107-
event_file:
108-
name: "Event File"
109-
runs-on: ubuntu-latest
110-
steps:
111-
- name: Upload
112-
uses: actions/upload-artifact@v2
113-
with:
114-
name: Event File
115-
path: ${{ github.event_path }}
141+
out/jreleaser/output.properties

.github/workflows/display_test_results.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)