nezha/.github/workflows/release.yml

177 lines
5.8 KiB
YAML
Raw Normal View History

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*"
2020-11-06 07:51:23 -05:00
jobs:
build:
strategy:
fail-fast: true
matrix:
goos: [linux, windows]
goarch: [amd64]
include:
- goos: linux
goarch: s390x
- goos: linux
goarch: arm64
name: Build artifacts
2020-11-06 07:51:23 -05:00
runs-on: ubuntu-latest
container:
image: goreleaser/goreleaser-cross:v1.21
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
GOARM: ${{ matrix.goarm }}
outputs:
tag_name: ${{ steps.extract_branch.outputs.tag }}
2020-11-06 07:51:23 -05:00
steps:
- run: git config --global --add safe.directory /__w/nezha/nezha
2023-10-21 06:27:25 -04:00
- uses: actions/checkout@v4
2020-11-11 09:21:16 -05:00
- name: Fetch IPInfo GeoIP Database
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
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.21.x"
- name: Build
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: '~> v2'
args: build --single-target --clean --skip=validate
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: dashboard-${{ env.GOOS }}-${{ env.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: |
for file in assets/*/*/*; do
if [ -f "$file" ]; then
chmod +x "$file"
export fileWithoutExt=${file%.*}
zip -jr "$fileWithoutExt.zip" "$file"
fi
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
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
needs: build
name: Release Docker images
steps:
- uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
2022-07-06 23:21:54 -04:00
with:
path: ./assets
- name: Fix permissions
run: |
chmod -R +x ./assets/*
mkdir dist
mv ./assets/*/*/* ./dist
- name: Extract branch name
run: |
export TAG_NAME=$(echo ${GITHUB_REF#refs/tags/})
echo "tag=$TAG_NAME" >> $GITHUB_OUTPUT
id: extract_branch
- 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 }}
password: ${{ github.token }}
2021-08-18 06:53:35 -04:00
- name: Log in to the AliyunCS
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: |
GHCR_IMAGE_NAME=$(echo "ghcr.io/${{ github.repository_owner }}/nezha-dashboard" | tr '[:upper:]' '[:lower:]')
2021-04-11 09:59:33 -04:00
if [ ${{ github.repository_owner }} = "naiba" ]
2021-07-07 14:35:23 -04:00
then ALI_IMAGE_NAME=$(echo "registry.cn-shanghai.aliyuncs.com/naibahq/nezha-dashboard")
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
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
2021-07-07 14:35:23 -04:00
- name: Build dasbboard image And Push
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
platforms: linux/amd64,linux/arm64,linux/s390x
2021-07-07 14:35:23 -04: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 10:01:37 -05:00
${{ steps.image-name.outputs.ALI_IMAGE_NAME }}:latest
${{ steps.image-name.outputs.ALI_IMAGE_NAME }}:${{ steps.extract_branch.outputs.tag }}