Skip to content
This repository has been archived by the owner on Aug 4, 2024. It is now read-only.

CI/CD

CI/CD #66

Workflow file for this run

name: CI/CD
on:
push:
branches:
- master
pull_request:
branches:
- master
workflow_dispatch:
inputs:
is-a-release:
description: Publish release? (Only works on master, and for untagged versions)
type: boolean
permissions:
contents: write
issues: write
checks: write
pull-requests: write
jobs:
test:
name: Run test suite
if: inputs.is-a-release == false
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
java-version: [ 11 ]
runs-on: ubuntu-latest
timeout-minutes: 35
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup JDK
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: ${{ matrix.java-version }}
check-latest: true
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Cache osxcross toolchain
uses: actions/cache@v3
with:
path: |
./osxcross/target/
key: ${{ runner.os }}-osxcross-${{ hashFiles('ci-setup.sh') }}
- name: Make CI script executable
run: chmod +x ./ci-setup.sh
- name: Execute CI script
run: ./ci-setup.sh
- name: Add osxcross to PATH
run: echo "$(pwd)/osxcross/target/bin" >> $GITHUB_PATH
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Test with Gradle
uses: gradle/gradle-build-action@v2
with:
arguments: test
env:
CSJ_FULL_BUILD: 1
- name: Upload test results
if: always()
uses: actions/upload-artifact@v3
with:
name: Test artifacts
retention-days: 21
path: |
**/TEST-*
**/hs_err_pid*
# Publishes the test results of 'test'
publish-test-results:
name: Publish tests results
if: inputs.is-a-release == false
needs: test
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v3
with:
path: artifacts
- name: Publish test results
uses: EnricoMi/publish-unit-test-result-action@v2
with:
check_name: Unit Test results
files: artifacts/unit-test-*/**/*.xml
# Builds the projects and attempts to publish a release if the current project version
# does not match any existing tags in the repository.
build-and-release:
name: Publish release
if: inputs.is-a-release && github.repository == 'native4j/capstone-java' && github.ref == 'refs/heads/master'
strategy:
fail-fast: true
runs-on: ubuntu-latest
timeout-minutes: 35
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0 # Required depth for JReleaser
- name: Setup Java JDK
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 11
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Cache osxcross toolchain
uses: actions/cache@v3
with:
path: |
./osxcross/target/
key: ${{ runner.os }}-osxcross-${{ hashFiles('ci-setup.sh') }}
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Download Gradle wrapper
run: ./gradlew --version
- name: Extract project version to environment variable
run: echo "PROJECT_VERSION=$(./gradlew properties | grep -Po '(?<=version\W ).*')" >> $GITHUB_ENV
# Check if a tag exists that matches the current project version.
# Write the existence state to the step output 'tagExists'.
- name: Check the package version has corresponding Git tag
id: tagged
shell: bash
run: |
git show-ref --tags --verify --quiet -- "refs/tags/${{ env.PROJECT_VERSION }}" && echo "tagExists=1" >> $GITHUB_OUTPUT || echo "tagExists=0" >> $GITHUB_OUTPUT
git show-ref --tags --verify --quiet -- "refs/tags/${{ env.PROJECT_VERSION }}" && echo "Tag for current version exists" || echo "Tag for current version does not exist"
# If the tag could not be fetched, show a message and abort the job.
# The wonky if logic is a workaround for: https://github.com/actions/runner/issues/1173
- name: Abort if tag exists, or existence check fails
if: ${{ false && steps.tagged.outputs.tagExists }}
run: |
echo "Output of 'tagged' step: ${{ steps.tagged.outputs.tagExists }}"
echo "Failed to check if tag exists."
echo "PROJECT_VERSION: ${{ env.PROJECT_VERSION }}"
echo "Tags $(git tag | wc -l):"
git tag
git show-ref --tags --verify -- "refs/tags/${{ env.PROJECT_VERSION }}"
exit 1
# Run build to generate the release artifacts.
# Tag does not exist AND trigger was manual. Deploy release artifacts!
- name: Make CI script executable
run: chmod +x ./ci-setup.sh
- name: Execute CI script
run: ./ci-setup.sh
- name: Add osxcross to PATH
run: echo "$(pwd)/osxcross/target/bin" >> $GITHUB_PATH
- name: Test with Gradle
uses: gradle/gradle-build-action@v2
with:
arguments: test
env:
CSJ_FULL_BUILD: 1
- name: Publish with Gradle
uses: gradle/gradle-build-action@v2
with:
arguments: publish
env:
CSJ_FULL_BUILD: 1
# Make release with JReleaser, only running when the project version does not exist as a tag on the repository.
- name: Publish release
uses: jreleaser/release-action@v2
with:
arguments: full-release
env:
JRELEASER_PROJECT_VERSION: ${{ env.PROJECT_VERSION }}
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.JRELEASER_GPG_PUBLIC_KEY }}
JRELEASER_GPG_SECRET_KEY: ${{ secrets.JRELEASER_GPG_SECRET_KEY }}
JRELEASER_GPG_PASSPHRASE: ${{ secrets.JRELEASER_GPG_PASSPHRASE }}
JRELEASER_NEXUS2_USERNAME: ${{ secrets.JRELEASER_DEPLOY_MAVEN_NEXUS2_USERNAME }}
JRELEASER_NEXUS2_PASSWORD: ${{ secrets.JRELEASER_DEPLOY_MAVEN_NEXUS2_PASSWORD }}
# Upload JRelease debug log
- name: JReleaser output
uses: actions/upload-artifact@v3
if: always()
with:
name: jreleaser-release
path: |
out/jreleaser/trace.log
out/jreleaser/output.properties