2023-11-28 10:01:37 -05:00
|
|
|
name: Release
|
2020-11-06 07:51:23 -05:00
|
|
|
|
2020-11-29 09:17:40 -05:00
|
|
|
on:
|
2023-11-28 10:08:50 -05:00
|
|
|
push:
|
2023-11-28 10:01:37 -05:00
|
|
|
tags:
|
|
|
|
- "v*"
|
2024-10-24 09:33:36 -04:00
|
|
|
branches:
|
|
|
|
- dev
|
2020-11-06 07:51:23 -05:00
|
|
|
|
|
|
|
jobs:
|
2024-09-02 10:13:13 -04:00
|
|
|
build:
|
|
|
|
strategy:
|
|
|
|
fail-fast: true
|
|
|
|
matrix:
|
2024-11-28 06:43:50 -05:00
|
|
|
goos: [linux, windows]
|
2024-09-02 10:13:13 -04:00
|
|
|
goarch: [amd64]
|
2024-11-28 06:43:50 -05:00
|
|
|
include:
|
|
|
|
- goos: linux
|
|
|
|
goarch: s390x
|
|
|
|
- goos: linux
|
|
|
|
goarch: arm64
|
2024-11-28 11:31:20 -05:00
|
|
|
|
2024-09-02 10:13:13 -04:00
|
|
|
name: Build artifacts
|
2020-11-06 07:51:23 -05:00
|
|
|
runs-on: ubuntu-latest
|
2024-11-28 06:43:50 -05:00
|
|
|
container:
|
|
|
|
image: goreleaser/goreleaser-cross:v1.23
|
2020-11-06 07:51:23 -05:00
|
|
|
steps:
|
2024-11-28 06:43:50 -05:00
|
|
|
- run: git config --global --add safe.directory /__w/nezha/nezha
|
2024-11-29 08:31:39 -05:00
|
|
|
|
2023-10-21 06:27:25 -04:00
|
|
|
- uses: actions/checkout@v4
|
2020-11-11 09:21:16 -05:00
|
|
|
|
2024-11-29 08:31:39 -05:00
|
|
|
- uses: robinraju/release-downloader@v1
|
|
|
|
with:
|
|
|
|
repository: nezhahq/admin-frontend
|
2024-11-30 00:50:46 -05:00
|
|
|
tag: v1.0.6
|
2024-11-29 08:31:39 -05:00
|
|
|
fileName: dist.zip
|
|
|
|
latest: true
|
|
|
|
extract: true
|
|
|
|
|
|
|
|
- name: prepare admin-frontend dists
|
|
|
|
run: |
|
|
|
|
rm -rf cmd/dashboard/admin-dist
|
|
|
|
mv dist cmd/dashboard/admin-dist
|
|
|
|
|
|
|
|
- uses: robinraju/release-downloader@v1
|
|
|
|
with:
|
|
|
|
repository: nezhahq/user-frontend
|
2024-11-29 22:46:28 -05:00
|
|
|
tag: v1.0.4
|
2024-11-29 08:31:39 -05:00
|
|
|
fileName: dist.zip
|
|
|
|
latest: true
|
|
|
|
extract: true
|
|
|
|
|
|
|
|
- name: prepare admin-frontend dists
|
|
|
|
run: |
|
|
|
|
rm -rf cmd/dashboard/user-dist
|
|
|
|
mv dist cmd/dashboard/user-dist
|
|
|
|
|
2024-07-28 01:59:58 -04:00
|
|
|
- name: Fetch IPInfo GeoIP Database
|
2024-09-02 10:13:13 -04:00
|
|
|
env:
|
2024-07-28 01:59:58 -04:00
|
|
|
IPINFO_TOKEN: ${{ secrets.IPINFO_TOKEN }}
|
|
|
|
run: |
|
|
|
|
rm pkg/geoip/geoip.db
|
2024-09-02 10:13:13 -04:00
|
|
|
wget -qO pkg/geoip/geoip.db https://ipinfo.io/data/free/country.mmdb?token=${IPINFO_TOKEN}
|
2024-07-28 01:59:58 -04:00
|
|
|
|
2024-09-02 10:13:13 -04:00
|
|
|
- name: Set up Go
|
|
|
|
uses: actions/setup-go@v5
|
|
|
|
with:
|
2024-10-17 09:03:03 -04:00
|
|
|
go-version: "1.23.x"
|
2024-10-24 10:15:37 -04:00
|
|
|
|
2024-10-24 10:35:26 -04:00
|
|
|
- name: generate swagger docs
|
2024-10-24 10:15:37 -04:00
|
|
|
run: |
|
|
|
|
go install github.com/swaggo/swag/cmd/swag@latest
|
2024-11-29 08:55:29 -05:00
|
|
|
swag init --pd -d . -g ./cmd/dashboard/main.go -o ./cmd/dashboard/docs --parseGoList=false
|
2024-11-28 11:31:20 -05:00
|
|
|
|
2024-10-24 10:15:37 -04:00
|
|
|
- name: Build with tag
|
|
|
|
if: contains(github.ref, 'refs/tags/')
|
2024-09-02 10:13:13 -04:00
|
|
|
uses: goreleaser/goreleaser-action@v6
|
2024-10-24 10:25:12 -04:00
|
|
|
env:
|
|
|
|
GOOS: ${{ matrix.goos }}
|
|
|
|
GOARCH: ${{ matrix.goarch }}
|
2024-11-28 06:43:50 -05:00
|
|
|
GOARM: ${{ matrix.goarm }}
|
2024-09-02 10:13:13 -04:00
|
|
|
with:
|
|
|
|
distribution: goreleaser
|
2024-11-28 11:31:20 -05:00
|
|
|
version: "~> v2"
|
2024-09-02 10:13:13 -04:00
|
|
|
args: build --single-target --clean --skip=validate
|
|
|
|
|
2024-10-24 10:15:37 -04:00
|
|
|
- name: Build snapshot
|
|
|
|
if: contains(github.ref, 'refs/tags/') == false
|
|
|
|
uses: goreleaser/goreleaser-action@v6
|
2024-10-24 10:25:12 -04:00
|
|
|
env:
|
|
|
|
GOOS: ${{ matrix.goos }}
|
|
|
|
GOARCH: ${{ matrix.goarch }}
|
2024-11-28 06:43:50 -05:00
|
|
|
GOARM: ${{ matrix.goarm }}
|
2024-10-24 10:15:37 -04:00
|
|
|
with:
|
|
|
|
distribution: goreleaser
|
2024-11-28 11:31:20 -05:00
|
|
|
version: "~> v2"
|
2024-10-30 11:22:37 -04:00
|
|
|
args: build --single-target --clean --skip=validate --snapshot
|
2024-10-24 10:15:37 -04:00
|
|
|
|
2024-11-28 06:43:50 -05:00
|
|
|
- name: Upload artifacts
|
|
|
|
uses: actions/upload-artifact@v4
|
|
|
|
with:
|
|
|
|
name: dashboard-${{ matrix.goos }}-${{ matrix.goarch }}
|
|
|
|
path: |
|
|
|
|
./dist/*/*
|
2024-09-02 10:13:13 -04:00
|
|
|
|
|
|
|
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
|
2022-07-06 22:27:14 -04:00
|
|
|
run: |
|
2024-11-28 11:31:20 -05:00
|
|
|
find assets/*/*/* -type f | while read -r file; do
|
|
|
|
dir=$(dirname "$file")
|
|
|
|
filename=$(basename "$file")
|
|
|
|
fileWithoutExt="${filename%.*}"
|
|
|
|
zip -jr "$dir/$fileWithoutExt.zip" "$file"
|
2024-09-02 10:13:13 -04:00
|
|
|
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
|
2022-07-06 22:27:14 -04:00
|
|
|
|
2024-09-02 10:13:13 -04:00
|
|
|
release-docker:
|
|
|
|
runs-on: ubuntu-latest
|
2024-10-24 09:33:36 -04:00
|
|
|
if: github.event_name == 'push'
|
2024-09-02 10:13:13 -04:00
|
|
|
needs: build
|
|
|
|
name: Release Docker images
|
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v4
|
2024-10-24 10:15:37 -04:00
|
|
|
|
2024-11-28 06:43:50 -05:00
|
|
|
- name: Download artifacts
|
|
|
|
uses: actions/download-artifact@v4
|
|
|
|
with:
|
|
|
|
path: ./assets
|
2024-09-02 10:13:13 -04:00
|
|
|
|
|
|
|
- name: Fix permissions
|
2022-07-06 22:27:14 -04:00
|
|
|
run: |
|
2024-09-02 10:13:13 -04:00
|
|
|
chmod -R +x ./assets/*
|
|
|
|
mkdir dist
|
|
|
|
mv ./assets/*/*/* ./dist
|
2022-07-06 22:27:14 -04:00
|
|
|
|
2024-10-24 09:33:36 -04:00
|
|
|
- name: Extract branch name in tag
|
2024-09-02 10:13:13 -04:00
|
|
|
run: |
|
2024-10-24 10:44:13 -04: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 10:15:37 -04:00
|
|
|
fi
|
2024-09-02 10:13:13 -04:00
|
|
|
echo "tag=$TAG_NAME" >> $GITHUB_OUTPUT
|
|
|
|
id: extract_branch
|
2024-10-24 09:33:36 -04:00
|
|
|
|
2024-09-02 10:13:13 -04:00
|
|
|
- name: Log into GHCR
|
2021-08-18 06:53:35 -04:00
|
|
|
uses: docker/login-action@master
|
|
|
|
with:
|
|
|
|
registry: ghcr.io
|
|
|
|
username: ${{ github.repository_owner }}
|
2024-09-02 10:13:13 -04:00
|
|
|
password: ${{ github.token }}
|
2021-08-18 06:53:35 -04:00
|
|
|
|
|
|
|
- name: Log in to the AliyunCS
|
2024-10-30 10:50:51 -04:00
|
|
|
if: contains(github.ref, 'refs/tags/')
|
2021-08-18 06:53:35 -04:00
|
|
|
uses: docker/login-action@master
|
|
|
|
with:
|
|
|
|
registry: registry.cn-shanghai.aliyuncs.com
|
|
|
|
username: ${{ secrets.ALI_USER }}
|
|
|
|
password: ${{ secrets.ALI_PAT }}
|
2021-09-04 00:18:12 -04:00
|
|
|
|
2021-07-07 13:54:44 -04:00
|
|
|
- name: Set up QEMU
|
2023-10-21 06:27:25 -04:00
|
|
|
uses: docker/setup-qemu-action@v3
|
2021-09-04 00:18:12 -04:00
|
|
|
|
2021-07-07 13:54:44 -04:00
|
|
|
- name: Set up Docker Buildx
|
2023-10-21 06:27:25 -04:00
|
|
|
uses: docker/setup-buildx-action@v3
|
2021-09-04 00:18:12 -04:00
|
|
|
|
2021-07-07 14:35:23 -04:00
|
|
|
- name: Set up image name
|
2021-04-11 08:13:34 -04:00
|
|
|
run: |
|
2024-11-28 06:43:50 -05:00
|
|
|
GHCR_IMAGE_NAME=$(echo "ghcr.io/${{ github.repository_owner }}/nezha" | tr '[:upper:]' '[:lower:]')
|
|
|
|
if [ ${{ github.repository_owner }} = "nezhahq" ]
|
2024-11-28 11:58:20 -05:00
|
|
|
then ALI_IMAGE_NAME=$(echo "registry.cn-shanghai.aliyuncs.com/naibahq/nezha-dashboard")
|
2021-07-07 14:35:23 -04:00
|
|
|
else ALI_IMAGE_NAME=$(echo "registry.cn-shanghai.aliyuncs.com/${{ github.repository_owner }}/nezha-dashboard" | tr '[:upper:]' '[:lower:]')
|
2021-04-11 09:59:33 -04:00
|
|
|
fi
|
2024-09-02 10:13:13 -04:00
|
|
|
echo "GHCR_IMAGE_NAME=$GHCR_IMAGE_NAME" >> $GITHUB_OUTPUT
|
|
|
|
echo "ALI_IMAGE_NAME=$ALI_IMAGE_NAME" >> $GITHUB_OUTPUT
|
2021-07-07 14:38:35 -04:00
|
|
|
id: image-name
|
2021-09-04 00:18:12 -04:00
|
|
|
|
2024-10-24 10:15:37 -04:00
|
|
|
- name: Build dasbboard image And Push with tag
|
|
|
|
if: contains(github.ref, 'refs/tags/')
|
2023-10-21 06:27:25 -04:00
|
|
|
uses: docker/build-push-action@v5
|
2021-07-07 14:35:23 -04:00
|
|
|
with:
|
|
|
|
context: .
|
|
|
|
file: ./Dockerfile
|
2024-09-02 10:13:13 -04:00
|
|
|
platforms: linux/amd64,linux/arm64,linux/s390x
|
2021-07-07 14:35:23 -04:00
|
|
|
push: true
|
|
|
|
tags: |
|
2024-09-02 10:13:13 -04:00
|
|
|
${{ steps.image-name.outputs.GHCR_IMAGE_NAME }}:latest
|
|
|
|
${{ steps.image-name.outputs.GHCR_IMAGE_NAME }}:${{ steps.extract_branch.outputs.tag }}
|
2023-11-28 10:01:37 -05:00
|
|
|
${{ steps.image-name.outputs.ALI_IMAGE_NAME }}:latest
|
2022-07-06 22:27:14 -04:00
|
|
|
${{ steps.image-name.outputs.ALI_IMAGE_NAME }}:${{ steps.extract_branch.outputs.tag }}
|
2024-10-24 10:15:37 -04: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
|
2024-11-28 06:43:50 -05:00
|
|
|
platforms: linux/amd64,linux/arm64,linux/s390x
|
2024-10-24 10:15:37 -04:00
|
|
|
push: true
|
|
|
|
tags: |
|
|
|
|
${{ steps.image-name.outputs.GHCR_IMAGE_NAME }}:${{ steps.extract_branch.outputs.tag }}
|