75 lines
2.5 KiB
YAML
75 lines
2.5 KiB
YAML
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
|
|
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path
|
|
|
|
name: Maven Publish
|
|
|
|
on:
|
|
workflow_call:
|
|
secrets:
|
|
AWS_CA_TOKEN:
|
|
required: true
|
|
MVN_SETTINGS_XML:
|
|
required: true
|
|
JAVA_VERSION:
|
|
required: true
|
|
|
|
jobs:
|
|
build:
|
|
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Set up Maven
|
|
uses: stCarolas/setup-maven@v5
|
|
with:
|
|
maven-version: '3.9.9'
|
|
|
|
- name: Set up JDK 21
|
|
if: github.ref == 'refs/heads/feature/T2900-java21'
|
|
uses: actions/setup-java@v4
|
|
with:
|
|
java-version: '21'
|
|
distribution: 'corretto'
|
|
cache: maven
|
|
|
|
- name: Set up JDK from ENV
|
|
if: github.ref != 'refs/heads/feature/T2900-java21'
|
|
uses: actions/setup-java@v4
|
|
with:
|
|
java-version: '${{ secrets.JAVA_VERSION }}'
|
|
distribution: 'corretto'
|
|
cache: maven
|
|
|
|
- name: Create Maven settings
|
|
run: |
|
|
echo -e "$SETTINGS_XML" > ~/.m2/settings.xml
|
|
env:
|
|
SETTINGS_XML: ${{ secrets.MVN_SETTINGS_XML }}
|
|
|
|
- name: Build with Maven
|
|
run: |
|
|
mvn -B -U clean package --file pom.xml
|
|
|
|
- name: Deploy artifacts
|
|
run: |
|
|
mvn deploy -U --file pom.xml -DrepositoryId=pravila--pravila-maven
|
|
env:
|
|
GITHUB_TOKEN: ${{ github.token }}
|
|
CODEARTIFACT_AUTH_TOKEN: ${{ secrets.AWS_CA_TOKEN }}
|
|
|
|
- name: Delete artifact from Nexus
|
|
run: |
|
|
GROUP_ID=$(mvn help:evaluate -Dexpression="project.groupId" -q -DforceStdout)
|
|
ARTIFACT_ID=$(mvn help:evaluate -Dexpression="project.artifactId" -q -DforceStdout)
|
|
VERSION=$(mvn help:evaluate -Dexpression="project.version" -q -DforceStdout)
|
|
echo "Deleting artifact for $GROUP_ID:$ARTIFACT_ID:$VERSION"
|
|
curl --request DELETE --user "admin:$NEXUS_ADMIN_PASSWORD" https://devops.pravilanovait.hr/nexus/service/rest/v1/repositories/maven/proxy/amazon-codeartifact/content/$GROUP_ID/$ARTIFACT_ID/$VERSION/$ARTIFACT_ID-$VERSION.jar
|
|
curl --request POST --user "admin:$NEXUS_ADMIN_PASSWORD" https://devops.pravilanovait.hr/nexus/service/rest/v1/repositories/maven/proxy/amazon-codeartifact/invalidate-cache
|
|
env:
|
|
NEXUS_ADMIN_PASSWORD: ${{ secrets.NEXUS_ADMIN_PASSWORD }}
|