Repository navigation
Redo commented code 2 #20
Workflow file for this run
This file contains hidden or 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: Publish package to GitHub Packages | ||
| on: | ||
| release: | ||
| types: | ||
| - published | ||
| workflow_dispatch: | ||
| jobs: | ||
| publish: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| packages: write | ||
| steps: | ||
| - | ||
| uses: actions/checkout@v4 | ||
| - # Extract version from tag (if release triggered) | ||
| name: Extract version from tag (if release) | ||
| id: extract_version | ||
| if: ${{ -z github.event.release }} == false && ${{ -z github.event.release.tag_name }} == false | ||
| run: | | ||
| version=$(echo "${{ github.event.release.tag_name }}" | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+') | ||
| if [[ -z "$version" ]]; then | ||
| echo "::error:: No version found in tag name: ${{ github.event.release.tag_name }}" | ||
| exit 1 | ||
| fi | ||
| echo "::set-output name=jar_version::$version" | ||
| - # Fallback version for manual triggers | ||
| name: Generate fallback version (if manual trigger) | ||
| id: fallback_version | ||
| if: ${{ github.event.release.tag_name }} == '' | ||
| run: | | ||
| # Try to find the latest tag | ||
| latest_tag=$(git describe --tags --abbrev=0 HEAD) | ||
| # If no tags exist, use the current commit SHA | ||
| if [[ -z "$latest_tag" ]]; then | ||
| echo "Unable to find latest tag" | ||
| exit 1 | ||
| fi | ||
| # Extract the version number from the tag (if tag format allows) | ||
| version=$(echo "$latest_tag" | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+') | ||
| # If no version found in tag, fallback to "latest" | ||
| if [[ -z "$version" ]]; then | ||
| echo "Unable to extract version from tag: $latest_tag" | ||
| exit 1 | ||
| fi | ||
| # Get the first 7 characters of the latest commit SHA | ||
| latest_commit_sha=$(git rev-parse HEAD:short) | ||
| # Combine version and SHA for fallback version | ||
| fallback_version=$(echo "$version-${latest_commit_sha}") | ||
| echo "::set-output name=jar_version::$fallback_version" | ||
| - | ||
| name: Echo versions | ||
| run: | | ||
| echo "Extracted version: ${{ steps.extract_version.outputs.jar_version }}" | ||
| echo "Fallback version: ${{ steps.fallback_version.outputs.jar_version }}" | ||
| echo "Deploy command: mvn --batch-mode deploy -Dversion=${{ steps.extract_version.outputs.jar_version || steps.fallback_version.outputs.jar_version }}" | ||
| # - | ||
| # uses: actions/setup-java@v4 | ||
| # with: | ||
| # java-version: '21' | ||
| # distribution: 'corretto' | ||
| # - | ||
| # name: Publish package | ||
| # run: mvn --batch-mode deploy -Dversion=${{ steps.extract_version.outputs.jar_version || steps.fallback_version.outputs.jar_version }} | ||
| # env: | ||
| # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||