Improve workflow input handling (#34097)

* Improve workflow input handling by using environment variables with additional input validation and error handling
This commit is contained in:
Lorenzo
2025-10-10 08:35:13 -06:00
committed by GitHub
parent c597b4c70f
commit 5cefad29ee
+24 -5
View File
@@ -22,6 +22,8 @@ jobs:
permissions:
contents: write
runs-on: ubuntu-22.04
env:
COMMIT_SHA: ${{ inputs.commit_sha }}
steps:
- name: release/checkout-mattermost
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -32,14 +34,31 @@ jobs:
run: |
echo LATEST_MODULE_TAG=$(git tag --list 'server/public/*' --format='%(refname:lstrip=-1)' --sort -v:refname | head -1) >> ${GITHUB_ENV}
- name: release/validate-commit-sha
run: |
if [ -n "$COMMIT_SHA" ]; then
# Validate commit SHA format (40 character hex string)
if [[ ! "$COMMIT_SHA" =~ ^[a-f0-9]{40}$ ]]; then
echo "Error: Invalid commit SHA format. Must be a 40-character hexadecimal string."
exit 1
fi
# Verify the commit exists in the repository
if ! git cat-file -e "$COMMIT_SHA" 2>/dev/null; then
echo "Error: Commit SHA '$COMMIT_SHA' does not exist in the repository."
exit 1
fi
echo "Commit SHA validation passed: $COMMIT_SHA"
else
echo "No commit SHA provided, will use HEAD"
fi
- name: release/generate-module-release-notes
run: |
echo "RELEASE_NOTES<<EOF" >> ${GITHUB_ENV}
if [ "${{ inputs.commit_sha }}" = "" ];
then
echo "$(git log --oneline --graph --decorate --abbrev-commit server/public/${{ env.LATEST_MODULE_TAG }}...$(git rev-parse HEAD) server/public)" >> ${GITHUB_ENV}
else
echo "$(git log --oneline --graph --decorate --abbrev-commit server/public/${{ env.LATEST_MODULE_TAG }}...${{ inputs.commit_sha }} server/public)" >> ${GITHUB_ENV}
if [ -z "$COMMIT_SHA" ]; then
echo "$(git log --oneline --graph --decorate --abbrev-commit server/public/${{ env.LATEST_MODULE_TAG }}...$(git rev-parse HEAD) server/public)" >> ${GITHUB_ENV}
else
echo "$(git log --oneline --graph --decorate --abbrev-commit server/public/${{ env.LATEST_MODULE_TAG }}...${COMMIT_SHA} server/public)" >> ${GITHUB_ENV}
fi
echo "EOF" >> ${GITHUB_ENV}