Skip to content

Commit

Permalink
ci: release latest build (#151)
Browse files Browse the repository at this point in the history
Signed-off-by: zyguan <zhongyangguan@gmail.com>

Signed-off-by: zyguan <zhongyangguan@gmail.com>
  • Loading branch information
zyguan authored Oct 13, 2022
1 parent 2e28a9b commit 47d907e
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: "release"
on:
push:
tags:
- '*'
tags: ['v*']
branches: [ master ]

jobs:
release:
Expand All @@ -12,11 +12,51 @@ jobs:
with:
go-version: 1.18.x
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Run GoReleaser
- name: Release
if: github.event.ref != 'refs/heads/master'
uses: goreleaser/goreleaser-action@v1
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build
if: github.event.ref == 'refs/heads/master'
uses: goreleaser/goreleaser-action@v1
with:
version: latest
args: build --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Package
if: github.event.ref == 'refs/heads/master'
run: |
tar -zcf go-tpc_latest_linux_amd64.tar.gz -C dist/go-tpc_linux_amd64_v1 go-tpc
tar -zcf go-tpc_latest_linux_arm64.tar.gz -C dist/go-tpc_linux_arm64 go-tpc
tar -zcf go-tpc_latest_darwin_amd64.tar.gz -C dist/go-tpc_darwin_amd64_v1 go-tpc
tar -zcf go-tpc_latest_darwin_amd64.tar.gz -C dist/go-tpc_darwin_amd64 go-tpc
- name: Release latest build
uses: softprops/action-gh-release@v1
if: github.event.ref == 'refs/heads/master'
with:
name: Latest Build
tag_name: latest-${{ github.sha }}
files: |
*.tar.gz
- name: Clean legacy latest releases
uses: actions/github-script@v6
if: github.event.ref == 'refs/heads/master'
with:
script: |
const { owner, repo } = context.repo;
const releases = (await github.rest.repos.listReleases({ owner, repo })).data.filter(r => r.draft && r.tag_name.startsWith('latest'));
for (const r of releases) { await github.rest.repos.deleteRelease({ owner, repo, release_id: r.id }).catch(_ => {}); }
- name: Clean legacy latest tags
if: github.event.ref == 'refs/heads/master'
run: |
git tag -l | grep latest | grep -v latest-${{ github.sha }} | xargs -I{} git push -d origin {} || true

0 comments on commit 47d907e

Please sign in to comment.