Skip to content

Commit

Permalink
Merge pull request #630 from paketo-buildpacks/release-draft
Browse files Browse the repository at this point in the history
Add an action to update draft release notes
  • Loading branch information
Daniel Mikusa authored Apr 14, 2022
2 parents eaa12f7 + 52ccb19 commit 062dd10
Show file tree
Hide file tree
Showing 22 changed files with 1,528 additions and 46 deletions.
2 changes: 2 additions & 0 deletions .github/pipeline-descriptor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ actions:
target: ghcr.io/paketo-buildpacks/actions/cf-java-index-dependency
- source: clojure-tools-dependency
target: ghcr.io/paketo-buildpacks/actions/clojure-tools-dependency
- source: draft-release
target: ghcr.io/paketo-buildpacks/actions/draft-release
- source: foojay-dependency
target: ghcr.io/paketo-buildpacks/actions/foojay-dependency
- source: gcs-dependency
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/create-action-draft-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Create Action draft-release
"on":
pull_request:
paths:
- actions/*
- actions/draft-release/*
push:
branches:
- main
paths:
- actions/*
- actions/draft-release/*
release:
types:
- published
jobs:
create-action:
name: Create Action
runs-on:
- ubuntu-latest
steps:
- name: Docker login ghcr.io
if: ${{ (github.event_name != 'pull_request' || ! github.event.pull_request.head.repo.fork) && (github.actor != 'dependabot[bot]') }}
uses: docker/login-action@v1
with:
password: ${{ secrets.JAVA_GITHUB_TOKEN }}
registry: ghcr.io
username: ${{ secrets.JAVA_GITHUB_USERNAME }}
- uses: actions/checkout@v3
- name: Create Action
run: |
#!/usr/bin/env bash
set -euo pipefail
echo "::group::Building ${TARGET}:${VERSION}"
docker build \
--file actions/Dockerfile \
--build-arg "SOURCE=${SOURCE}" \
--tag "${TARGET}:${VERSION}" \
.
echo "::endgroup::"
if [[ "${PUSH}" == "true" ]]; then
echo "::group::Pushing ${TARGET}:${VERSION}"
docker push "${TARGET}:${VERSION}"
echo "::endgroup::"
else
echo "Skipping push"
fi
env:
PUSH: ${{ github.event_name != 'pull_request' }}
SOURCE: draft-release
TARGET: ghcr.io/paketo-buildpacks/actions/draft-release
VERSION: main
81 changes: 80 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,85 @@ name: Tests
branches:
- main
jobs:
integration:
name: Integration Test
runs-on:
- ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
path: ${{ env.HOME }}/go/pkg/mod
restore-keys: ${{ runner.os }}-go-
- uses: actions/setup-go@v2
with:
go-version: "1.17"
- name: Install create-package
run: |
#!/usr/bin/env bash
set -euo pipefail
GO111MODULE=on go get -u -ldflags="-s -w" github.com/paketo-buildpacks/libpak/cmd/create-package
- name: Install pack
run: |
#!/usr/bin/env bash
set -euo pipefail
echo "Installing pack ${PACK_VERSION}"
mkdir -p "${HOME}"/bin
echo "${HOME}/bin" >> "${GITHUB_PATH}"
curl \
--location \
--show-error \
--silent \
"https://github.com/buildpacks/pack/releases/download/v${PACK_VERSION}/pack-v${PACK_VERSION}-linux.tgz" \
| tar -C "${HOME}"/bin -xz pack
env:
PACK_VERSION: 0.24.0
- name: Enable pack Experimental
if: ${{ false }}
run: |
#!/usr/bin/env bash
set -euo pipefail
echo "Enabling pack experimental features"
mkdir -p "${HOME}"/.pack
echo "experimental = true" >> "${HOME}"/.pack/config.toml
- name: Install richgo
run: |
#!/usr/bin/env bash
set -euo pipefail
echo "Installing richgo ${RICHGO_VERSION}"
mkdir -p "${HOME}"/bin
echo "${HOME}/bin" >> "${GITHUB_PATH}"
curl \
--location \
--show-error \
--silent \
"https://github.com/kyoh86/richgo/releases/download/v${RICHGO_VERSION}/richgo_${RICHGO_VERSION}_linux_amd64.tar.gz" \
| tar -C "${HOME}"/bin -xz richgo
env:
RICHGO_VERSION: 0.3.10
- name: Run Tests
run: |
#!/usr/bin/env bash
set -euo pipefail
richgo test ./integration/... -run Integration
env:
RICHGO_FORCE_COLOR: "1"
unit:
name: Unit Test
runs-on:
Expand Down Expand Up @@ -44,6 +123,6 @@ jobs:
set -euo pipefail
richgo test ./...
richgo test ./... -run Unit
env:
RICHGO_FORCE_COLOR: "1"
2 changes: 1 addition & 1 deletion actions/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
type Inputs map[string]string

func NewInputs() Inputs {
re := regexp.MustCompile("^INPUT_([A-Z0-9-_]+)=(.+)$")
re := regexp.MustCompile("^INPUT_([A-Z0-9-_]+)=((?s).+)$")

i := make(Inputs)
for _, s := range os.Environ() {
Expand Down
67 changes: 67 additions & 0 deletions actions/draft-release/draft.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
**ID**: `{{ .PrimaryBuildpack.Info.ID }}`
**Digest**: <!-- DIGEST PLACEHOLDER -->

{{ if .NestedBuildpacks -}}
#### Included Buildpackages:
Name | ID | Version
:--- | :- | :------
{{ range .NestedBuildpacks -}}
{{ .Info.Name }} | `{{ .Info.ID }}` | `{{ .Info.Version }}`
{{ end -}}
{{ end -}}

{{ if .PrimaryBuildpack.Stacks }}
#### Supported Stacks:
{{ range .PrimaryBuildpack.Stacks -}}
- `{{ .ID }}`
{{ end -}}
{{ end }}

{{ if .PrimaryBuildpack.Dependencies }}
#### Dependencies:
Name | Version | SHA256
:--- | :------ | :-----
{{ range .PrimaryBuildpack.Dependencies -}}
{{ .Name }} | `{{ .Version }}` | `{{ .SHA256 }}`
{{ end }}
{{ end }}
{{ if .PrimaryBuildpack.OrderGroups }}
<details>
<summary>Order Groupings</summary>

{{ range .PrimaryBuildpack.OrderGroups -}}
ID | Version | Optional
:- | :------ | :-------
{{ range .Groups -}}
`{{ .ID }}` | `{{ .Version }}` | `{{ .Optional }}`
{{ end }}
{{ end -}}
</details>
{{ end }}
---

{{ range .NestedBuildpacks -}}
<details>
<summary>{{- .Info.Name }} {{ .Info.Version -}}</summary>

**ID**: `{{ .Info.ID }}`

{{ if .Stacks -}}
#### Supported Stacks:
{{ range .Stacks -}}
- `{{ .ID }}`
{{ end -}}
{{ end }}
{{ if .Dependencies -}}
#### Dependencies:
Name | Version | SHA256
:--- | :------ | :-----
{{ range .Dependencies -}}
{{ .Name }} | `{{ .Version }}` | `{{ .SHA256 }}`
{{ end -}}
{{ end -}}

---
</details>
{{ end }}
{{ .Release.Body -}}
90 changes: 90 additions & 0 deletions actions/draft-release/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright 2018-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package main

import (
_ "embed"

"fmt"
"io/ioutil"
"path/filepath"

"github.com/paketo-buildpacks/libpak/effect"
"github.com/paketo-buildpacks/pipeline-builder/actions"
"github.com/paketo-buildpacks/pipeline-builder/drafts"
)

//go:embed "draft.template"
var templateContents string

func main() {
inputs := actions.NewInputs()

drafter := drafts.Drafter{Loader: drafts.RegistryBuildpackLoader{}}
payload, err := drafter.CreatePayload(inputs, ".")
if err != nil {
panic(err)
}

scratchDir, err := ioutil.TempDir("", "drafts")
if err != nil {
panic(err)
}

err = drafter.BuildAndWriteReleaseToFileDraftFromTemplate(
filepath.Join(scratchDir, "body"), templateContents, payload)
if err != nil {
panic(err)
}

name := payload.Release.Name
if payload.PrimaryBuildpack.Info.Name != "" {
name = fmt.Sprintf("%s %s", payload.PrimaryBuildpack.Info.Name, payload.Release.Name)
}

err = ioutil.WriteFile(filepath.Join(scratchDir, "name"), []byte(name), 0644)
if err != nil {
panic(err)
}

execution := effect.Execution{
Command: "gh",
Args: []string{
"api",
"--method", "PATCH",
fmt.Sprintf("/repos/:owner/:repo/releases/%s", payload.Release.ID),
"--field", fmt.Sprintf("tag_name=%s", payload.Release.Tag),
"--field", fmt.Sprintf("name=@%s/name", scratchDir),
"--field", fmt.Sprintf("body=@%s/body", scratchDir),
},
}
if _, dryRun := inputs["dry_run"]; dryRun {
bits, err := ioutil.ReadFile(filepath.Join(scratchDir, "body"))
if err != nil {
panic(err)
}

fmt.Println("Title:", name)
fmt.Println("Body:", string(bits))
fmt.Println("Would execute:", execution)
} else {
err = effect.NewExecutor().Execute(execution)
if err != nil {
panic(fmt.Errorf("unable to execute %s\n%w", execution, err))
}
}
}
Loading

0 comments on commit 062dd10

Please sign in to comment.