nezha/.github/workflows/release.yml

220 lines
7.3 KiB
YAML
Raw Normal View History

2023-11-28 23:01:37 +08:00
name: Release
2020-11-06 20:51:23 +08:00
2020-11-29 22:17:40 +08:00
on:
2023-11-28 23:08:50 +08:00
push:
2023-11-28 23:01:37 +08:00
tags:
- "v*"
2024-10-24 21:33:36 +08:00
branches:
- dev
2020-11-06 20:51:23 +08:00
jobs:
build:
strategy:
fail-fast: true
matrix:
goos: [linux, windows]
goarch: [amd64]
include:
- goos: linux
goarch: s390x
- goos: linux
goarch: arm64
2024-11-29 00:31:20 +08:00
name: Build artifacts
2020-11-06 20:51:23 +08:00
runs-on: ubuntu-latest
container:
image: goreleaser/goreleaser-cross:v1.23
2020-11-06 20:51:23 +08:00
steps:
- run: |
apt update && apt install unzip curl -y
wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq
chmod +x /usr/bin/yq
- run: git config --global --add safe.directory /__w/nezha/nezha
2024-11-29 21:31:39 +08:00
2023-10-21 18:27:25 +08:00
- uses: actions/checkout@v4
2020-11-11 22:21:16 +08:00
- name: Prepare frontends' dists
2024-12-06 23:45:12 +08:00
run: |
chmod +x ./script/fetch-frontends.sh && ./script/fetch-frontends.sh
2024-12-06 23:45:12 +08:00
- name: Fetch IPInfo GeoIP Database
env:
IPINFO_TOKEN: ${{ secrets.IPINFO_TOKEN }}
run: |
rm pkg/geoip/geoip.db
wget -qO pkg/geoip/geoip.db https://ipinfo.io/data/free/country.mmdb?token=${IPINFO_TOKEN}
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.23.x"
2024-10-24 22:15:37 +08:00
2024-10-24 22:35:26 +08:00
- name: generate swagger docs
2024-10-24 22:15:37 +08:00
run: |
go install github.com/swaggo/swag/cmd/swag@latest
2024-11-29 21:55:29 +08:00
swag init --pd -d . -g ./cmd/dashboard/main.go -o ./cmd/dashboard/docs --parseGoList=false
2024-11-29 00:31:20 +08:00
2024-10-24 22:15:37 +08:00
- name: Build with tag
if: contains(github.ref, 'refs/tags/')
uses: goreleaser/goreleaser-action@v6
2024-10-24 22:25:12 +08:00
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
GOARM: ${{ matrix.goarm }}
with:
distribution: goreleaser
2024-11-29 00:31:20 +08:00
version: "~> v2"
args: build --single-target --clean --skip=validate
2024-10-24 22:15:37 +08:00
- name: Build snapshot
if: contains(github.ref, 'refs/tags/') == false
uses: goreleaser/goreleaser-action@v6
2024-10-24 22:25:12 +08:00
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
GOARM: ${{ matrix.goarm }}
2024-10-24 22:15:37 +08:00
with:
distribution: goreleaser
2024-11-29 00:31:20 +08:00
version: "~> v2"
2024-10-30 23:22:37 +08:00
args: build --single-target --clean --skip=validate --snapshot
2024-10-24 22:15:37 +08:00
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: dashboard-${{ matrix.goos }}-${{ matrix.goarch }}
path: |
./dist/*/*
release:
runs-on: ubuntu-latest
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
needs: build
name: Release
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: ./assets
- name: Archive and compress binaries
run: |
2024-11-29 00:31:20 +08:00
find assets/*/*/* -type f | while read -r file; do
dir=$(dirname "$file")
filename=$(basename "$file")
fileWithoutExt="${filename%.*}"
zip -jr "$dir/$fileWithoutExt.zip" "$file"
done
- name: Release
uses: ncipollo/release-action@v1
with:
artifacts: "assets/*/*/*.zip"
generateReleaseNotes: true
- name: Purge jsdelivr cache
run: |
curl -s https://purge.jsdelivr.net/gh/${{ github.repository_owner }}/nezha@master/script/install.sh
curl -s https://purge.jsdelivr.net/gh/${{ github.repository_owner }}/nezha@master/script/nezha-agent.service
curl -s https://purge.jsdelivr.net/gh/${{ github.repository_owner }}/nezha@master/script/docker-compose.yaml
curl -s https://purge.jsdelivr.net/gh/${{ github.repository_owner }}/nezha@master/script/config.yaml
LOWER_USERNAME=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
curl -s https://purge.jsdelivr.net/gh/$LOWER_USERNAME/nezha@master/script/install.sh
curl -s https://purge.jsdelivr.net/gh/$LOWER_USERNAME/nezha@master/script/nezha-agent.service
curl -s https://purge.jsdelivr.net/gh/$LOWER_USERNAME/nezha@master/script/docker-compose.yaml
curl -s https://purge.jsdelivr.net/gh/$LOWER_USERNAME/nezha@master/script/config.yaml
- name: Trigger sync
env:
GH_REPO: ${{ github.repository }}
GH_TOKEN: ${{ github.token }}
GH_DEBUG: api
run: |
gh workflow run sync-release.yml
release-docker:
runs-on: ubuntu-latest
2024-10-24 21:33:36 +08:00
if: github.event_name == 'push'
needs: build
name: Release Docker images
steps:
- uses: actions/checkout@v4
2024-10-24 22:15:37 +08:00
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: ./assets
- name: Fix permissions
run: |
chmod -R +x ./assets/*
mkdir dist
mv ./assets/*/*/* ./dist
2024-10-24 21:33:36 +08:00
- name: Extract branch name in tag
run: |
2024-10-24 22:44:13 +08:00
if [[ $GITHUB_REF == refs/heads/* ]]; then
export TAG_NAME=$(echo ${GITHUB_REF#refs/heads/})
else
export TAG_NAME=$(echo ${GITHUB_REF#refs/tags/})
2024-10-24 22:15:37 +08:00
fi
echo "tag=$TAG_NAME" >> $GITHUB_OUTPUT
id: extract_branch
2024-10-24 21:33:36 +08:00
- name: Log into GHCR
2021-08-18 18:53:35 +08:00
uses: docker/login-action@master
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ github.token }}
2021-08-18 18:53:35 +08:00
- name: Log in to the AliyunCS
2024-10-30 22:50:51 +08:00
if: contains(github.ref, 'refs/tags/')
2021-08-18 18:53:35 +08:00
uses: docker/login-action@master
with:
registry: registry.cn-shanghai.aliyuncs.com
username: ${{ secrets.ALI_USER }}
password: ${{ secrets.ALI_PAT }}
2021-09-04 12:18:12 +08:00
2021-07-08 01:54:44 +08:00
- name: Set up QEMU
2023-10-21 18:27:25 +08:00
uses: docker/setup-qemu-action@v3
2021-09-04 12:18:12 +08:00
2021-07-08 01:54:44 +08:00
- name: Set up Docker Buildx
2023-10-21 18:27:25 +08:00
uses: docker/setup-buildx-action@v3
2021-09-04 12:18:12 +08:00
2021-07-08 02:35:23 +08:00
- name: Set up image name
2021-04-11 20:13:34 +08:00
run: |
GHCR_IMAGE_NAME=$(echo "ghcr.io/${{ github.repository_owner }}/nezha" | tr '[:upper:]' '[:lower:]')
if [ ${{ github.repository_owner }} = "nezhahq" ]
2024-11-29 00:58:20 +08:00
then ALI_IMAGE_NAME=$(echo "registry.cn-shanghai.aliyuncs.com/naibahq/nezha-dashboard")
2021-07-08 02:35:23 +08:00
else ALI_IMAGE_NAME=$(echo "registry.cn-shanghai.aliyuncs.com/${{ github.repository_owner }}/nezha-dashboard" | tr '[:upper:]' '[:lower:]')
2021-04-11 21:59:33 +08:00
fi
echo "GHCR_IMAGE_NAME=$GHCR_IMAGE_NAME" >> $GITHUB_OUTPUT
echo "ALI_IMAGE_NAME=$ALI_IMAGE_NAME" >> $GITHUB_OUTPUT
2021-07-08 02:38:35 +08:00
id: image-name
2021-09-04 12:18:12 +08:00
2024-10-24 22:15:37 +08:00
- name: Build dasbboard image And Push with tag
if: contains(github.ref, 'refs/tags/')
2023-10-21 18:27:25 +08:00
uses: docker/build-push-action@v5
2021-07-08 02:35:23 +08:00
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64,linux/s390x
2021-07-08 02:35:23 +08:00
push: true
tags: |
${{ steps.image-name.outputs.GHCR_IMAGE_NAME }}:latest
${{ steps.image-name.outputs.GHCR_IMAGE_NAME }}:${{ steps.extract_branch.outputs.tag }}
2023-11-28 23:01:37 +08:00
${{ steps.image-name.outputs.ALI_IMAGE_NAME }}:latest
${{ steps.image-name.outputs.ALI_IMAGE_NAME }}:${{ steps.extract_branch.outputs.tag }}
2024-10-24 22:15:37 +08:00
- name: Build dasbboard image And Push snapshot
if: contains(github.ref, 'refs/tags/') == false
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64,linux/s390x
2024-10-24 22:15:37 +08:00
push: true
tags: |
${{ steps.image-name.outputs.GHCR_IMAGE_NAME }}:${{ steps.extract_branch.outputs.tag }}