Skip to content

Commit

Permalink
release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
jkaflik committed Sep 12, 2023
1 parent 351c034 commit 9d4a43b
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: publish draft release

permissions: read-all|write-all

on:
workflow_dispatch:

jobs:
single-node:
runs-on: [self-hosted, style-checker]
steps:
- uses: actions/checkout@main

- name: Install Go 1.21
uses: actions/[email protected]
with:
stable: false
go-version: 1.21

- name: Prepare release
id: release_prep
run: |
go run internal/cmd/release_prep/main.go
- name: Commit and push hanges
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add .
git commit -m "Update release notes"
git push
- name: Publish draft release
env:
RELEASE_API_URL: ${{ steps.release_prep.outputs.RELEASE_URL }}
run: |
curl -X PATCH -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" $RELEASE_API_URL -d '{"draft": false}'
29 changes: 29 additions & 0 deletions internal/cmd/release_prep/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,35 @@ func main() {

runGoGenerate()
runGoFmt()

gitHubOutputReleaseURLIfAvailable(releaseURL)
}

func gitHubOutputReleaseURLIfAvailable(url string) {
if len(url) == 0 {
return
}

gitHubOutputFile, exists := os.LookupEnv("GITHUB_OUTPUT")
if !exists {
return
}

f, err := os.OpenFile(gitHubOutputFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Fatalln(err)
return
}

if _, err := f.WriteString(fmt.Sprintf("RELEASE_URL=%s\n", url)); err != nil {
log.Fatalln(err)
return
}

if err := f.Close(); err != nil {
log.Fatalln(err)
return
}
}

func runGoFmt() {
Expand Down

0 comments on commit 9d4a43b

Please sign in to comment.