feat: add reusable script for checking required config #12
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: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Check required configuration | |
| env: | |
| DOCKERHUB_USERNAME: ${{ vars.DOCKERHUB_USERNAME }} | |
| DB_IMAGE_REPO: ${{ vars.DB_IMAGE_REPO }} | |
| DOCKERHUB_ACCESS_TOKEN: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }} | |
| DOMAIN_NAME: ${{ vars.DOMAIN_NAME }} | |
| REDEPLOYMENT_WEBHOOK_PORT: ${{ secrets.REDEPLOYMENT_WEBHOOK_PORT }} | |
| REDEPLOYMENT_HOOK_ID: ${{ secrets.REDEPLOYMENT_HOOK_ID }} | |
| TEST_SERVER_REDEPLOYMENT_WEBHOOK_SECRET: ${{ secrets.TEST_SERVER_REDEPLOYMENT_WEBHOOK_SECRET }} | |
| run: | | |
| bash .github/scripts/check-required-config.sh \ | |
| v:DOCKERHUB_USERNAME \ | |
| v:DB_IMAGE_REPO \ | |
| s:DOCKERHUB_ACCESS_TOKEN \ | |
| v:DOMAIN_NAME \ | |
| s:REDEPLOYMENT_WEBHOOK_PORT \ | |
| s:REDEPLOYMENT_HOOK_ID \ | |
| s:TEST_SERVER_REDEPLOYMENT_WEBHOOK_SECRET | |
| 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 |