Publish #13
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: Publish | |
# Build, deploy and attach supported artifacts and draft release tag | |
on: | |
workflow_dispatch: | |
push: | |
tags: | |
- "v*.*.*" | |
jobs: | |
build_and_test: | |
name: Build and test java code | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Java | |
uses: actions/[email protected] | |
with: | |
java-version: 11 | |
- name: Build | |
run: mvn --no-transfer-progress clean compile | |
- name: Unit Test | |
run: mvn --no-transfer-progress test | |
build_jars: | |
if: success() | |
needs: [ build_and_test ] | |
name: Package and upload package to Maven Central | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Java | |
uses: actions/[email protected] | |
with: | |
java-version: 11 | |
server-id: ossrh | |
server-username: MAVEN_USERNAME | |
server-password: MAVEN_PASSWORD | |
gpg-private-key: ${{ secrets.GPG_SIGNING_KEY }} | |
gpg-passphrase: MAVEN_GPG_PASSPHRASE | |
- name: Package | |
run: | | |
mvn --no-transfer-progress -DskipTests clean package | |
- name: Publish to the Maven Central Repository | |
if: github.ref_type == 'tag' && startsWith(github.ref_name, 'v') | |
run: | | |
mvn --no-transfer-progress --batch-mode deploy | |
env: | |
MAVEN_USERNAME: ${{ secrets.OSSRH_USER_TOKEN }} | |
MAVEN_PASSWORD: ${{ secrets.OSSRH_PWD_TOKEN }} | |
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PWD }} | |
- name: Cache Jars | |
uses: actions/upload-artifact@v4 | |
with: | |
name: scanoss-jars-maven | |
path: ./target/*.jar | |
# Build all the native binaries for the given OSes | |
build_native: | |
if: success() | |
needs: [ build_and_test ] | |
name: Build native on ${{ matrix.os }} | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ubuntu-latest, macos-latest, windows-latest] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: graalvm/setup-graalvm@v1 | |
with: | |
java-version: '17' | |
distribution: 'graalvm' | |
- name: Version Details | |
run: | | |
echo "GRAALVM_HOME: $GRAALVM_HOME" | |
echo "JAVA_HOME: $JAVA_HOME" | |
java --version | |
native-image --version | |
- name: Native Build ${{ matrix.os }} | |
run: | | |
mvn --no-transfer-progress -Pnative -DskipTests package -X | |
- name: List Binaries | |
continue-on-error: true | |
run: | | |
ls target/scanoss-java* | |
- name: Rename Binary Windows | |
if: runner.os == 'Windows' | |
run: | | |
cd target | |
ren scanoss-java-*.exe scanoss-java-${{ matrix.os }}.exe | |
cd .. | |
- name: Rename Binary Unix | |
if: runner.os != 'Windows' | |
run: mv target/scanoss-java-* target/scanoss-java-${{ matrix.os }} | |
- name: List Packages | |
continue-on-error: true | |
run: | | |
ls target/ | |
- name: Test Binary Windows | |
if: runner.os == 'Windows' | |
shell: pwsh | |
run: | | |
.\target\scanoss-java-${{ matrix.os }}.exe -h | |
.\target\scanoss-java-${{ matrix.os }}.exe wfp src > fingers-${{ matrix.os }}.wfp | |
- name: Test Binary Unix | |
if: runner.os != 'Windows' | |
run: | | |
./target/scanoss-java-${{ matrix.os }} -h | |
./target/scanoss-java-${{ matrix.os }} wfp src > fingers-${{ matrix.os }}.wfp | |
wfps=$(fgrep 'file=' fingers-${{ matrix.os }}.wfp | wc -l) | |
echo "Found ${wfps} in src." | |
- name: Cache ${{ matrix.os }} Binary Unix | |
if: runner.os != 'Windows' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: scanoss-jars-${{ matrix.os }} | |
path: ./target/scanoss-java-${{ matrix.os }} | |
- name: Cache ${{ matrix.os }} Binary Windows | |
if: runner.os == 'Windows' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: scanoss-jars-${{ matrix.os }} | |
path: ./target/scanoss-java-${{ matrix.os }}.exe | |
merge: | |
runs-on: ubuntu-latest | |
needs: [build_jars, build_native] | |
steps: | |
- name: Merge artifacts | |
uses: actions/upload-artifact/merge@v4 | |
with: | |
name: scanoss-jars | |
pattern: scanoss-jars-* | |
# Upload all the jars and binaries a GH Release | |
create_release: | |
if: success() | |
needs: [ build_jars, build_native ] | |
name: Create Release | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Download Cached artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
pattern: scanoss-jars-* | |
merge-multiple: true | |
path: target | |
- name: List Packages | |
continue-on-error: true | |
run: | | |
ls -la target/ | |
- name: GH Release ${{ github.ref_type }} - ${{ github.ref_name }} | |
if: github.ref_type == 'tag' && startsWith(github.ref_name, 'v') | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
gh release create ${{github.ref_name}} \ | |
--draft \ | |
--repo ${{ github.server_url }}/${{ github.repository }} \ | |
--generate-notes \ | |
target/* scanoss-cli.sh |