Bump actions/checkout from 3 to 4 #1112
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Continuous Integration | |
on: [push, pull_request, workflow_dispatch] | |
jobs: | |
check_duplicate_workflows: | |
name: Check for duplicate workflows | |
runs-on: ubuntu-latest | |
if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }} | |
# Map a step output to a job output | |
outputs: | |
should_skip: ${{ steps.skip_check.outputs.should_skip }} | |
steps: | |
- id: skip_check | |
uses: fkirc/skip-duplicate-actions@master | |
with: | |
skip_after_successful_duplicate: 'false' | |
concurrent_skipping: 'same_content' | |
do_not_skip: '["pull_request", "workflow_dispatch", "schedule"]' | |
paths_ignore: '["**/*.md"]' | |
build: | |
name: Build | |
runs-on: ${{ matrix.platform }} | |
needs: [check_duplicate_workflows] | |
if: ${{ needs.check_duplicate_workflows.outputs.should_skip != 'true' }} | |
strategy: | |
matrix: | |
java: [ '8', '11', '17' ] | |
platform: ['windows-latest', 'ubuntu-latest'] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK ${{ matrix.java }} | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'adopt' | |
java-version: ${{ matrix.java }} | |
cache: 'gradle' | |
- name: print Java version | |
run: java -version | |
- name: Run build | |
run: ./gradlew clean assemble --info | |
test: | |
name: Test | |
runs-on: ${{ matrix.platform }} | |
needs: [build] | |
strategy: | |
matrix: | |
java: [ '8', '11', '17' ] | |
platform: ['windows-latest', 'ubuntu-latest'] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Gradle wrapper validation | |
uses: gradle/wrapper-validation-action@v3 | |
- name: Set up JDK | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'adopt' | |
java-version: ${{ matrix.java }} | |
cache: 'gradle' | |
- name: print Java version | |
run: java -version | |
- name: Run test | |
run: ./gradlew check --info | |
publish: | |
name : Publish | |
runs-on: ubuntu-latest | |
needs: [ test ] | |
if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && github.repository == 'tschuchortdev/kotlin-compile-testing' | |
env: | |
# https://proandroiddev.com/publishing-a-maven-artifact-3-3-step-by-step-instructions-to-mavencentral-publishing-bd661081645d | |
SONATYPE_NEXUS_USERNAME: ${{ secrets.SONATYPE_NEXUS_USERNAME }} | |
SONATYPE_NEXUS_PASSWORD: ${{ secrets.SONATYPE_NEXUS_PASSWORD }} | |
# https://blog.solidsoft.pl/2020/06/03/simpler-and-safer-artifact-signing-on-ci-server-with-gradle/ | |
# https://stackoverflow.com/questions/57921325/gradle-signarchives-unable-to-read-secret-key | |
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SONATYPE_SIGNING_KEY_PASSWORD }} | |
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SONATYPE_SIGNING_PRIVATE_KEY }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
persist-credentials: false # without this, all access tokens set later on will be ignored | |
- name: Set up JDK | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'adopt' | |
java-version: 11 | |
cache: 'gradle' | |
- name: Set git config | |
run: | | |
git config user.name github-actions | |
git config user.email [email protected] | |
- name: Check if snapshot version | |
run: | | |
VERSION_NAME=$(./gradlew -q printVersionName | tail -n 1) | |
echo "VERSION_NAME=$VERSION_NAME" >> $GITHUB_ENV | |
IS_SNAPSHOT_VERSION=$([[ "$VERSION_NAME" =~ ^[0-9]+\.[0-9]+\.[0-9]+-SNAPSHOT$ ]] && echo "true" || echo "false") | |
echo "IS_SNAPSHOT_VERSION=$IS_SNAPSHOT_VERSION" >> $GITHUB_ENV | |
- name: Publish to Sonatype Nexus | |
run: | | |
# --max-workers 1 limits Gradle to a single thread even if parallel builds are enabled in the hopes | |
# of making the the upload to Sonatype Nexus less flaky | |
if [[ "$IS_SNAPSHOT_VERSION" == "true" ]]; then | |
echo "Version is a snapshot. No closing of the repository is necessary." | |
./gradlew publishToSonatype --info --max-workers 1 | |
elif [[ "$IS_SNAPSHOT_VERSION" == "false" ]]; then | |
echo "Version is not a snapshot. Trying to close and release repository." | |
# Note: Until https://github.com/gradle-nexus/publish-plugin/issues/19 is fixed | |
# publish and close/release always have to be executed in the same Gradle call | |
# or closing will fail with error 'No staging repository with name sonatype created'. | |
./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository --info --max-workers 1 | |
else | |
echo "IS_SNAPSHOT_VERSION has unknown value: $IS_SNAPSHOT_VERSION" | |
exit 1 | |
fi | |
- name: Make release on Github | |
uses: marvinpinto/action-automatic-releases@latest | |
if: ${{ env.IS_SNAPSHOT_VERSION == 'false' }} | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
automatic_release_tag: ${{ env.VERSION_NAME }} | |
prerelease: false | |
title: ${{ env.VERSION_NAME }} | |
files: | | |
LICENSE | |
core/build/libs/*.* | |
ksp/build/libs/*.* | |
- name: Set next snapshot version | |
if: ${{ env.IS_SNAPSHOT_VERSION == 'false' }} | |
run: | | |
echo "Setting next snapshot version" | |
./gradlew incrementPatchVersion --info | |
./gradlew setSnapshotVersionSuffix --info | |
git add gradle.properties | |
git commit -m "Setting next snapshot version [skip ci]" | |
git push https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git --follow-tags |