-
Notifications
You must be signed in to change notification settings - Fork 2
245 lines (229 loc) · 9.32 KB
/
ant.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
name: Java CI
on:
workflow_call:
inputs:
josm-revision:
type: string
default: ''
description: The JOSM revision to use. May be empty (''), 'latest', 'tested', or 'rNUMBER' ('r10000')
required: false
operating-system:
type: string
default: ubuntu-latest
description: The operating system to run on
required: false
java-version:
type: number
default: 11
description: The java version to build against
required: false
java-distribution:
type: string
default: temurin
description: The java distribution to build against
required: false
plugin-jar-name:
type: string
default: ${{ github.event.repository.name }}
description: "The base name of the jar file, if not the repository name. Only useful in conjunction with `update-pluginssource`."
required: false
ant-version:
type: string
default: 'apache-ant-1.10.14'
perform-revision-tagging:
type: boolean
default: false
required: false
description: "Set to true if you want to automatically tag every push to the main branch for use with releasing"
revision-offset:
type: number
default: 0
required: false
description: "Set to an offset for automatic tagging. For example, if the last plugin version was 100, but there are only 20 commits, then this should be 80"
outputs:
tag:
description: "The release tag"
value: ${{ jobs.create_tag.outputs.revision }}
plugin_directory:
description: "The directory that the plugin has been cloned into"
value: ${{ jobs.plugin-build.outputs.plugin_directory }}
jobs:
josm-build:
runs-on: ${{ inputs.operating-system }}
outputs:
josm-revision: ${{ steps.josm-build.outputs.josm-revision }}
josm-test-revision: ${{ steps.josm-build.outputs.josm-test-revision }}
steps:
- uses: actions/setup-java@v4
with:
distribution: ${{ inputs.java-distribution }}
java-version: ${{ inputs.java-version }}
- id: josm-build
uses: JOSM/JOSMPluginAction/actions/josm_build@v3
with:
josm-revision: ${{ inputs.josm-revision }}
create_tag:
runs-on: ${{ inputs.operating-system }}
outputs:
revision: ${{ steps.create_revision.outputs.revision }}
steps:
- uses: actions/checkout@v4
if: ${{ inputs.perform-revision-tagging }}
with:
fetch-depth: 0
- name: Set revision env variable
if: ${{ inputs.perform-revision-tagging }}
id: create_revision
# Count the total commits for this branch
run: |
revision="v$(($(git rev-list --count HEAD) + ${{ inputs.revision-offset }}))"
git tag $revision
git push -u origin $revision
echo "revision=$revision" >> $GITHUB_OUTPUT
plugin-build:
runs-on: ${{ inputs.operating-system }}
needs: [josm-build, create_tag]
outputs:
plugin_directory: ${{ steps.version.outputs.plugin_directory }}
permissions:
id-token: write
attestations: write
steps:
- uses: JOSM/JOSMPluginAction/actions/setup-ant@v3
with:
ant-version: ${{ inputs.ant-version }}
- uses: JOSM/JOSMPluginAction/actions/plugin_clone@v3
with:
java-distribution: ${{ inputs.java-distribution }}
java-version: ${{ inputs.java-version }}
josm-revision: ${{ needs.josm-build.outputs.josm-revision }}
josm-test-revision: ${{ needs.josm-build.outputs.josm-test-revision }}
plugin-jar-name: ${{ inputs.plugin-jar-name }}
fetch-depth: 0
- name: Set version information
id: version
run: |
cd $GITHUB_WORKSPACE/josm/plugins/${{ github.event.repository.name }}
if [ $GITHUB_REF_TYPE == "tag" ]; then
version=$GITHUB_REF_NAME
else
version="$(git describe --tags --always --dirty --broken)"
fi
echo "version=${version#v}" >> $GITHUB_OUTPUT
echo "plugin_directory=josm/plugins/${{ github.event.repository.name }}" >> $GITHUB_OUTPUT
- name: Build with Ant
run: |
cd $GITHUB_WORKSPACE/josm/plugins/${{ github.event.repository.name }}
ant -noinput -buildfile build.xml -Dplugin.version=${{ steps.version.outputs.version }}
- name: Perform attestation
if: ${{ startsWith(github.ref, 'refs/tags/') || inputs.perform-revision-tagging }}
uses: actions/attest-build-provenance@v1
with:
subject-path: josm/dist/${{ inputs.plugin-jar-name }}.jar, josm/dist/${{ inputs.plugin-jar-name }}-sources.jar, josm/dist/${{ inputs.plugin-jar-name }}-javadoc.jar
- name: Upload plugin build
id: cache-plugin-build
uses: actions/upload-artifact@v4
with:
name: plugin-build-${{ inputs.java-version }}-${{ needs.josm-build.outputs.josm-revision }}
path: |
josm/dist/${{ inputs.plugin-jar-name }}.jar
josm/dist/${{ inputs.plugin-jar-name }}-javadoc.jar
josm/dist/${{ inputs.plugin-jar-name }}-sources.jar
plugin-test:
runs-on: ${{ inputs.operating-system }}
needs: [josm-build, plugin-build]
steps:
- uses: JOSM/JOSMPluginAction/actions/setup-ant@v3
with:
ant-version: ${{ inputs.ant-version }}
- uses: JOSM/JOSMPluginAction/actions/plugin_clone@v3
with:
java-distribution: ${{ inputs.java-distribution }}
java-version: ${{ inputs.java-version }}
josm-revision: ${{ needs.josm-build.outputs.josm-revision }}
josm-test-revision: ${{ needs.josm-build.outputs.josm-test-revision }}
- name: Check if ivy.xml exists
id: ivy-file-check
run: |
if [ -f "josm/plugins/${{ github.event.repository.name }}/ivy.xml" ]; then
echo "ivy-xml=true" >> $GITHUB_OUTPUT
else
echo "ivy-xml=false" >> $GITHUB_OUTPUT
fi
shell: bash
- name: Cache plugin test dependencies
id: cache-plugin-test-dependencies
if: steps.ivy-file-check.outputs.ivy-xml == 'true'
uses: actions/cache@v4
with:
key: ${{ runner.os }}-${{ runner.arch }}-ivy-plugin-test-${{ hashFiles('**/ivy.xml') }}
path: |
~/.ivy2/cache/
~/.ant/cache
- name: Test with Ant
id: ant-test
run: |
cd $GITHUB_WORKSPACE/josm/plugins/${{ github.event.repository.name }}
# Not all plugins have tests.
if [ -d "test" ]; then TEST_REPORT_PATH="test/report"; elif [ -d "src/test" ]; then TEST_REPORT_PATH="src/test/report"; else exit 0; fi
echo "TEST_REPORT_PATH=${TEST_REPORT_PATH}" >> $GITHUB_ENV
ant -diagnostics
ant -noinput -buildfile build.xml -Dplugin.version=$version -Dtest.headless=true test
- name: Upload Ant reports
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: Ant reports for JOSM plugin ${{ github.event.repository.name }}-${{ inputs.java-version }}-${{ needs.josm-build.outputs.josm-revision }}
path: |
josm/plugins/${{ github.event.repository.name }}/${{ env.TEST_REPORT_PATH }}/*.txt
josm/plugins/${{ github.event.repository.name }}/${{ env.TEST_REPORT_PATH }}/TEST*.xml
- name: Publish Test Report
uses: mikepenz/action-junit-report@v4
if: always() # always run even if the previous step fails
with:
report_paths: 'josm/plugins/${{ github.event.repository.name }}/${{ env.TEST_REPORT_PATH }}/TEST*.xml'
fail_on_failure: true
release:
runs-on: ${{ inputs.operating-system }}
needs: [create_tag, plugin-build, plugin-test, josm-build]
if: ${{ startsWith(github.ref, 'refs/tags/') || inputs.perform-revision-tagging }}
steps:
- name: Get build
id: cache-plugin-build
uses: actions/download-artifact@v4
with:
name: plugin-build-${{ inputs.java-version }}-${{ needs.josm-build.outputs.josm-revision }}
- name: Set revision env variable
id: create_revision
run: |
if [[ ! -z "${{ needs.create_tag.outputs.revision }}" ]]; then
revision="${{ needs.create_tag.outputs.revision }}"
else
revision="${{ github.ref_name }}"
fi
echo "revision=$revision" >> $GITHUB_OUTPUT
echo "revision_number=${revision#v}" >> $GITHUB_OUTPUT
- name: Generate update site
id: create_update_site
run: |
jarname="${{ inputs.plugin-jar-name }}.jar"
jarurl="https://github.com/${{ github.repository }}/releases/download/${{ steps.create_revision.outputs.revision }}/${jarname}"
echo "${jarname};$jarurl" > updatesite
unzip -p "${jarname}" META-INF/MANIFEST.MF | sed 's/^/\t/' >> updatesite
- name: Release
run: |
ls -R .
target="${{ steps.create_revision.outputs.revision }}"
if [ -z "$(gh --repo ${{ github.repository }} release view \"${target}\")" ]; then
gh release --repo ${{ github.repository }} create "${target}" \
--title "${target}" \
--latest \
--generate-notes
fi
gh release --repo ${{ github.repository }} upload --clobber "${target}" \
"${{ inputs.plugin-jar-name }}.jar" \
"${{ inputs.plugin-jar-name }}-javadoc.jar" \
"${{ inputs.plugin-jar-name }}-sources.jar" \
"updatesite"
env:
GH_TOKEN: ${{ github.token }}