source: josm/trunk/.github/workflows/ant.yml @ 17486

Last change on this file since 17486 was 17373, checked in by Don-vip, 12 months ago

see #20146 - Improvements to macOS build and github actions (patch by Stereo)

From https://github.com/openstreetmap/josm/pull/67:

  • Separate the create-release github action to pass the release url to all subsequent jobs, to be able to...
  • Upload .jar artefacts from all runs, and a separate .app for all java versions for macOS
  • Better caching for ant/junit
  • Support for the release workflow from #20146
  • A few cosmetic fixes, more readable syntax, etc.
File size: 7.7 KB
Line 
1name: Java CI
2env:
3  junit_platform_version: '1.7.0'
4  # ANT_HOME is also our ant version
5  ANT_HOME: 'apache-ant-1.10.9'
6on:
7  push:
8    branches: [master]
9  pull_request:
10    branches: [master]
11
12defaults:
13  run:
14    shell: bash
15
16jobs:
17  createrelease:
18    name: Create Release
19    runs-on: ubuntu-latest
20    env:
21      LANG: en_US.UTF-8
22    outputs:
23      upload_url: ${{ steps.create_release.outputs.upload_url }}
24      josm_revision: ${{ steps.create_revision.outputs.josm_revision }}
25      josm_prerelease: ${{ steps.create_revision.outputs.josm_prerelease }}
26    steps:
27      - name: Checkout
28        uses: actions/checkout@v2
29        with:
30          fetch-depth: 32
31      - name: Set revision env variable
32        id: create_revision
33        # grab josm revision from last git-svn-id
34        run: |
35          josm_revision="$(git log -1 --grep 'git-svn-id: https://josm.openstreetmap.de/svn/trunk@' --pretty=format:%B | tail -1 | sed -n 's%git-svn-id: https://josm.openstreetmap.de/svn/trunk@\([0-9]*\) [-0-9a-f]*%\1%p')"
36          if [[ "$josm_revision" == "$(curl --silent https://josm.openstreetmap.de/tested)" ]]; then
37            sed -i '/Is-Local-Build/d' resources/REVISION
38            echo "josm_prerelease=false" >> $GITHUB_ENV
39            echo "::set-output name=josm_prerelease::false"
40            echo "josm_release=$josm_revision-tested" >> $GITHUB_ENV
41          else
42            echo "josm_prerelease=true" >> $GITHUB_ENV
43            echo "::set-output name=josm_prerelease::true"
44            echo "josm_release=$josm_revision" >> $GITHUB_ENV
45          fi
46          echo "josm_revision=$josm_revision" >> $GITHUB_ENV
47          echo "::set-output name=josm_revision::$josm_revision"
48      - name: Create release
49        id: create_release
50        uses: actions/create-release@v1
51        env:
52          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
53        with:
54          tag_name: ${{ env.josm_release }}
55          release_name: JOSM.app release ${{ env.josm_release }}
56          body: |
57            JOSM.app release ${{ env.josm_release }}
58          draft: false
59          prerelease: ${{ env.josm_prerelease }}
60  build:
61    needs: createrelease
62    runs-on: ${{ matrix.os }}
63    env:
64      LANG: en_US.UTF-8
65    strategy:
66      fail-fast: false
67      matrix:
68        # test against latest update of each major Java version, as well as specific updates of LTS versions:
69        java: [8, 11, 15, 16-ea]
70        os: [ubuntu-latest, macos-latest, windows-latest]
71        headless: ["true", "false"]
72        exclude:
73          - java: 8
74            os: macos-latest
75          - java: 11
76            os: macos-latest
77          - headless: "false"
78            os: macos-latest
79          - headless: "false"
80            os: windows-latest
81    name: Java ${{ matrix.java }} on ${{ matrix.os }} with headless=${{ matrix.headless }}
82    steps:
83      - name: Checkout
84        uses: actions/checkout@v2
85        with:
86          fetch-depth: 32
87      - name: Cache
88        uses: actions/cache@v2.0.0
89        with:
90          path:  |
91            ~/.ivy2/cache/
92            ~/work/josm/josm/tools/
93            build-tools-cache/
94          key: ${{ runner.os }}-ivy2-${{ hashFiles('ivy.xml') }}
95      - name: Setup java
96        uses: actions/setup-java@v1.4.3
97        with:
98          java-version: ${{ matrix.java }}
99      - name: Install ant ${{ env.ANT_HOME }} and junit ${{ env.junit_platform_version }}
100        run: |
101          mkdir -p build-tools-cache/
102          cd build-tools-cache/
103          if [ ! -f ${{ env.ANT_HOME }}-bin.tar.gz ]; then
104            curl -o ${{ env.ANT_HOME }}-bin.tar.gz https://downloads.apache.org/ant/binaries/${{ env.ANT_HOME }}-bin.tar.gz
105          fi
106          if [ ! -f junit-platform-console-standalone-${{ env.junit_platform_version }}.jar ]; then
107            curl -o junit-platform-console-standalone-${{ env.junit_platform_version }}.jar https://repo1.maven.org/maven2/org/junit/platform/junit-platform-console-standalone/${{ env.junit_platform_version }}/junit-platform-console-standalone-${{ env.junit_platform_version }}.jar
108          fi
109          cd ..
110          tar zxf build-tools-cache/${{ env.ANT_HOME }}-bin.tar.gz
111          cp build-tools-cache/junit-platform-console-standalone-${{ env.junit_platform_version }}.jar ${{ env.ANT_HOME }}/lib/junit-platform-console-standalone-${{ env.junit_platform_version }}.jar
112      - name: Print ant version, expecting ${{ env.ANT_HOME }}
113        run: ${{ env.ANT_HOME }}/bin/ant -version
114      - name: Optimise images
115        if: ${{ runner.os == 'macos' && always() }}
116        run: |
117          brew cask install imageoptim
118          defaults write net.pornel.ImageOptim SvgoEnabled 1
119          defaults write net.pornel.ImageOptim PngCrush2Enabled 1
120          defaults write net.pornel.ImageOptim PngOutEnabled 1
121          /Applications/ImageOptim.app/Contents/MacOS/ImageOptim resources/images
122      - name: Build with Ant
123        # Disables errorprone for Java 16
124        # See https://github.com/google/error-prone/issues/1872
125        run: |
126          if [[ "x${{ matrix.java }}x" =~ x1[6-9](-ea)?x ]]; then
127            ${{ env.ANT_HOME }}/bin/ant -DnoErrorProne dist
128          else
129            ${{ env.ANT_HOME }}/bin/ant dist
130          fi
131      - name: Upload jar
132        if: ${{ always() && matrix.headless }}
133        id: upload-jar
134        uses: actions/upload-release-asset@v1
135        env:
136          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
137        with:
138          upload_url: ${{ needs.createrelease.outputs.upload_url }} # This pulls from the CREATE RELEASE job above, referencing its ID to get its outputs object, which include a `upload_url`.
139          asset_path: dist/josm-custom.jar
140          asset_name: JOSM-${{ runner.os}}-java${{ matrix.java }}-${{ needs.createrelease.outputs.josm_revision }}.jar
141          asset_content_type: application/java-archive
142      - name: Test with Ant, headless ${{ matrix.headless }}
143        if: ${{ needs.createrelease.outputs.josm_prerelease }}
144        run: |
145          ANT="${{ env.ANT_HOME }}/bin/ant -DnoJavaFX=true test-unit-hardfail"
146          if [ "${{ matrix.headless }}" == "true" ]; then
147            $ANT -Dtest.headless=true
148          else
149            xvfb-run $ANT -Dtest.headless=false
150          fi
151      - name: Dump errors if failed
152        if: ${{ failure() }}
153        run: "grep -L ', Failures: 0, Skipped: ' test/report/*.txt | xargs cat"
154      - name: Upload Ant reports
155        if: ${{ always() }}
156        uses: actions/upload-artifact@v2
157        with:
158          name: Ant reports for JOSM ${{ needs.createrelease.outputs.josm_revision }} on java ${{ matrix.java }} on ${{ matrix.os }} with headless=${{ matrix.headless }}
159          path: test/report/*.txt
160      - name: Build and package for macOS
161        if: ${{ runner.os == 'macos' && always() }}
162        env:
163          CERT_MACOS_P12: ${{ secrets.CERT_MACOS_P12 }}
164          CERT_MACOS_PW: ${{ secrets.CERT_MACOS_PW }}
165          APPLE_ID_PW: ${{ secrets.APPLE_ID_PW }}
166        run: |
167          ./native/macosx/macos-jpackage.sh ${{ needs.createrelease.outputs.josm_revision }}
168      - name: Upload app
169        if: ${{ runner.os == 'macos' && always() }}
170        id: upload-app
171        uses: actions/upload-release-asset@v1
172        env:
173          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
174        with:
175          upload_url: ${{ needs.createrelease.outputs.upload_url }} # This pulls from the CREATE RELEASE job above, referencing its ID to get its outputs object, which include a `upload_url`.
176          asset_path: app/JOSM.zip
177          asset_name: JOSM-${{ runner.os}}-java${{ matrix.java }}.zip
178          asset_content_type: application/zip
Note: See TracBrowser for help on using the repository browser.