Skip to content

Build and Package master branch #83

Build and Package master branch

Build and Package master branch #83

name: Build and Package master branch
on:
workflow_dispatch:
schedule:
- cron: '55 2 * * *'
release:
types: [created]
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Maven Clean
run: mvn clean
- name: Maven Install
run: mvn install
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Extract Maven project groupId
run: echo "maven_groupId=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.groupId}' --non-recursive exec:exec)" >> "$GITHUB_ENV"
- name: Extract Maven project artifactId
run: echo "maven_artifactId=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.artifactId}' --non-recursive exec:exec)" >> "$GITHUB_ENV"
- name: Extract Maven project version
run: echo "maven_version=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)" >> "$GITHUB_ENV"
- name: Show extracted Maven project groupId, artifactId, version
run: printf '%s\n' "$maven_groupId" "$maven_artifactId" "$maven_version"
- name: Delete package or package version
uses: actions/github-script@v7
id: delete-package-version
with:
script: |
const packageName = process.env.maven_groupId + '.' + process.env.maven_artifactId
const org = context.repo.owner
const versionInfo = await github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg({
package_type: 'maven',
package_name: packageName,
org: org,
})
const versions = versionInfo.data
for (const version of versions) {
if (version.name == process.env.maven_version) {
/* This version is the maven version we want to delete: */
if (versions.length == 1) {
/* This version is the last version of the package so we have to delete the complete package: */
await github.rest.packages.deletePackageForOrg({
package_type: 'maven',
package_name: packageName,
org: context.repo.owner,
});
} else {
/* Remove this version from the package: */
await github.rest.packages.deletePackageVersionForOrg({
package_type: 'maven',
package_name: packageName,
org: context.repo.owner,
package_version_id: version.id,
});
}
break;
}
}
- name: Publish to GitHub Packages Apache Maven
run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml
env:
GITHUB_TOKEN: ${{ github.token }}