Skip to content

Merge pull request #1 from tmpMeM/main #11

Merge pull request #1 from tmpMeM/main

Merge pull request #1 from tmpMeM/main #11

Workflow file for this run

name: Go Build and Release
on:
push:
tags:
- 'v*' # 只在推送符合版本标签的分支时触发
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.22'
- name: Display Go version
run: go version
- name: Build Go executable
run: |
GOOS=windows GOARCH=amd64 go build -o cmddir.exe ./main.go
- name: Upload executable as artifact
uses: actions/upload-artifact@v4
with:
name: cmddir
path: cmddir.exe
release:
name: Create Release
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: cmddir
- name: Create GitHub Release
id: create_release
uses: actions/github-script@v7
with:
script: |
const tagName = context.ref.replace('refs/tags/', '');
const { data: existingRelease } = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo
});
let release;
if (existingRelease.some(r => r.tag_name === tagName)) {
console.log(`Release with tag ${tagName} already exists.`);
release = existingRelease.find(r => r.tag_name === tagName);
} else {
release = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: tagName,
name: `Release ${tagName}`,
draft: false,
prerelease: false
});
}
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.id,
name: 'cmddir.exe',
data: require('fs').readFileSync('cmddir.exe')
});