2121name : Deploy Documentation
2222
2323concurrency :
24- group : deploy-docs-${{ github.ref }}
24+ group : deploy-docs
2525 cancel-in-progress : false
2626
2727on :
3030 push :
3131 branches :
3232 - main
33- # checkov:skip=CKV_GHA_7: Inputs are sanitized via regex in the run block to prevent injection.
33+ # checkov:skip=CKV_GHA_7: Inputs are validated and sanitized via regex below to prevent injection.
3434 workflow_dispatch :
3535 inputs :
3636 version :
@@ -47,6 +47,7 @@ permissions:
4747
4848jobs :
4949 check-for-changes :
50+ if : github.event_name == 'push'
5051 name : Check for changes
5152 runs-on : ubuntu-latest
5253 outputs :
@@ -71,17 +72,46 @@ jobs:
7172 contents : write
7273 runs-on : ubuntu-latest
7374 timeout-minutes : 10
74- needs : check-for-changes
75+ needs : [ check-for-changes]
7576 if : |
76- needs.check-for-changes.outputs.changed == 'true' ||
77- github.event_name == 'workflow_dispatch' ||
78- github.event_name == 'release'
77+ github.event_name != 'push' ||
78+ needs.check-for-changes.outputs.changed == 'true'
7979 env :
8080 CI_COMMIT_AUTHOR : ' CI Bot'
8181 CI_COMMIT_EMAIL : ' ci@noreply.github.com'
8282 CI_COMMIT_MESSAGE : ' Continuous Integration - Deploy Documentation'
8383
8484 steps :
85+ - name : Validate Inputs
86+ id : validation
87+ env :
88+ MY_VERSION : ${{ github.event.inputs.version }}
89+ MY_ALIAS : ${{ github.event.inputs.alias }}
90+ # language=bash
91+ run : |
92+ if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
93+ if [[ ! "$MY_VERSION" =~ ^[a-zA-Z0-9._-]+$ ]]; then
94+ echo "::error::Invalid version name: $MY_VERSION. Only alphanumeric, dots, and hyphens allowed."
95+ exit 1
96+ fi
97+ if [[ -n "$MY_ALIAS" && ! "$MY_ALIAS" =~ ^[a-zA-Z0-9._-]+$ ]]; then
98+ echo "::error::Invalid alias name: $MY_ALIAS. Only alphanumeric, dots, and hyphens allowed."
99+ exit 1
100+ fi
101+ fi
102+
103+ if [ "${{ github.event_name }}" == "release" ]; then
104+ TARGET_REF="${{ github.event.release.tag_name }}"
105+ elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
106+ TARGET_REF="${{ github.event.inputs.version }}"
107+ else
108+ TARGET_REF="${{ github.ref }}"
109+ fi
110+
111+ echo "target_version=$MY_VERSION" >> "$GITHUB_OUTPUT"
112+ echo "target_alias=$MY_ALIAS" >> "$GITHUB_OUTPUT"
113+ echo "target_ref=$TARGET_REF" >> "$GITHUB_OUTPUT"
114+
85115 - name : Generate GitHub App Token
86116 id : generate_token
87117 uses : actions/create-github-app-token@v3
93123 uses : actions/checkout@v6
94124 with :
95125 token : ${{ steps.generate_token.outputs.token }}
126+ ref : ${{ steps.validation.outputs.target_ref }}
96127 fetch-depth : 0
97128
98129 - name : Set up Python
@@ -105,37 +136,24 @@ jobs:
105136 run : pip install -r requirements.txt
106137
107138 - name : Deploy Docs to GitHub Pages
108- env :
109- MY_VERSION : ${{ github.event.inputs.version }}
110- MY_ALIAS : ${{ github.event.inputs.alias }}
111- RELEASE_TAG : ${{ github.event.release.tag_name }}
139+ # language=bash
112140 run : |
113141 git config --global user.name "${{ env.CI_COMMIT_AUTHOR }}"
114142 git config --global user.email "${{ env.CI_COMMIT_EMAIL }}"
115143 git remote set-url origin https://x-access-token:${{ steps.generate_token.outputs.token }}@github.com/DigiLive/mushroom-strategy.git
116144
117145 if ! git fetch origin gh-pages --depth=1 2>/dev/null; then
118- echo "::notice::gh-pages branch does not exist yet. Mike will create it."
146+ echo "::notice::gh-pages branch does not exist yet. mike will create it."
119147 fi
120148
121149 if [ "${{ github.event_name }}" == "release" ]; then
122150 # Release: Create a permanent version folder and update latest alias.
123- mike deploy --push --update-aliases "$RELEASE_TAG " latest
151+ mike deploy --push --update-aliases "${{ github.event.release.tag_name }} " latest
124152 elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
125- # Manual: Use UI inputs for version and optional alias.
126- if [[ ! "$MY_VERSION" =~ ^[a-zA-Z0-9._-]+$ ]]; then
127- echo "::error::Invalid version name: $MY_VERSION. Only alphanumeric, dots, and hyphens allowed."
128- exit 1
129- fi
130- if [[ -n "$MY_ALIAS" && ! "$MY_ALIAS" =~ ^[a-zA-Z0-9._-]+$ ]]; then
131- echo "::error::Invalid alias name: $MY_ALIAS. Only alphanumeric, dots, and hyphens allowed."
132- exit 1
133- fi
134-
135- if [ -n "$MY_ALIAS" ]; then
136- mike deploy --push --update-aliases "$MY_VERSION" "$MY_ALIAS"
153+ if [ -n "${{ steps.validation.outputs.target_alias }}" ]; then
154+ mike deploy --push --update-aliases "${{ steps.validation.outputs.target_version }}" "${{ steps.validation.outputs.target_alias }}"
137155 else
138- mike deploy --push "$MY_VERSION "
156+ mike deploy --push "${{ steps.validation.outputs.target_version }} "
139157 fi
140158 else
141159 # Push: Update the /main/ folder
0 commit comments