Repository navigation
140 lines (126 loc) · 5.71 KB
/
Copy pathbuild.yml
File metadata and controls
140 lines (126 loc) · 5.71 KB
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
name: Build
run-name: >-
${{ github.event_name == 'pull_request' && format('Checking that #{0} builds', github.event.pull_request.number)
|| format('Building {0}', github.ref_name) }}
# Trunk-based: main is the only long-lived branch. Every pull request and every push to main compiles the
# library for Java 8, tests it, builds the javadoc and sources jars and the examples on each supported JDK,
# but nothing is published here: Maven Central versions are permanent, so a release is a deliberate act -
# publishing a GitHub Release v{semver}, which runs publish.yml. The required status check is the last
# job's name, `build`, which passes only when every JDK passed.
on:
pull_request:
branches: [main]
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
# A newer push to the same pull request cancels the older build; builds of main never cancel each other.
concurrency:
group: build-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || github.run_id }}
cancel-in-progress: true
env:
# The live tests convert real files against the staging API with a staging token. Without the token
# (a pull request from a fork gets no secrets) they are skipped, and the offline tests still run.
CONVERT_API_BASE_URI: https://stag-v2.convertapi.com/
MAVEN_ARGS: --batch-mode --no-transfer-progress
jobs:
test:
name: test (JDK ${{ matrix.java }})
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
java: [17, 21, 25]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad # v6.1.0
with:
distribution: temurin
java-version: ${{ matrix.java }}
cache: maven
- name: Test, javadoc and package
env:
CONVERT_API_SECRET: ${{ secrets.CONVERTAPI_STAGING_TOKEN }}
run: |
if [ -z "$CONVERT_API_SECRET" ]; then
echo "::warning::The CONVERTAPI_STAGING_TOKEN secret is not available to this run (a pull request from a fork gets no secrets), so the live API tests are skipped"
fi
# Surefire reruns a failed test twice; the staging API also answers 503 (no healthy upstream) in
# bursts of up to a minute, so the whole build gets up to three attempts, 30 s apart.
for attempt in 1 2 3; do
./mvnw install && exit 0
echo "::warning::Attempt $attempt: the build failed, see above"
sleep 30
done
echo "::error::The build failed three times"
exit 1
# The examples are not run (they need input files and write to the temp directory), only compiled
# against the library just built, so an API change that breaks them fails here.
- name: Compile the examples
run: ./mvnw -f examples/pom.xml -Dconvertapi.version=0.0.0-SNAPSHOT compile
build:
name: build
needs: test
# Runs even when a test job failed, so that the required check reports a failure instead of being
# skipped (a skipped required check counts as passed).
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Check every JDK passed
env:
RESULT: ${{ needs.test.result }}
run: |
if [ "$RESULT" != success ]; then
echo "::error::The tests did not pass on every JDK ($RESULT)"
exit 1
fi
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad # v6.1.0
with:
distribution: temurin
java-version: 17
cache: maven
# A pre-release version that sorts below any real release and names the run, so a jar downloaded
# from this run can be tried out but never mistaken for a published one. The tests ran above.
- name: Package
id: package
env:
RUN: ${{ github.run_number }}
SHORT_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
run: |
set -euo pipefail
VERSION="0.0.0-ci.$RUN.g${SHORT_SHA:0:7}"
./mvnw versions:set -DnewVersion="$VERSION" -DgenerateBackupPoms=false
./mvnw package -DskipTests
for f in "convertapi-$VERSION.jar" "convertapi-$VERSION-sources.jar" "convertapi-$VERSION-javadoc.jar"; do
test -f "target/$f" || { echo "::error::target/$f was not built"; exit 1; }
done
# Class file major version 52 = Java 8, which the library still supports.
MAJOR=$(unzip -p "target/convertapi-$VERSION.jar" com/convertapi/client/ConvertApi.class | od -An -j7 -N1 -tu1 | tr -d ' ')
[ "$MAJOR" = 52 ] || { echo "::error::The classes are compiled for class file version $MAJOR, not 52 (Java 8)"; exit 1; }
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: convertapi-${{ steps.package.outputs.version }}
path: |
target/convertapi-*.jar
pom.xml
retention-days: 14
if-no-files-found: error
- name: Summary
env:
VERSION: ${{ steps.package.outputs.version }}
run: |
{
echo "| | |"
echo "|---|---|"
echo "| Package | \`com.convertapi.client:convertapi:$VERSION\` (artifact only, not published) |"
echo "| Runs on | Java 8 and later (built and tested on JDK 17, 21 and 25) |"
} >> "$GITHUB_STEP_SUMMARY"