Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Release Drafter with GitHub API #2584

Merged
merged 2 commits into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 0 additions & 60 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,3 @@
name-template: 'v$RESOLVED_VERSION'
tag-template: 'v$RESOLVED_VERSION'
categories:
- title: '🚀 Features'
labels:
- "enhancement"
- title: '💣 Breaking Change'
labels:
- "change"
- title: '🐛 Bug Fixes'
labels:
- "bug"
- title: '📝 Documentation'
labels:
- "documentation"
- title: '🧪 Tests'
labels:
- "tests"
- title: '🔨 Maintenance'
labels:
- "chore"
- title: '⬆️ Dependencies'
labels:
- "dependencies"
version-resolver:
major:
labels:
- 'change'
minor:
labels:
- 'enhancement'
patch:
labels:
- 'bug'
- 'chore'
- 'dependencies'
- 'documentation'
- 'tests'
default: patch
exclude-labels:
- 'skip-changelog'
autolabeler:
- label: 'documentation'
files:
Expand Down Expand Up @@ -71,22 +30,3 @@ autolabeler:
- 'vendor*'
branch:
- '/deps\/.+/'
template: |
*Help make the NGINX Ingress Controller better by participating in our [survey](https://forms.office.com/Pages/ResponsePage.aspx?id=L_093Ttq0UCb4L-DJ9gcUKLQ7uTJaE1PitM_37KR881UMEs0Rk5PMkYzMTJTWVA0V1hUVTRLUUMyNS4u)!*

## New in NGINX Ingress Controller v$RESOLVED_VERSION

$CHANGES

## Upgrade

- For NGINX, use the v$RESOLVED_VERSION image from our [DockerHub](https://hub.docker.com/r/nginx/nginx-ingress/tags?page=1&ordering=last_updated&name=$RESOLVED_VERSION), [GitHub Container](https://github.com/nginxinc/kubernetes-ingress/pkgs/container/kubernetes-ingress) or [Amazon ECR Public Gallery](https://gallery.ecr.aws/nginx/nginx-ingress).
- For NGINX Plus, use the v$RESOLVED_VERSION image from the F5 Container registry or the [AWS Marketplace](https://aws.amazon.com/marketplace/search/?CREATOR=741df81b-dfdc-4d36-b8da-945ea66b522c&FULFILLMENT_OPTION_TYPE=CONTAINER&filters=CREATOR%2CFULFILLMENT_OPTION_TYPE) or build your own image using the v$RESOLVED_VERSION source code.
- For Helm, use version HELM_VERSION_REPLACE_ME! of the chart.

## Resources

- Documentation -- https://docs.nginx.com/nginx-ingress-controller/
- Configuration examples -- https://github.com/nginxinc/kubernetes-ingress/tree/v$RESOLVED_VERSION/examples
- Helm Chart -- https://github.com/nginxinc/kubernetes-ingress/tree/v$RESOLVED_VERSION/deployments/helm-chart
- Operator -- https://github.com/nginxinc/nginx-ingress-operator/
26 changes: 26 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
changelog:
exclude:
labels:
- skip-changelog
categories:
- title: 🚀 Features
labels:
- enhancement
- title: 💣 Breaking Changes
labels:
- change
- title: 🐛 Bug Fixes
labels:
- bug
- title: 📝 Documentation
labels:
- documentation
- title: 🧪 Tests
labels:
- tests
- title: 🔨 Maintenance
labels:
- chore
- title: ⬆️ Dependencies
labels:
- dependencies
17 changes: 0 additions & 17 deletions .github/workflows/release-drafter-branches.yml

This file was deleted.

138 changes: 138 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
name: Create Draft Release

on:
push:
branches:
- release-*
workflow_dispatch:
inputs:
tagFrom:
description: The tag to create the release from.
required: true
type: string
tagTo:
description: The tag to create the release to.
required: true
type: string
branch:
description: The branch where the release will be created.
required: true
type: string

jobs:

binary:
name: Create Draft Release
runs-on: ubuntu-20.04
steps:
- uses: actions/setup-node@v3
- run: npm install semver
- uses: actions/github-script@v6
continue-on-error: true
with:
script: |
const semver = require('semver');
const ref = context.ref.split("/")[2]

const releases = (await github.rest.repos.listReleases({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
per_page: 100,
})).data

let latest_release
const latest_release_current_branch = releases.find(release => release.tag_name.includes(ref.split("-")[1]))

if (latest_release_current_branch === undefined){
latest_release = (await github.rest.repos.getLatestRelease({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
})).data.tag_name
} else {
latest_release = latest_release_current_branch.tag_name
}

let tagFrom, tagTo, branch
if (context.eventName === 'workflow_dispatch'){
console.log(`Dispatch run with inputs: ${JSON.stringify(context.payload.inputs)}`)
;({ tagFrom, tagTo, branch } = context.payload.inputs)
} else {
;({ tagFrom, tagTo, branch } = {
tagFrom: latest_release,
tagTo: 'next',
branch: ref,
})
console.log(`Push run with: { tagFrom: ${tagFrom}, tagTo: ${tagTo}, branch: ${branch} }`)
}
console.log(`The latest release was ${tagFrom}`)

let version = tagTo.replace('v', '')
if (version === 'next'){
const temp_notes = (await github.rest.repos.generateReleaseNotes({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
tag_name: tagTo,
previous_tag_name: tagFrom,
target_commitish: branch,
})).data.body

let level
temp_notes.includes("### 🚀 Features") ? level = 'minor' : level = 'patch'
temp_notes.includes("### 💣 Breaking Changes") ? level = 'major' : level = level
version = semver.inc(tagFrom, level)
console.log(`The level of the release is ${level}`)
}
const draft = releases.find((r) => r.draft && r.tag_name === "v"+version)
const draft_found = !(draft === undefined)

console.log(`The next version is v${version}`)

const footer = `
## Upgrade
- For NGINX, use the v${version} image from our [DockerHub](https://hub.docker.com/r/nginx/nginx-ingress/tags?page=1&ordering=last_updated&name=${version}), [GitHub Container](https://github.com/nginxinc/kubernetes-ingress/pkgs/container/kubernetes-ingress) or [Amazon ECR Public Gallery](https://gallery.ecr.aws/nginx/nginx-ingress).
- For NGINX Plus, use the v${version} image from the F5 Container registry or the [AWS Marketplace](https://aws.amazon.com/marketplace/search/?CREATOR=741df81b-dfdc-4d36-b8da-945ea66b522c&FULFILLMENT_OPTION_TYPE=CONTAINER&filters=CREATOR%2CFULFILLMENT_OPTION_TYPE) or build your own image using the v${version} source code.
- For Helm, use version HELM_VERSION_REPLACE_ME! of the chart.

## Resources
- Documentation -- https://docs.nginx.com/nginx-ingress-controller/
- Configuration examples -- https://github.com/nginxinc/kubernetes-ingress/tree/v${version}/examples
- Helm Chart -- https://github.com/nginxinc/kubernetes-ingress/tree/v${version}/deployments/helm-chart
- Operator -- https://github.com/nginxinc/nginx-ingress-operator/
`

const release_notes = (await github.rest.repos.generateReleaseNotes({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
tag_name: 'v' + version,
previous_tag_name: tagFrom,
target_commitish: branch,
}))

let release
if (draft_found){
console.log("Draft found")
release = (await github.rest.repos.updateRelease({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
release_id: draft.id,
tag_name: 'v' + version,
target_commitish: branch,
name: 'v' + version,
body: release_notes.data.body + footer,
draft: true,
}))
} else {
console.log("Draft not found")
release = (await github.rest.repos.createRelease({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
tag_name: 'v' + version,
target_commitish: ref,
name: 'v' + version,
body: release_notes.data.body + footer,
draft: true,
}))
}

console.log(`Release created: ${release.data.html_url}`)
console.log(`Release notes: ${release_notes.data.body}`)