diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index acdf72d..8c0bf60 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -67,9 +67,12 @@ jobs: registry-type: public - name: Validate and fixup Helm version + env: + # Pass inputs through the environment, never by interpolating + # expressions into the script, so input text cannot run as shell code. + INPUT_VERSION: ${{ inputs.version }} + FORCE_REPUBLISH: ${{ inputs.force_republish }} run: | - INPUT_VERSION="${{ github.event.inputs.version }}" - # Strip v prefix if present for helm chart version if [[ $INPUT_VERSION == v* ]]; then VERSION="${INPUT_VERSION#v}" @@ -85,7 +88,7 @@ jobs: exit 1 fi - if [[ "${{ github.event.inputs.force_republish }}" != "true" ]]; then + if [[ "$FORCE_REPUBLISH" != "true" ]]; then if [[ -n "$(git tag --list "$VERSION")" ]]; then echo "❌ Error: Version $VERSION already exists" echo "Please use a different version number" @@ -104,21 +107,30 @@ jobs: echo "CHART_VERSION=$VERSION" >> $GITHUB_ENV - name: Validate and fixup services version + env: + INPUT_SERVICES_VERSION: ${{ inputs.services_version }} run: | - if [ "${{ inputs.services_version }}" != "" ]; then - INPUT_SERVICES_VERSION="${{ inputs.services_version }}" + if [ "$INPUT_SERVICES_VERSION" != "" ]; then if [[ $INPUT_SERVICES_VERSION == v* ]]; then SERVICES_VERSION="$INPUT_SERVICES_VERSION" else SERVICES_VERSION="v$INPUT_SERVICES_VERSION" - echo "ℹ️ Added 'v' prefix to services version: ${{ inputs.services_version }} -> $SERVICES_VERSION" + echo "ℹ️ Added 'v' prefix to services version: $INPUT_SERVICES_VERSION -> $SERVICES_VERSION" + fi + + # The value is written to GITHUB_ENV and passed to lock_versions, + # so reject anything that is not a v-prefixed semver tag. + if [[ ! $SERVICES_VERSION =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$ ]]; then + echo "❌ Error: Services version '$INPUT_SERVICES_VERSION' is not a valid semver format" + echo "Expected format: [v]x.y.z[-prerelease][+build] (e.g., 1.2.3, v1.2.3)" + exit 1 fi echo "SERVICES_VERSION=$SERVICES_VERSION" >> $GITHUB_ENV fi - name: Prepare release branch run: | - if [[ "${{ github.event.inputs.force_republish }}" == "true" ]]; then + if [[ "$FORCE_REPUBLISH" == "true" ]]; then # Capture the SHA from the existing (broken) tag before we delete anything START_POINT=$(git rev-parse $CHART_VERSION) echo "ℹ️ Republishing from existing tag $CHART_VERSION @ $START_POINT" @@ -183,11 +195,12 @@ jobs: # In normal mode, fast-forward main to include the version bumps. # (Skipped for force_republish: the release branch diverges from main.) - if [[ "${{ github.event.inputs.force_republish }}" != "true" ]]; then + if [[ "$FORCE_REPUBLISH" != "true" ]]; then git push origin release/$CHART_VERSION:main fi env: GH_TOKEN: ${{ steps.bot-token.outputs.token }} + FORCE_REPUBLISH: ${{ inputs.force_republish }} - name: Create GitHub Release run: |