diff --git a/.github/workflows/build-package-development.yml b/.github/workflows/build-package-development.yml index 83fc7309..63aac37a 100644 --- a/.github/workflows/build-package-development.yml +++ b/.github/workflows/build-package-development.yml @@ -47,6 +47,43 @@ jobs: - 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: