In my Gradle project I have a hardcoded project version – SNAPSHOT.
When I push a new version – everything is OK, but if I push the same version for 2nd time – publishing fails. How can I tell GitHub that I want to override existing package?
For GitHub Actions I have a workflow to publish that project on every push to the main branch:
name: Publish package to GitHub Packages
on:
push:
branches: ['main']
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: '18'
cache: 'gradle'
- name: Publish package
uses: gradle/gradle-build-action@v2
with:
arguments: publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
I’m expecting a new package with the same version to be publish to the GitHub Packages.
2
Answers
Since I did not found any GitHub Action for my task, I decided to create one: https://github.com/marketplace/actions/version-cleaner-action
This is possible but first you need to delete that package version and then republish it.
But keep in mind that: