Add tag-only handoff mode with deferred ARR follow-up #313
Workflow file for this run
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: Test, Build, Deploy | |
| on: | |
| push: | |
| branches: | |
| - '**' | |
| paths: | |
| - 'src/**' | |
| - 'main.py' | |
| - 'docker/**' | |
| - '.github/workflows/build.yml' | |
| pull_request: | |
| branches: | |
| - '**' | |
| paths: | |
| - 'src/**' | |
| - 'main.py' | |
| - 'docker/**' | |
| - '.github/workflows/build.yml' | |
| workflow_dispatch: | |
| create: | |
| branches: | |
| - '**' | |
| permissions: | |
| contents: write | |
| packages: write | |
| jobs: | |
| validate-branch-name: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| valid_branch_name: ${{ steps.validate.outputs.valid_branch_name }} | |
| steps: | |
| - name: Validate Branch Name | |
| id: validate | |
| run: | | |
| BRANCH_NAME="${{ github.ref_name }}" | |
| if [[ "$BRANCH_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| echo "::error::Branch name '$BRANCH_NAME' is not allowed. Branch names using versioning names like 'v1.2.3' are prohibited." | |
| echo "valid_branch_name=false" >> $GITHUB_OUTPUT | |
| exit 1 | |
| else | |
| echo "Branch name '$BRANCH_NAME' is valid." | |
| echo "valid_branch_name=true" >> $GITHUB_OUTPUT | |
| fi | |
| unit-tests: | |
| needs: validate-branch-name | |
| if: needs.validate-branch-name.outputs.valid_branch_name == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.10.13' | |
| - name: Install testing dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r docker/requirements.txt | |
| - name: Run unit tests | |
| run: | | |
| python3 -m pytest -o log_cli=false | |
| build: | |
| needs: unit-tests | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: '0' | |
| - name: Bump version and push tag | |
| if: ${{ github.ref_name == 'latest' }} | |
| id: setversion | |
| uses: anothrNick/github-tag-action@1.36.0 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| WITH_V: true | |
| RELEASE_BRANCHES: latest | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Store short Commit ID in env variable | |
| id: vars | |
| run: | | |
| calculatedSha=$(git rev-parse --short ${{ github.sha }}) | |
| echo "SHORT_COMMIT_ID=$calculatedSha" >> $GITHUB_ENV | |
| - name: Determine Docker image tag | |
| id: determine_tag | |
| run: | | |
| BRANCH_NAME="${{ github.ref_name }}" | |
| if [[ "$BRANCH_NAME" == "dev" ]]; then | |
| IMAGE_TAG="dev" | |
| elif [[ "$BRANCH_NAME" == "latest" ]]; then | |
| IMAGE_TAG=${{ steps.setversion.outputs.new_tag }} | |
| else | |
| IMAGE_TAG=$BRANCH_NAME | |
| fi | |
| # Normalize tags to Docker-compatible values so feature/* branches can be published. | |
| IMAGE_TAG=$(echo "$IMAGE_TAG" | tr '[:upper:]' '[:lower:]') | |
| IMAGE_TAG=$(echo "$IMAGE_TAG" | sed -E 's/[^a-z0-9._-]+/-/g; s/^-+//; s/-+$//; s/^[.]+//; s/[.]+$//; s/-{2,}/-/g') | |
| IMAGE_TAG="${IMAGE_TAG:0:120}" | |
| if [[ -z "$IMAGE_TAG" ]]; then | |
| IMAGE_TAG="branch-${SHORT_COMMIT_ID}" | |
| fi | |
| echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV | |
| # Convert repository owner to lowercase | |
| REPO_OWNER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]') | |
| echo "REPO_OWNER=$REPO_OWNER" >> $GITHUB_ENV | |
| - name: Build, Tag, and Push Docker Image | |
| env: | |
| GHCR_IMAGE_NAME: ghcr.io/${{ env.REPO_OWNER }}/decluttarr | |
| DOCKERHUB_IMAGE_NAME: docker.io/${{ secrets.DOCKERHUB_USERNAME }}/decluttarr | |
| IMAGE_TAG: ${{ env.IMAGE_TAG }} | |
| run: | | |
| BRANCH_NAME="${{ github.ref_name }}" | |
| TAG_ARGS="-t ${GHCR_IMAGE_NAME}:${IMAGE_TAG} -t ${DOCKERHUB_IMAGE_NAME}:${IMAGE_TAG}" | |
| if [[ "$BRANCH_NAME" == "latest" ]]; then | |
| TAG_ARGS="$TAG_ARGS -t ${GHCR_IMAGE_NAME}:latest -t ${DOCKERHUB_IMAGE_NAME}:latest" | |
| fi | |
| docker buildx build \ | |
| --platform linux/amd64,linux/arm64 -f docker/Dockerfile . \ | |
| --progress plain \ | |
| $TAG_ARGS \ | |
| --label com.decluttarr.version=$IMAGE_TAG \ | |
| --label com.decluttarr.commit=$SHORT_COMMIT_ID \ | |
| --build-arg IMAGE_TAG=$IMAGE_TAG \ | |
| --build-arg SHORT_COMMIT_ID=$SHORT_COMMIT_ID \ | |
| --push | |
| docker-image-clean-up: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Clean up Docker images | |
| uses: dataaxiom/ghcr-cleanup-action@v1.0.8 | |
| with: | |
| exclude-tags: dev | |
| delete-untagged: true | |
| delete-ghost-images: true | |
| delete-partial-images: true | |
| token: ${{ secrets.GITHUB_TOKEN }} |