fix: 处理可能存在的在接收频道消息时没有 Member.Roles
的情况
#19
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Release | |
on: | |
push: | |
tags: | |
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set up Go | |
uses: actions/setup-go@v2 | |
with: | |
go-version: 1.21.5 | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v2 | |
- name: Set up environment | |
run: | | |
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH | |
echo $PATH | |
echo $(go env GOPATH) | |
- name: Check if release exists | |
id: check_release | |
run: | | |
TAG_NAME=${{ github.ref }} # refs/tags/v0.1.0 | |
TAG_NAME=${TAG_NAME#refs/tags/} # v0.1.0 | |
RELEASE_ID=$(curl --silent --show-error --header "Authorization: token ${{ secrets.PAT }}" "https://api.github.com/repos/${{ github.repository }}/releases/tags/$TAG_NAME" | jq '.id') | |
IS_PRERELEASE=$(curl --silent --show-error --header "Authorization: token ${{ secrets.PAT }}" "https://api.github.com/repos/${{ github.repository }}/releases/tags/$TAG_NAME" | jq '.prerelease') | |
echo "RELEASE_ID=$RELEASE_ID" >> $GITHUB_ENV | |
echo "IS_PRERELEASE=$IS_PRERELEASE" >> $GITHUB_ENV | |
- name: Build binaries | |
uses: goreleaser/goreleaser-action@v2 | |
with: | |
version: latest | |
args: release | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT }} | |
IS_PRERELEASE: ${{ env.IS_PRERELEASE }} | |
# - name: Create Release | |
# id: create_release | |
# uses: actions/create-release@v1 | |
# env: | |
# GITHUB_TOKEN: ${{ secrets.PAT }} | |
# with: | |
# tag_name: ${{ github.ref }} | |
# release_name: Release ${{ github.ref }} | |
# draft: false | |
# prerelease: false | |
# if: env.RELEASE_ID == 'null' | |
- name: Upload Release Assets | |
run: | | |
UPLOAD_URL=$(if [ "${{ env.RELEASE_ID }}" == "null" ]; then echo "${{ steps.create_release.outputs.upload_url }}"; else echo "https://uploads.github.com/repos/${{ github.repository }}/releases/${{ env.RELEASE_ID }}/assets"; fi) | |
for file in dist/*; do | |
if [[ -f "$file" ]]; then | |
filename=$(basename -- "$file") | |
extension="${filename##*.}" | |
if [[ "$extension" == "exe" || "$extension" == "tar.gz" ]]; then | |
echo "Uploading $file" | |
curl \ | |
--header "Authorization: token ${{ secrets.PAT }}" \ | |
--header "Content-Type: $(file -b --mime-type $file)" \ | |
--data-binary @"$file" \ | |
"$UPLOAD_URL?name=$(basename $file)" | |
fi | |
fi | |
done |