reqs #1023
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: SDLC - Branch push | |
| on: | |
| push: | |
| branches: | |
| - "**" | |
| jobs: | |
| prepare-docker: | |
| name: "Prepare Docker image tag" | |
| runs-on: ubuntu-latest | |
| outputs: | |
| docker_image_tag: ${{ steps.sanitize-branch.outputs.docker_image_tag }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| - name: Get current branch name | |
| id: get-branch | |
| run: | | |
| if [[ "${GITHUB_REF}" == refs/pull/*/merge ]]; then | |
| BRANCH_NAME="${GITHUB_HEAD_REF}" | |
| else | |
| BRANCH_NAME="${GITHUB_REF_NAME}" | |
| fi | |
| echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT | |
| - name: Sanitize branch name for Docker | |
| id: sanitize-branch | |
| run: | | |
| SAFE_BRANCH=$(echo "${{ steps.get-branch.outputs.branch_name }}" | tr '[:upper:]' '[:lower:]' | sed 's#[^a-z0-9_.-]#-#g') | |
| echo "docker_image_tag=$SAFE_BRANCH" >> $GITHUB_OUTPUT | |
| build-push: | |
| name: "Build & push image" | |
| runs-on: ubuntu-latest | |
| needs: [prepare-docker] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| - name: Free Disk Space | |
| uses: jlumbroso/free-disk-space@main | |
| with: | |
| tool-cache: true | |
| android: true | |
| dotnet: true | |
| haskell: true | |
| large-packages: true | |
| docker-images: true | |
| swap-storage: true | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Install the latest version of uv | |
| uses: astral-sh/setup-uv@v7 | |
| with: | |
| enable-cache: true | |
| cache-dependency-glob: "pyproject.toml" | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set target input | |
| id: config | |
| run: | | |
| version=$(uvx --with hatch-vcs hatchling metadata version) | |
| COMMIT_SHA=$(git rev-parse "$GITHUB_SHA") | |
| git_reference="${{ github.event.inputs.git_reference }}" | |
| tag="${{ github.event.inputs.tag }}" | |
| if [ -z "$tag" ]; then | |
| tag="$git_reference" | |
| fi | |
| BUILD_DATE=$(date +"%Y-%m-%d %H:%M") | |
| echo "git_reference=$git_reference" >> $GITHUB_OUTPUT | |
| echo "version=$version" >> $GITHUB_OUTPUT | |
| echo "tag=$tag" >> $GITHUB_OUTPUT | |
| echo "build_date=$BUILD_DATE" >> $GITHUB_OUTPUT | |
| echo "commit_sha=$COMMIT_SHA" >> $GITHUB_OUTPUT | |
| - name: Build and push image | |
| run: | | |
| IMAGE_TAG="${{ needs.prepare-docker.outputs.docker_image_tag }}" | |
| docker buildx create --use | |
| docker buildx build \ | |
| --build-arg VERSION="${{ steps.config.outputs.version }}" \ | |
| --build-arg BUILD_DATE="${{ steps.config.outputs.build_date }}" \ | |
| --build-arg SOURCE_COMMIT=${{ steps.config.outputs.commit_sha }} \ | |
| --cache-from type=registry,ref=${{ vars.DOCKERHUB_ORGANIZATION }}/${{ vars.DOCKERHUB_REPOSITORY }}:cache-develop \ | |
| --cache-from type=registry,ref=${{ vars.DOCKERHUB_ORGANIZATION }}/${{ vars.DOCKERHUB_REPOSITORY }}:cache-$IMAGE_TAG \ | |
| --cache-to type=registry,ref=${{ vars.DOCKERHUB_ORGANIZATION }}/${{ vars.DOCKERHUB_REPOSITORY }}:cache-$IMAGE_TAG,mode=max \ | |
| -t ${{ vars.DOCKERHUB_ORGANIZATION }}/${{ vars.DOCKERHUB_REPOSITORY }}:$IMAGE_TAG \ | |
| -f ./docker/Dockerfile \ | |
| --push \ | |
| ./ | |
| deploy: | |
| name: "Trigger deployment" | |
| if: github.ref == 'refs/heads/develop' | |
| needs: [build-push] | |
| uses: ./.github/workflows/trigger-azure-pipeline.yml | |
| with: | |
| azure-organization: ${{ vars.AZURE_ORGANIZATION }} | |
| azure-project: ${{ vars.AZURE_PROJECT }} | |
| azure-pipeline-id: ${{ vars.AZURE_PIPELINE_ID_DEVELOP }} | |
| image-tag: "develop" | |
| secrets: | |
| azure-pat: ${{ secrets.AZURE_PAT }} |