Skip to content

Commit

Permalink
Pass a release body file because the release notes are too long
Browse files Browse the repository at this point in the history
  • Loading branch information
ForestEckhardt committed Dec 17, 2024
1 parent 540ac03 commit dac0f79
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 31 deletions.
9 changes: 5 additions & 4 deletions actions/stack/release-notes/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ name: 'Create Release Notes'
description: |
Creates release notes for a stack in Markdown format
outputs:
release_body:
description: Generated detailed release notes for the stack

inputs:
build_image:
description: 'Image registry location of build image'
Expand Down Expand Up @@ -47,6 +43,9 @@ inputs:
receipts_show_limit:
description: 'Integer which defines the limit of whether it should show or not the receipts array of each image'
required: false
release_body_file:
description: 'Path to the release body file'
required: false

runs:
using: 'docker'
Expand Down Expand Up @@ -78,3 +77,5 @@ runs:
- "${{ inputs.supports_usns }}"
- "--receipts-show-limit"
- "${{ inputs.receipts_show_limit }}"
- "--release-body-file"
- "${{ inputs.release_body_file }}"
45 changes: 19 additions & 26 deletions actions/stack/release-notes/entrypoint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ package main

import (
"bytes"
"crypto/rand"
_ "embed"
"encoding/hex"
"encoding/json"
"flag"
"fmt"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -53,6 +50,7 @@ func main() {
PatchedJSON string
SupportsUsns string
ReceiptsShowLimit string
ReleaseBodyFile string
}

flag.StringVar(&config.BuildImage, "build-image", "", "Registry location of stack build image")
Expand All @@ -61,13 +59,14 @@ func main() {
flag.StringVar(&config.RunCveReport, "run-cve-report", "", "CVE scan report path of run image in markdown format")
flag.StringVar(&config.PatchedJSON, "patched-usns", "", "JSON Array of patched USNs")
flag.StringVar(&config.SupportsUsns, "supports-usns", "", "Boolean variable to show patched USNs in release notes")
flag.StringVar(&config.BuildPackagesAddedJSON, "build-added", "", "JSON Array of packages added to build image")
flag.StringVar(&config.BuildPackagesModifiedJSON, "build-modified", "", "JSON Array of packages modified in build image")
flag.StringVar(&config.BuildPackagesRemovedJSON, "build-removed", "", "JSON Array of packages removed in build image")
flag.StringVar(&config.RunPackagesAddedJSON, "run-added", "", "JSON Array of packages added to run image")
flag.StringVar(&config.RunPackagesModifiedJSON, "run-modified", "", "JSON Array of packages modified in run image")
flag.StringVar(&config.RunPackagesRemovedJSON, "run-removed", "", "JSON Array of packages removed in run image")
flag.StringVar(&config.BuildPackagesAddedJSON, "build-added", "", "Path to diff file of packages added to build image")
flag.StringVar(&config.BuildPackagesModifiedJSON, "build-modified", "", "Path to diff file of packages modified in build image")
flag.StringVar(&config.BuildPackagesRemovedJSON, "build-removed", "", "Path to diff file of packages removed in build image")
flag.StringVar(&config.RunPackagesAddedJSON, "run-added", "", "Path to diff file of packages added to run image")
flag.StringVar(&config.RunPackagesModifiedJSON, "run-modified", "", "Path to diff file of packages modified in run image")
flag.StringVar(&config.RunPackagesRemovedJSON, "run-removed", "", "Path to diff file of packages removed in run image")
flag.StringVar(&config.ReceiptsShowLimit, "receipts-show-limit", "", "Integer which defines the limit of whether it should show or not the receipts array of each image")
flag.StringVar(&config.ReleaseBodyFile, "release-body-file", "", "Path to release body file")
flag.Parse()

absolute, err := filepath.Abs(config.BuildPackagesAddedJSON)
Expand Down Expand Up @@ -106,6 +105,12 @@ func main() {
}
config.RunPackagesRemovedJSON = absolute

absolute, err = filepath.Abs(config.ReleaseBodyFile)
if err != nil {
log.Fatalf("Failed to create absolute path for %s", config.ReleaseBodyFile)
}
config.ReleaseBodyFile = absolute

var contents struct {
PatchedArray []USN
SupportsUsns bool
Expand Down Expand Up @@ -240,28 +245,16 @@ func main() {
log.Fatalf("failed to execute release notes template: %s", err.Error())
}

fmt.Println(b.String())

outputFileName, ok := os.LookupEnv("GITHUB_OUTPUT")
if !ok {
log.Fatalf("GITHUB_OUTPUT is not set, see https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter")
}
file, err := os.OpenFile(outputFileName, os.O_APPEND|os.O_WRONLY, 0)
releaseBodyFile, err := os.OpenFile(config.ReleaseBodyFile, os.O_RDWR|os.O_CREATE, 0666)
if err != nil {
log.Fatalf("failed to set output: %s", err.Error())
log.Fatal(err)
}
defer file.Close()
delimiter := generateDelimiter()
fmt.Fprintf(file, "release_body<<%s\n%s\n%s\n", delimiter, b.String(), delimiter) // see https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
}
defer releaseBodyFile.Close()

func generateDelimiter() string {
data := make([]byte, 16) // roughly the same entropy as uuid v4 used in https://github.com/actions/toolkit/blob/b36e70495fbee083eb20f600eafa9091d832577d/packages/core/src/file-command.ts#L28
_, err := rand.Read(data)
err = releaseBodyFile.Write(b.Bytes())
if err != nil {
log.Fatal("could not generate random delimiter", err)
log.Fatalf("failed to write release body: %s", err.Error())
}
return hex.EncodeToString(data)
}

func fixEmptyArray(original string) string {
Expand Down
3 changes: 2 additions & 1 deletion stack/.github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ jobs:
run_packages_modified: "/github/workspace/${{ env.RUN_DIFF_MODIFIED_FILENAME }}"
run_packages_removed_with_force: "/github/workspace/${{ env.RUN_DIFF_REMOVED_FILENAME }}"
patched_usns: ${{ needs.poll_usns.outputs.usns }}
release_body_file: "/github/workspace/release-body.md"

- name: Setup Release Assets
id: assets
Expand Down Expand Up @@ -512,7 +513,7 @@ jobs:
tag_name: v${{ steps.tag.outputs.tag }}
target_commitish: ${{ github.sha }}
name: v${{ steps.tag.outputs.tag }}
body: ${{ steps.notes.outputs.release_body }}
body_file: "/github/workspace/release-body.md"
draft: false
assets: ${{ steps.assets.outputs.assets }}

Expand Down

0 comments on commit dac0f79

Please sign in to comment.