Skip to content

Commit

Permalink
Github action for releases
Browse files Browse the repository at this point in the history
  • Loading branch information
zimbatm committed Jan 31, 2020
1 parent e9bca3d commit 5cd51ba
Show file tree
Hide file tree
Showing 3 changed files with 139 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 @@
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

# TODO: also publish the dist
name: Create Release

jobs:
build:
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.13.6
uses: actions/setup-go@v1
with:
go-version: 1.13.6
- name: Checkout code
uses: actions/checkout@master
- name: Get release notes
id: release-notes
run: |
go run ./script/issue-command/main.go set-output \
--name=body \
"$(go run ./script/release-changelog/main.go)"
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body: "${{ steps.release-notes.outputs.body }}"
draft: true
prerelease: false
56 changes: 56 additions & 0 deletions script/issue-command/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package main

import (
"fmt"
"os"
"strings"
)

func escapeData(data string) string {
data = strings.ReplaceAll(data, "%", "%25")
data = strings.ReplaceAll(data, "\r", "%0D")
data = strings.ReplaceAll(data, "\n", "%0A")
return data
}

func escapeProperty(prop string) string {
prop = escapeData(prop)
prop = strings.ReplaceAll(prop, ":", "%3A")
prop = strings.ReplaceAll(prop, ",", "%2C")
return prop
}

// Go implementation of
// https://github.com/actions/toolkit/blob/master/packages/core/src/command.ts
func main() {
var remain []string
var props []string

for _, arg := range os.Args[1:] {
if arg == "--" {
continue
}
if strings.HasPrefix(arg, "--") {
kv := strings.SplitN(arg[2:], "=", 2)
if len(kv) != 2 {
panic(fmt.Sprintf("expected %s to be of form --key=value", arg[2:]))
}
props = append(props, fmt.Sprintf("%s=%s", kv[0], escapeProperty(kv[1])))
} else {
remain = append(remain, arg)
}
}

if len(remain) != 2 {
panic(fmt.Sprintf("expected 2 remaining arguments, go %v", remain))
}

cmd := remain[0]
msg := escapeData(remain[1])
var propStr string
if len(props) > 0 {
propStr = " " + strings.Join(props, ",")
}

fmt.Printf("::%s%s::%s", cmd, propStr, msg)
}
46 changes: 46 additions & 0 deletions script/release-changelog/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"bufio"
"os"
"strings"
)

func run() error {
headers := 0

f, err := os.Open("CHANGELOG.md")
if err != nil {
return err
}

r := bufio.NewReader(f)

prev, err := r.ReadString('\n')
if err != nil {
return err
}

for {
line, err := r.ReadString('\n')
if err != nil {
return err
}
if strings.HasPrefix(line, "======") {
headers++
}
if headers > 1 {
return nil
}

os.Stdout.WriteString(prev)
prev = line
}
}

func main() {
err := run()
if err != nil {
panic(err)
}
}

0 comments on commit 5cd51ba

Please sign in to comment.