feat(build): enhance version validation in build workflow to prevent branch names as version tags
This commit is contained in:
@@ -36,7 +36,15 @@ jobs:
|
|||||||
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ github.event.inputs.version }}" ]; then
|
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ github.event.inputs.version }}" ]; then
|
||||||
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
|
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
|
||||||
elif [[ "${{ github.ref }}" == refs/tags/* ]]; then
|
elif [[ "${{ github.ref }}" == refs/tags/* ]]; then
|
||||||
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
|
VERSION="${GITHUB_REF#refs/tags/}"
|
||||||
|
if [ -z "${VERSION}" ]; then
|
||||||
|
VERSION="${{ github.ref_name }}"
|
||||||
|
fi
|
||||||
|
if [ "${VERSION}" = "master" ] || [ "${VERSION}" = "main" ]; then
|
||||||
|
echo "Error: Invalid tag name '${VERSION}'. Tag name cannot be a branch name." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "version=${VERSION}" >> $GITHUB_OUTPUT
|
||||||
else
|
else
|
||||||
SHORT_SHA=$(git rev-parse --short HEAD)
|
SHORT_SHA=$(git rev-parse --short HEAD)
|
||||||
echo "version=${SHORT_SHA}" >> $GITHUB_OUTPUT
|
echo "version=${SHORT_SHA}" >> $GITHUB_OUTPUT
|
||||||
@@ -104,6 +112,19 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
- name: Validate version
|
||||||
|
run: |
|
||||||
|
VERSION="${{ steps.version.outputs.version }}"
|
||||||
|
if [ -z "${VERSION}" ]; then
|
||||||
|
echo "Error: Version is empty" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [ "${VERSION}" = "master" ] || [ "${VERSION}" = "main" ]; then
|
||||||
|
echo "Error: Invalid version '${VERSION}'. Version cannot be a branch name." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Using version: ${VERSION}"
|
||||||
|
|
||||||
- name: Create Release
|
- name: Create Release
|
||||||
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
|
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
|
||||||
uses: https://git.quad4.io/actions/gitea-release-action@4875285c0950474efb7ca2df55233c51333eeb74 # v1
|
uses: https://git.quad4.io/actions/gitea-release-action@4875285c0950474efb7ca2df55233c51333eeb74 # v1
|
||||||
|
|||||||
Reference in New Issue
Block a user