Add github workflow #22
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: Java CI with Maven and Release | |
on: | |
push: | |
branches: [ "main" ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: 11 | |
distribution: 'temurin' | |
cache: maven | |
- name: Build with Maven | |
run: mvn -B -f pom_for_bundle.xml -PbuildKar clean package -Dmaven.test.skip=true | |
- name: Determine Artifact Path | |
run: echo "ARTIFACT_PATH=$(ls target/nexus-oauth2-proxy-plugin-*-bundle.kar)" >> $GITHUB_ENV | |
- name: Upload Artifact to Workflow | |
uses: actions/upload-artifact@v3 | |
with: | |
name: nexus-oauth2-proxy-plugin-java-11.kar | |
path: ${{ env.ARTIFACT_PATH }} | |
prepare_release: | |
needs: build | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
outputs: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Generate tag and release name | |
run: | | |
TAG_NAME=$(date +'%Y%m%d%H%M%S')-$(git rev-parse --short HEAD) | |
echo "TAG_NAME=${TAG_NAME// /_}" >> $GITHUB_ENV | |
RELEASE_NAME="Release $(date +'%Y-%m-%d %H:%M:%S')" | |
echo "RELEASE_NAME=${RELEASE_NAME// /_}" >> $GITHUB_ENV | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ env.TAG_NAME }} | |
release_name: ${{ env.RELEASE_NAME }} | |
draft: false | |
prerelease: false | |
upload_release_asset: | |
needs: [prepare_release] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Download Artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: nexus-oauth2-proxy-plugin-java-11.kar | |
- name: Find KAR file | |
id: find_kar | |
run: | | |
kar_path=$(find . -name "*.kar") | |
kar_name=$(basename "$kar_path") | |
echo "KAR_PATH=$kar_path" >> $GITHUB_ENV | |
echo "kar_name=$kar_name" >> $GITHUB_ENV | |
echo "kar_name=$kar_name" >> $GITHUB_OUTPUT | |
- name: Upload Release Asset | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ needs.prepare_release.outputs.upload_url }} | |
asset_path: ${{ env.KAR_PATH }} | |
asset_name: ${{ env.kar_name }} | |
asset_content_type: application/zip |