Skip to content

Commit c45800e

Browse files
committed
Compute safe branch name
1 parent 6f4f874 commit c45800e

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

.github/workflows/publish-snapshot.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,25 @@ jobs:
3131
uses: gradle/actions/setup-gradle@v4
3232

3333
- name: Generate snapshot version
34-
id: version
34+
id: snapshot_version
3535
run: |
36-
COMMIT_HASH=$(git rev-parse --short ${{ github.sha }})
37-
# Replace slashes in branch name with dashes for proper versioning
38-
SNAPSHOT_VERSION="${BRANCH_NAME//\//-}+${COMMIT_HASH}"
39-
echo "snapshot_version=${SNAPSHOT_VERSION}" >> $GITHUB_OUTPUT
40-
echo "Generated snapshot version: ${SNAPSHOT_VERSION}"
41-
echo "::notice title=Snapshot Version::${SNAPSHOT_VERSION}"
36+
# Replace non-alphanumeric characters in branch name with hyphens
37+
SAFE_BRANCH=$(echo "${BRANCH_NAME}" | sed 's#[^A-Za-z0-9._-]#-#g')
38+
SHORT_SHA=$(echo "${GITHUB_SHA}" | cut -c1-8)
39+
VERSION="${SAFE_BRANCH}+${SHORT_SHA}"
40+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
41+
echo "::notice title=Snapshot Version::Generated snapshot version: ${VERSION}"
4242
4343
- name: Publish snapshot
44-
run: ./gradlew publish -Pversion=${{ steps.version.outputs.snapshot_version }}
44+
run: ./gradlew publish -Pversion=${{ steps.snapshot_version.outputs.version }}
4545
env:
4646
GITHUB_ACTOR: ${{ github.actor }}
4747
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4848

4949
- name: Write summary
5050
run: |
5151
echo "## 📦 Snapshot Published" >> $GITHUB_STEP_SUMMARY
52-
echo "**Version:** \`${{ steps.version.outputs.snapshot_version }}\`" >> $GITHUB_STEP_SUMMARY
52+
echo "**Project:** \`${{ github.repository }}\`" >> $GITHUB_STEP_SUMMARY
53+
echo "**Version:** \`${{ steps.snapshot_version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
5354
echo "**Branch:** \`${BRANCH_NAME}\`" >> $GITHUB_STEP_SUMMARY
54-
echo "**Commit:** \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY
55-
echo "**Repository:** GitHub Packages" >> $GITHUB_STEP_SUMMARY
55+
echo "**Commit:** \`${GITHUB_SHA}\`" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)