fix: improve secret validation check #11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - "v*" | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: "Tag version to use (e.g., v1.2.0)" | |
| required: true | |
| type: string | |
| permissions: | |
| contents: read | |
| jobs: | |
| check-required-config: | |
| name: Check Required Variables and Secrets | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check required variables | |
| run: | | |
| MISSING_VARS=() | |
| if [ -z "${{ vars.DOCKERHUB_USERNAME }}" ]; then | |
| MISSING_VARS+=("DOCKERHUB_USERNAME") | |
| fi | |
| if [ -z "${{ vars.DB_IMAGE_REPO }}" ]; then | |
| MISSING_VARS+=("DB_IMAGE_REPO") | |
| fi | |
| if [ ${#MISSING_VARS[@]} -gt 0 ]; then | |
| echo "❌ Missing required variables:" | |
| printf ' - %s\n' "${MISSING_VARS[@]}" | |
| exit 1 | |
| fi | |
| echo "✅ All required variables are set" | |
| - name: Check required secrets | |
| run: | | |
| MISSING_SECRETS=() | |
| # Check DOCKERHUB_ACCESS_TOKEN - if empty or just whitespace, it's missing | |
| DOCKERHUB_TOKEN="${{ secrets.DOCKERHUB_ACCESS_TOKEN }}" | |
| if [ -z "${DOCKERHUB_TOKEN}" ] || [ "${DOCKERHUB_TOKEN}" = "" ]; then | |
| MISSING_SECRETS+=("DOCKERHUB_ACCESS_TOKEN") | |
| fi | |
| if [ ${#MISSING_SECRETS[@]} -gt 0 ]; then | |
| echo "❌ Missing required secrets:" | |
| printf ' - %s\n' "${MISSING_SECRETS[@]}" | |
| echo "" | |
| echo "Please ensure all required secrets are configured in repository settings." | |
| exit 1 | |
| fi | |
| echo "✅ All required secrets are set" | |
| build-and-push-to-dockerhub: | |
| name: Build / Push to Dockerhub | |
| needs: [check-required-config] | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: TEST | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set tag name | |
| id: tag | |
| run: | | |
| if [ "${{ github.event_name }}" == "release" ]; then | |
| echo "tag_name=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT | |
| elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |
| echo "tag_name=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT | |
| elif [[ "${{ github.ref }}" == refs/tags/* ]]; then | |
| echo "tag_name=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT | |
| else | |
| echo "tag_name=latest" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Login to Dockerhub | |
| run: echo "${{ secrets.DOCKERHUB_ACCESS_TOKEN }}" | docker login -u "${{ vars.DOCKERHUB_USERNAME }}" --password-stdin | |
| - name: Build and push | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| tags: ${{ vars.DOCKERHUB_USERNAME }}/${{ vars.DB_IMAGE_REPO }}:${{ steps.tag.outputs.tag_name }} | |
| call-redeployment-webhook: | |
| name: Call Redeployment Webhook | |
| needs: [build-and-push-to-dockerhub] | |
| uses: BehindTheMusicTree/github-workflows/.github/workflows/call-redeployment-webhook.yml@main | |
| with: | |
| env: "TEST" | |
| secrets: inherit |