From d0eb330f94c02dcdd0d243feb81583d16716ec58 Mon Sep 17 00:00:00 2001 From: Luca Comellini Date: Fri, 8 Apr 2022 02:08:10 -0700 Subject: [PATCH 1/2] Replace Release Drafter with GitHub API --- .github/release-drafter.yml | 60 --------- .github/release.yml | 26 ++++ .../workflows/release-drafter-branches.yml | 17 --- .github/workflows/release.yaml | 117 ++++++++++++++++++ 4 files changed, 143 insertions(+), 77 deletions(-) create mode 100644 .github/release.yml delete mode 100644 .github/workflows/release-drafter-branches.yml create mode 100644 .github/workflows/release.yaml diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 4ab54d49ed..485188332e 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -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: @@ -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/ diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 0000000000..191ccd628f --- /dev/null +++ b/.github/release.yml @@ -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 diff --git a/.github/workflows/release-drafter-branches.yml b/.github/workflows/release-drafter-branches.yml deleted file mode 100644 index 9cc9fdcd89..0000000000 --- a/.github/workflows/release-drafter-branches.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: Release Drafter (branches) - -on: - push: - branches: - - main - - release-* - -jobs: - update_release_draft: - runs-on: ubuntu-20.04 - steps: - - uses: release-drafter/release-drafter@v5 - with: - disable-autolabeler: true - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000000..3859b12763 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,117 @@ +name: Create Draft Release + +on: + push: + branches: + - main + - release-* + +jobs: + + binary: + name: Create Draft Release + runs-on: ubuntu-20.04 + steps: + - uses: actions/setup-node@v2 + - run: npm install semver + - uses: actions/github-script@v6 + continue-on-error: true + id: data + 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 + } + console.log(`The latest release was ${latest_release}`) + + let level = 'patch' + for await (const response of github.paginate.iterator(await github.rest.pulls.list({ + owner: context.payload.repository.owner.login, + repo: context.payload.repository.name, + state: 'closed', + per_page: 100, + sort: 'updated', + direction: 'desc', + }))) { + if (response.data.find((pulls) => pulls.labels.find((label) => label.name === 'change'))) { + level = 'major' + break; + } + if (response.data.find((pulls) => pulls.labels.find((label) => label.name === 'enhancement'))) { + level = 'minor' + break; + } + } + + const version = semver.inc(latest_release, level); + const draft = releases.find((r) => r.draft && r.tag_name === "v"+version) + const draft_found = !(draft === undefined) + + console.log(`The level of the release is ${level} and the 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: latest_release, + target_commitish: ref, + })) + + 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: ref, + 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}`) From a132caa1358b00278356f24d5873a1eaf60e34cf Mon Sep 17 00:00:00 2001 From: Luca Comellini Date: Fri, 8 Apr 2022 16:25:31 -0700 Subject: [PATCH 2/2] Add workflow_dispatch for manual run --- .github/workflows/release.yaml | 73 ++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 26 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 3859b12763..10e5748d63 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -3,8 +3,21 @@ name: Create Draft Release on: push: branches: - - main - 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: @@ -12,11 +25,10 @@ jobs: name: Create Draft Release runs-on: ubuntu-20.04 steps: - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v3 - run: npm install semver - uses: actions/github-script@v6 continue-on-error: true - id: data with: script: | const semver = require('semver'); @@ -39,32 +51,41 @@ jobs: } else { latest_release = latest_release_current_branch.tag_name } - console.log(`The latest release was ${latest_release}`) - let level = 'patch' - for await (const response of github.paginate.iterator(await github.rest.pulls.list({ - owner: context.payload.repository.owner.login, - repo: context.payload.repository.name, - state: 'closed', - per_page: 100, - sort: 'updated', - direction: 'desc', - }))) { - if (response.data.find((pulls) => pulls.labels.find((label) => label.name === 'change'))) { - level = 'major' - break; - } - if (response.data.find((pulls) => pulls.labels.find((label) => label.name === 'enhancement'))) { - level = 'minor' - break; - } + 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}`) - const version = semver.inc(latest_release, level); + 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 level of the release is ${level} and the version is v${version}`) + console.log(`The next version is v${version}`) const footer = ` ## Upgrade @@ -83,8 +104,8 @@ jobs: owner: context.payload.repository.owner.login, repo: context.payload.repository.name, tag_name: 'v' + version, - previous_tag_name: latest_release, - target_commitish: ref, + previous_tag_name: tagFrom, + target_commitish: branch, })) let release @@ -95,7 +116,7 @@ jobs: repo: context.payload.repository.name, release_id: draft.id, tag_name: 'v' + version, - target_commitish: ref, + target_commitish: branch, name: 'v' + version, body: release_notes.data.body + footer, draft: true,