fix CI #22
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: Build and Push Docker image | |
| on: | |
| push: | |
| branches: [master] | |
| workflow_dispatch: | |
| jobs: | |
| check-version: | |
| name: Check Version | |
| runs-on: ubuntu-latest | |
| outputs: | |
| local-version: ${{ steps.version.outputs.version }} | |
| remote-version: ${{ steps.remote.outputs.remote_version }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Install Rust toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Extract crate version | |
| id: version | |
| run: | | |
| VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name=="matrix-gotify-bridge") | .version') | |
| if [ -z "$VERSION" ]; then | |
| echo "Failed to parse version from Cargo.toml" >&2 | |
| exit 1 | |
| fi | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| - name: Check Docker Hub tag exists | |
| id: remote | |
| env: | |
| VERSION: ${{ steps.version.outputs.version }} | |
| run: | | |
| TAG_URL="https://hub.docker.com/v2/repositories/controlnet/matrix-gotify-bridge/tags/${VERSION}" | |
| STATUS=$(curl -s -o /tmp/tag.json -w "%{http_code}" "$TAG_URL") | |
| if [ "$STATUS" = "200" ]; then | |
| echo "remote_version=$VERSION" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "remote_version=" >> "$GITHUB_OUTPUT" | |
| fi | |
| determine-runner: | |
| runs-on: ubuntu-latest | |
| needs: check-version | |
| outputs: | |
| runner: ${{ steps.set-runner.outputs.use-runner }} | |
| steps: | |
| - name: Choose runner | |
| id: set-runner | |
| uses: mikehardy/runner-fallback-action@v1 | |
| with: | |
| # 如果你的自托管 runner 标签是 self-hosted + linux + your-fast-pc | |
| primary-runner: "self-hosted,Linux,X64" | |
| fallback-runner: "ubuntu-latest" | |
| github-token: ${{ secrets.ADMIN_PAT }} | |
| primaries-required: 1 | |
| docker: | |
| runs-on: ${{ fromJson(needs.determine-runner.outputs.runner) }} | |
| needs: | |
| - check-version | |
| - determine-runner | |
| if: github.event_name == 'workflow_dispatch' || needs.check-version.outputs.remote-version != needs.check-version.outputs.local-version | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| platforms: linux/amd64,linux/arm64 | |
| tags: | | |
| controlnet/matrix-gotify-bridge:latest | |
| controlnet/matrix-gotify-bridge:${{ needs.check-version.outputs.local-version }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Create GitHub release tag | |
| uses: marvinpinto/action-automatic-releases@latest | |
| with: | |
| repo_token: ${{ secrets.ADMIN_PAT }} | |
| automatic_release_tag: v${{ needs.check-version.outputs.local-version }} | |
| title: "[${{ needs.check-version.outputs.local-version }}] Matrix-Gotify Bridge Release" | |
| prerelease: false | |
| draft: true |