name: CI on: create: pull_request: types: [ opened, synchronize, reopened ] push: branches: - master workflow_dispatch: defaults: run: shell: bash jobs: workflow_config: runs-on: ubuntu-latest outputs: do_release: ${{ steps.config.outputs.do_release }} do_snapshot_release: ${{ steps.config.outputs.do_snapshot_release }} pom_version: ${{ steps.config.outputs.pom_version }} steps: - name: Configure workflow id: config env: ACTOR: ${{ github.actor }} EVENT_ACTION: ${{ github.event.action }} REF_TYPE: ${{ github.event.ref_type }} REF: ${{ github.event.ref }} run: | cat <<-EOF ::group::Debug Info GITHUB_EVENT_NAME : '${GITHUB_EVENT_NAME}' EVENT_ACTION : '${EVENT_ACTION}' REF_TYPE : '${REF_TYPE}' REF : '${REF}' ACTOR : '${ACTOR}' GITHUB_REPOSITORY_OWNER : '${GITHUB_REPOSITORY_OWNER}' ::endgroup:: EOF # Do a release when a git tag starting with 'v' has been created by a suitable user. # (We match against github.repository_owner as a kludge so that forked repos can release themselves when testing the workflow) if [[ "${GITHUB_EVENT_NAME}" == "create" && "${REF_TYPE}" == "tag" && "${REF}" == v* && \ ( "${ACTOR}" == "arnaudroques" || "${ACTOR}" == "${GITHUB_REPOSITORY_OWNER}" ) \ ]]; then echo "::notice title=::This run will release '${REF}'" echo "::set-output name=do_release::true" echo "::set-output name=pom_version::${REF#v}" # pom_version is the tag without the 'v' prefix elif [[ "${GITHUB_EVENT_NAME}" =~ push|workflow_dispatch && "${REF}" == "refs/heads/master" ]]; then echo "::notice title=::This run will release a snapshot" echo "::set-output name=do_snapshot_release::true" else echo "This run will NOT make a release" fi # We run the tests on many OS / Java combinations but also the Compile step because some users build # their own jars from source, so it is good for CI to check that is working on all combinations. build: needs: workflow_config strategy: fail-fast: false matrix: java_version: [ 8, 11, 17 ] os: [ macos-10.15, macos-11, ubuntu-18.04, ubuntu-20.04, windows-2016, windows-2019, windows-2022 ] include: - release_from_this_build: true os: ubuntu-20.04 java_version: 8 runs-on: ${{ matrix.os }} steps: - name: Checkout the repository uses: actions/checkout@v2 - name: Set up java uses: actions/setup-java@v2.3.1 with: java-version: ${{ matrix.java_version }} distribution: temurin cache: maven # Downloading all the dependencies is very log spammy, so we do this in its own step. - name: Prime maven cache run: mvn --batch-mode dependency:go-offline # POM version is usually a -SNAPSHOT at this point, if this is a release then we use the version derived from the tag - name: Set POM version if: needs.workflow_config.outputs.do_release == 'true' env: POM_VERSION: ${{ needs.workflow_config.outputs.pom_version }} run: mvn --batch-mode versions:set "-DnewVersion=${POM_VERSION}" # Compile / Test / Package are separate steps so the reason for any failure is more obvious in GitHub UI - name: Compile run: mvn --batch-mode compile - name: Test run: mvn --batch-mode test - name: Package if: matrix.release_from_this_build run: mvn --batch-mode -DfinalName=plantuml -Dmaven.test.skip=true package - name: Upload jar artifacts if: matrix.release_from_this_build uses: actions/upload-artifact@v2 with: # Using github.run_number here to reduce confusion when downloading & comparing artifacts from several builds name: ${{ github.run_number }}-jars path: target/*.jar - name: Upload jar artifact (only simple jar - without javadoc or sources) if: ${{ matrix.release_from_this_build }} uses: actions/upload-artifact@v2 with: name: plantuml-jar path: | target/*.jar !target/*-javadoc.jar !target/*-sources.jar release: needs: [ workflow_config, build ] if: needs.workflow_config.outputs.do_release == 'true' || needs.workflow_config.outputs.do_snapshot_release == 'true' runs-on: ubuntu-latest steps: - name: Checkout the repository uses: actions/checkout@v2 - name: Download jar artifacts uses: actions/download-artifact@v2 with: name: ${{ github.run_number }}-jars - name: Create snapshot release if: needs.workflow_config.outputs.do_snapshot_release == 'true' env: GITHUB_TOKEN: ${{ github.token }} run: .github/scripts/release_snapshot.sh - name: Create release in GitHub if: needs.workflow_config.outputs.do_release == 'true' env: GITHUB_TOKEN: ${{ github.token }} POM_VERSION: ${{ needs.workflow_config.outputs.pom_version }} TAG: ${{ github.event.ref }} run: .github/scripts/release.sh