Update badge styling and modal #11
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: release | |
| on: | |
| push: | |
| tags: | |
| # PanWatch tags are like 0.2.3 (no "v" prefix) | |
| - '*.*.*' | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Docker tag to publish (e.g. 0.2.3)' | |
| required: true | |
| type: string | |
| push_latest: | |
| description: 'Also push :latest' | |
| required: false | |
| type: boolean | |
| default: true | |
| platforms: | |
| description: 'Target platforms' | |
| required: false | |
| type: string | |
| default: 'linux/amd64,linux/arm64' | |
| env: | |
| IMAGE_NAME: sunxiao0721/panwatch | |
| jobs: | |
| docker: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Resolve version | |
| id: vars | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
| version="${{ inputs.version }}" | |
| push_latest="${{ inputs.push_latest }}" | |
| platforms="${{ inputs.platforms }}" | |
| else | |
| version="${{ github.ref_name }}" | |
| push_latest="true" | |
| platforms="linux/amd64,linux/arm64" | |
| fi | |
| version_no_v="$version" | |
| if [[ "$version" == v* ]]; then | |
| version_no_v="${version#v}" | |
| fi | |
| echo "version=$version" >> "$GITHUB_OUTPUT" | |
| echo "version_no_v=$version_no_v" >> "$GITHUB_OUTPUT" | |
| echo "push_latest=$push_latest" >> "$GITHUB_OUTPUT" | |
| echo "platforms=$platforms" >> "$GITHUB_OUTPUT" | |
| - 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 Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=raw,value=${{ steps.vars.outputs.version }} | |
| type=raw,value=${{ steps.vars.outputs.version_no_v }},enable=${{ steps.vars.outputs.version_no_v != steps.vars.outputs.version }} | |
| type=raw,value=latest,enable=${{ steps.vars.outputs.push_latest == 'true' }} | |
| labels: | | |
| org.opencontainers.image.title=PanWatch | |
| org.opencontainers.image.version=${{ steps.vars.outputs.version }} | |
| org.opencontainers.image.source=${{ github.repositoryUrl }} | |
| - name: Build and push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| platforms: ${{ steps.vars.outputs.platforms }} | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| build-args: | | |
| VERSION=${{ steps.vars.outputs.version }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Generate release notes (tag push only) | |
| if: ${{ github.event_name == 'push' }} | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| current="${{ steps.vars.outputs.version }}" | |
| repo="${{ github.repository }}" | |
| # Find previous tag by semver sort (best effort). | |
| prev="" | |
| while IFS= read -r t; do | |
| if [[ "$t" != "$current" ]]; then | |
| prev="$t" | |
| break | |
| fi | |
| done < <(git tag --list --sort=-v:refname) | |
| echo "Current tag: $current" | |
| if [[ -n "$prev" ]]; then | |
| echo "Previous tag: $prev" | |
| range="$prev..$current" | |
| else | |
| echo "Previous tag: (none)" | |
| range="$current" | |
| fi | |
| { | |
| echo "## Docker" | |
| echo "- $IMAGE_NAME:$current" | |
| echo "- $IMAGE_NAME:latest" | |
| echo "" | |
| echo "## Commits" | |
| if [[ -n "$prev" ]]; then | |
| echo "Compare: https://github.com/$repo/compare/$prev...$current" | |
| echo "" | |
| echo "Changes since $prev:" | |
| echo "" | |
| # Non-merge commits only (exclude MR/PR merges). | |
| git log --no-merges --pretty=format:'- %s (%h)' "$range" || true | |
| else | |
| echo "First release tag." | |
| fi | |
| echo "" | |
| } > release-notes.md | |
| - name: Create GitHub Release (tag push only) | |
| if: ${{ github.event_name == 'push' }} | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.vars.outputs.version }} | |
| body_path: release-notes.md | |
| - name: Notify Telegram | |
| if: ${{ always() }} | |
| continue-on-error: true | |
| env: | |
| TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} | |
| TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} | |
| JOB_STATUS: ${{ job.status }} | |
| VERSION: ${{ steps.vars.outputs.version }} | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| if [[ -z "${TELEGRAM_BOT_TOKEN:-}" || -z "${TELEGRAM_CHAT_ID:-}" ]]; then | |
| echo "TELEGRAM_BOT_TOKEN or TELEGRAM_CHAT_ID is not configured; skip notify." | |
| exit 0 | |
| fi | |
| if [[ "${JOB_STATUS}" == "success" ]]; then | |
| icon="✅" | |
| status_text="发布成功" | |
| else | |
| icon="❌" | |
| status_text="发布失败" | |
| fi | |
| run_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
| ref_name="${{ github.ref_name }}" | |
| actor="${{ github.actor }}" | |
| event_name="${{ github.event_name }}" | |
| if [[ -z "${VERSION}" ]]; then | |
| VERSION="${ref_name}" | |
| fi | |
| text="$(cat <<EOF | |
| ${icon} PanWatch Release ${status_text} | |
| Repository: ${{ github.repository }} | |
| Version: ${VERSION} | |
| Ref: ${ref_name} | |
| Trigger: ${event_name} by ${actor} | |
| Run: ${run_url} | |
| EOF | |
| )" | |
| curl -sS -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \ | |
| --data-urlencode "chat_id=${TELEGRAM_CHAT_ID}" \ | |
| --data-urlencode "text=${text}" \ | |
| --data-urlencode "disable_web_page_preview=true" \ | |
| --max-time 20 |