Refactor conditional syntax in workflow files #154
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: Docker | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| jobs: | |
| build-docker: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: ./.github/actions/docker/build-start-services | |
| if: github.event.repository.name == 'python-template-server' | |
| - uses: javidahmed64592/python-template-server/.github/actions/docker/build-start-services@main | |
| if: github.event.repository.name != 'python-template-server' | |
| - uses: ./.github/actions/docker/show-logs | |
| if: github.event.repository.name == 'python-template-server' | |
| - uses: javidahmed64592/python-template-server/.github/actions/docker/show-logs@main | |
| if: github.event.repository.name != 'python-template-server' | |
| - uses: ./.github/actions/docker/check-containers | |
| if: github.event.repository.name == 'python-template-server' | |
| with: | |
| port: 443 | |
| - uses: javidahmed64592/python-template-server/.github/actions/docker/check-containers@main | |
| if: github.event.repository.name != 'python-template-server' | |
| with: | |
| port: 443 | |
| - uses: ./.github/actions/docker/stop-services | |
| if: github.event.repository.name == 'python-template-server' | |
| - uses: javidahmed64592/python-template-server/.github/actions/docker/stop-services@main | |
| if: github.event.repository.name != 'python-template-server' | |
| prepare-release: | |
| runs-on: ubuntu-latest | |
| needs: [build-docker] | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: javidahmed64592/template-python/.github/actions/setup/install-python-dev@main | |
| - uses: ./.github/actions/docker/prepare-release | |
| if: github.event.repository.name == 'python-template-server' | |
| - uses: javidahmed64592/python-template-server/.github/actions/docker/prepare-release@main | |
| if: github.event.repository.name != 'python-template-server' | |
| publish-release: | |
| runs-on: ubuntu-latest | |
| needs: [prepare-release] | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| permissions: | |
| contents: write | |
| packages: write | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: javidahmed64592/template-python/.github/actions/setup/install-python-core@main | |
| - uses: ./.github/actions/docker/check-repo-name | |
| if: github.event.repository.name == 'python-template-server' | |
| id: check_repo_name_local | |
| - uses: javidahmed64592/python-template-server/.github/actions/docker/check-repo-name@main | |
| if: github.event.repository.name != 'python-template-server' | |
| id: check_repo_name_remote | |
| - id: check_repo_name | |
| run: echo "should_release=${{ steps.check_repo_name_local.outputs.should_release || steps.check_repo_name_remote.outputs.should_release }}" >> $GITHUB_OUTPUT | |
| shell: bash | |
| - uses: ./.github/actions/docker/get-version | |
| if: steps.check_repo_name.outputs.should_release == 'true' && github.event.repository.name == 'python-template-server' | |
| id: get_version_local | |
| - uses: javidahmed64592/python-template-server/.github/actions/docker/get-version@main | |
| if: steps.check_repo_name.outputs.should_release == 'true' && github.event.repository.name != 'python-template-server' | |
| id: get_version_remote | |
| - id: get_version | |
| if: steps.check_repo_name.outputs.should_release == 'true' | |
| run: | | |
| echo "version=${{ steps.get_version_local.outputs.version || steps.get_version_remote.outputs.version }}" >> $GITHUB_OUTPUT | |
| echo "tag=${{ steps.get_version_local.outputs.tag || steps.get_version_remote.outputs.tag }}" >> $GITHUB_OUTPUT | |
| shell: bash | |
| - uses: ./.github/actions/docker/check-tag | |
| if: steps.check_repo_name.outputs.should_release == 'true' && github.event.repository.name == 'python-template-server' | |
| id: check_tag_local | |
| with: | |
| version: ${{ steps.get_version.outputs.version }} | |
| - uses: javidahmed64592/python-template-server/.github/actions/docker/check-tag@main | |
| if: steps.check_repo_name.outputs.should_release == 'true' && github.event.repository.name != 'python-template-server' | |
| id: check_tag_remote | |
| with: | |
| version: ${{ steps.get_version.outputs.version }} | |
| - id: check_tag | |
| if: steps.check_repo_name.outputs.should_release == 'true' | |
| run: echo "tag_exists=${{ steps.check_tag_local.outputs.tag_exists || steps.check_tag_remote.outputs.tag_exists }}" >> $GITHUB_OUTPUT | |
| shell: bash | |
| - name: Download release tarball | |
| if: steps.check_repo_name.outputs.should_release == 'true' && steps.check_tag.outputs.tag_exists == 'false' | |
| uses: actions/download-artifact@v8 | |
| with: | |
| name: ${{ env.PACKAGE_NAME }}_release | |
| - name: Set up Docker Buildx | |
| if: steps.check_repo_name.outputs.should_release == 'true' && steps.check_tag.outputs.tag_exists == 'false' | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Log in to GitHub Container Registry | |
| if: steps.check_repo_name.outputs.should_release == 'true' && steps.check_tag.outputs.tag_exists == 'false' | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata for Docker | |
| if: steps.check_repo_name.outputs.should_release == 'true' && steps.check_tag.outputs.tag_exists == 'false' | |
| id: meta | |
| uses: docker/metadata-action@v6 | |
| with: | |
| images: ghcr.io/${{ github.repository }} | |
| tags: | | |
| type=semver,pattern={{version}},value=v${{ steps.get_version.outputs.version }} | |
| type=semver,pattern={{major}}.{{minor}},value=v${{ steps.get_version.outputs.version }} | |
| type=semver,pattern={{major}},value=v${{ steps.get_version.outputs.version }} | |
| type=raw,value=latest | |
| - name: Build and push Docker image | |
| if: steps.check_repo_name.outputs.should_release == 'true' && steps.check_tag.outputs.tag_exists == 'false' | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: . | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| platforms: linux/amd64,linux/arm64 | |
| - uses: ./.github/actions/docker/generate-release-notes | |
| if: steps.check_repo_name.outputs.should_release == 'true' && steps.check_tag.outputs.tag_exists == 'false' && github.event.repository.name == 'python-template-server' | |
| id: release_notes_local | |
| with: | |
| version: ${{ steps.get_version.outputs.version }} | |
| - uses: javidahmed64592/python-template-server/.github/actions/docker/generate-release-notes@main | |
| if: steps.check_repo_name.outputs.should_release == 'true' && steps.check_tag.outputs.tag_exists == 'false' && github.event.repository.name != 'python-template-server' | |
| id: release_notes_remote | |
| with: | |
| version: ${{ steps.get_version.outputs.version }} | |
| - id: release_notes | |
| if: steps.check_repo_name.outputs.should_release == 'true' && steps.check_tag.outputs.tag_exists == 'false' | |
| run: echo "release_notes_file=${{ steps.release_notes_local.outputs.release_notes_file || steps.release_notes_remote.outputs.release_notes_file }}" >> $GITHUB_OUTPUT | |
| shell: bash | |
| - name: Create GitHub Release | |
| if: steps.check_repo_name.outputs.should_release == 'true' && steps.check_tag.outputs.tag_exists == 'false' | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.get_version.outputs.tag }} | |
| name: "${{ github.event.repository.name }} ${{ steps.get_version.outputs.version }}" | |
| body_path: ${{ steps.release_notes.outputs.release_notes_file }} | |
| draft: false | |
| prerelease: false | |
| generate_release_notes: false | |
| files: ${{ env.PACKAGE_NAME }}_${{ steps.get_version.outputs.version }}.tar.gz |