Skip to content

Commit e10008a

Browse files
authored
Validate release workflow version inputs (#132)
Add an explicit validation step for workflow inputs. Subsequent steps refer to the validated output values rather than raw input.
1 parent 709816c commit e10008a

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

.github/workflows/release.yml

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,25 @@ jobs:
2424
packages: write
2525

2626
steps:
27+
- name: Validate version input
28+
id: validation
29+
env:
30+
INPUT_RELEASE_VERSION: ${{ inputs.version }}
31+
INPUT_SNAPSHOT_VERSION: ${{ inputs.snapshot }}
32+
run: |
33+
if ! [[ "$INPUT_RELEASE_VERSION" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
34+
echo "Invalid version";
35+
exit 1;
36+
fi
37+
38+
if ! [[ "$INPUT_SNAPSHOT_VERSION" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)(-SNAPSHOT)?$ ]]; then
39+
echo "Invalid snapshot version";
40+
exit 1;
41+
fi
42+
43+
echo "release_version=$INPUT_RELEASE_VERSION" >> "$GITHUB_OUTPUT"
44+
echo "snapshot_version=$INPUT_SNAPSHOT_VERSION" >> "$GITHUB_OUTPUT"
45+
2746
- name: Checkout
2847
uses: actions/checkout@v4
2948

@@ -53,21 +72,21 @@ jobs:
5372

5473
- name: Get Snapshot versions
5574
id: snapshotVersions
56-
run: ./scripts/get_snapshot_versions.sh ${{ inputs.snapshot }}
75+
run: ./scripts/get_snapshot_versions.sh ${{ steps.validation.outputs.snapshot_version }}
5776

5877
- name: Prepare for release metadata
5978
shell: bash
6079
run: |
61-
sed -i.bak "s/${{ steps.snapshotVersions.outputs.cur_snapshot_version }}/${{ inputs.version }}/g" gradle.properties
80+
sed -i.bak "s/${{ steps.snapshotVersions.outputs.cur_snapshot_version }}/${{ steps.validation.outputs.release_version }}/g" gradle.properties
6281
63-
- name: Commit gradle.properties and set tag for v${{ inputs.version }}
82+
- name: Commit gradle.properties and set tag for v${{ steps.validation.outputs.release_version }}
6483
uses: IABTechLab/uid2-shared-actions/actions/commit_pr_and_merge@v2
6584
with:
6685
add: 'gradle.properties'
67-
message: 'Prepare for release: ${{ inputs.version }}'
68-
tag: v${{ inputs.version }}
86+
message: 'Prepare for release: ${{ steps.validation.outputs.release_version }}'
87+
tag: v${{ steps.validation.outputs.release_version }}
6988

70-
- name: Deploy v${{ inputs.version }}
89+
- name: Deploy v${{ steps.validation.outputs.release_version }}
7190
run: ./gradlew publish
7291
env:
7392
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.CENTRAL_SONATYPE_REPO_USERNAME }}
@@ -79,7 +98,7 @@ jobs:
7998
shell: bash
8099
run: |
81100
echo "Setting next snapshot version ${{ steps.snapshotVersions.outputs.new_snapshot_version }}"
82-
sed -i.bak "s/${{ inputs.version }}/${{ steps.snapshotVersions.outputs.new_snapshot_version }}/g" gradle.properties
101+
sed -i.bak "s/${{ steps.validation.outputs.release_version }}/${{ steps.snapshotVersions.outputs.new_snapshot_version }}/g" gradle.properties
83102
84103
- name: Commit gradle.properties for Snapshot version ${{ steps.snapshotVersions.outputs.new_snapshot_version }}
85104
uses: IABTechLab/uid2-shared-actions/actions/commit_pr_and_merge@v2
@@ -96,4 +115,4 @@ jobs:
96115
uses: softprops/action-gh-release@v2
97116
with:
98117
generate_release_notes: true
99-
tag_name: v${{ inputs.version }}
118+
tag_name: v${{ steps.validation.outputs.release_version }}

0 commit comments

Comments
 (0)