nezha/.github/workflows/release.yml

124 lines
4.6 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*"
2022-06-07 09:42:53 -04:00
workflow_dispatch:
2020-11-06 07:51:23 -05:00
jobs:
2023-11-28 10:18:29 -05:00
release:
2020-11-06 07:51:23 -05:00
runs-on: ubuntu-latest
steps:
2023-10-21 06:27:25 -04:00
- uses: actions/checkout@v4
2020-11-11 09:21:16 -05:00
- name: Extract branch name
run: |
export TAG_NAME=$(echo ${GITHUB_REF#refs/tags/})
echo "tag=$TAG_NAME" >> $GITHUB_OUTPUT
id: extract_branch
2022-07-06 23:50:25 -04:00
- name: xgo build
2022-07-06 23:21:54 -04:00
uses: crazy-max/ghaction-xgo@v2
with:
2023-10-21 10:35:12 -04:00
xgo_version: latest
2024-07-13 01:11:40 -04:00
go_version: 1.21.x
2022-07-06 23:50:25 -04:00
dest: dist
2022-07-06 23:21:54 -04:00
pkg: cmd/dashboard
prefix: dashboard
targets: linux/amd64,linux/arm64,linux/arm-7,linux/s390x,linux/riscv64,windows/amd64,windows/386,windows/arm64 # linux/386,
2022-07-06 23:21:54 -04:00
v: true
x: false
race: false
tags: timetzdata
2023-11-29 02:45:32 -05:00
ldflags: -s -w --extldflags '-static -fpic' -X github.com/naiba/nezha/service/singleton.Version=${{ steps.extract_branch.outputs.tag }}
2022-07-06 23:21:54 -04:00
buildmode: default
2022-07-07 01:38:44 -04:00
- name: fix dist
run: |
2024-07-13 01:11:40 -04:00
ls -al dist/
2023-11-29 04:13:45 -05:00
mv dist/dashboard-linux-arm-7 dist/dashboard-linux-arm
2021-08-18 06:53:35 -04:00
- name: Log in to the GHCR
uses: docker/login-action@master
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- 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: |
GHRC_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
2021-07-07 14:38:35 -04:00
echo "::set-output name=GHRC_IMAGE_NAME::$GHRC_IMAGE_NAME"
echo "::set-output name=ALI_IMAGE_NAME::$ALI_IMAGE_NAME"
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
2022-07-07 02:09:01 -04:00
platforms: linux/amd64,linux/arm64,linux/arm,linux/s390x,linux/riscv64 # linux/386,
2021-07-07 14:35:23 -04:00
push: true
tags: |
2023-11-28 10:01:37 -05:00
${{ steps.image-name.outputs.GHRC_IMAGE_NAME }}:latest
${{ steps.image-name.outputs.GHRC_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 }}
2023-02-11 10:08:28 -05:00
2023-11-28 10:01:37 -05:00
- name: Compress dist files
run: |
for file in dist/*; do
if [ -f "$file" ]; then
zip -r "$file.zip" "$file"
fi
done
- name: Release
2023-11-28 10:08:50 -05:00
uses: ncipollo/release-action@v1
with:
artifacts: "dist/*.zip"
generateReleaseNotes: true
2023-11-28 10:01:37 -05:00
2023-02-11 10:08:28 -05:00
- 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
2024-07-14 02:38:12 -04:00
- name: Trigger sync
if: ${{ env.SYNCED == 0 }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.rest.actions.createWorkflowDispatch({
owner: 'naiba',
repo: 'nezha',
workflow_id: 'sync-release.yml',
ref: 'main'
})