github.com/nginxinc/kubernetes-ingress@v1.12.5/.github/workflows/release-drafter.yml (about)

     1  name: Create Draft Release
     2  
     3  on:
     4    push:
     5      branches:
     6        - release-*
     7    workflow_dispatch:
     8      inputs:
     9        tagFrom:
    10          description: The tag to create the release from.
    11          required: true
    12          type: string
    13        tagTo:
    14          description: The tag to create the release to.
    15          required: true
    16          type: string
    17        branch:
    18          description: The branch where the release will be created.
    19          required: true
    20          type: string
    21  
    22  jobs:
    23  
    24    binary:
    25      name: Create Draft Release
    26      runs-on: ubuntu-20.04
    27      steps:
    28        - uses: actions/setup-node@v3
    29        - run: npm install semver
    30        - uses: actions/github-script@v6
    31          continue-on-error: true
    32          with:
    33            script: |
    34              const semver = require('semver');
    35              const ref = context.ref.split("/")[2]
    36  
    37              const releases = (await github.rest.repos.listReleases({
    38                owner: context.payload.repository.owner.login,
    39                repo: context.payload.repository.name,
    40                per_page: 100,
    41              })).data
    42  
    43              let latest_release
    44              const latest_release_current_branch = releases.find(release => !release.draft && release.tag_name.startsWith("v" + ref.split("-")[1]))
    45  
    46              if (latest_release_current_branch === undefined){
    47                latest_release = (await github.rest.repos.getLatestRelease({
    48                  owner: context.payload.repository.owner.login,
    49                  repo: context.payload.repository.name,
    50                })).data.tag_name
    51              } else {
    52                latest_release = latest_release_current_branch.tag_name
    53              }
    54  
    55              let tagFrom, tagTo, branch
    56              if (context.eventName === 'workflow_dispatch'){
    57                console.log(`Dispatch run with inputs: ${JSON.stringify(context.payload.inputs)}`)
    58                ;({ tagFrom, tagTo, branch } = context.payload.inputs)
    59              } else {
    60                ;({ tagFrom, tagTo, branch } = {
    61                  tagFrom: latest_release,
    62                  tagTo: 'next',
    63                  branch: ref,
    64                })
    65                console.log(`Push run with: { tagFrom: ${tagFrom}, tagTo: ${tagTo}, branch: ${branch} }`)
    66              }
    67              console.log(`The latest release was ${tagFrom}`)
    68  
    69              let version = tagTo.replace('v', '')
    70              if (version === 'next'){
    71                const temp_notes = (await github.rest.repos.generateReleaseNotes({
    72                  owner: context.payload.repository.owner.login,
    73                  repo: context.payload.repository.name,
    74                  tag_name: tagTo,
    75                  previous_tag_name: tagFrom,
    76                  target_commitish: branch,
    77                })).data.body
    78  
    79                let level
    80                temp_notes.includes("### 🚀 Features") ? level = 'minor' : level = 'patch'
    81                temp_notes.includes("### 💣 Breaking Changes") ? level = 'major' : level = level
    82                version = semver.inc(tagFrom, level)
    83                console.log(`The level of the release is ${level}`)
    84              }
    85              const draft = releases.find((r) => r.draft && r.tag_name === "v"+version)
    86              const draft_found = !(draft === undefined)
    87  
    88              console.log(`The next version is v${version}`)
    89  
    90              const footer = `
    91                ## Upgrade
    92                - 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), [Amazon ECR Public Gallery](https://gallery.ecr.aws/nginx/nginx-ingress) or [Quay.io](https://quay.io/repository/nginx/nginx-ingress).
    93                - 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.
    94                - For Helm, use version %HELM_CHART_VERSION% of the chart.
    95  
    96                ## Resources
    97                - Documentation -- https://docs.nginx.com/nginx-ingress-controller/
    98                - Configuration examples -- https://github.com/nginxinc/kubernetes-ingress/tree/v${version}/examples
    99                - Helm Chart -- https://github.com/nginxinc/kubernetes-ingress/tree/v${version}/deployments/helm-chart
   100                - Operator -- https://github.com/nginxinc/nginx-ingress-operator/
   101              `
   102  
   103              const release_notes = (await github.rest.repos.generateReleaseNotes({
   104                owner: context.payload.repository.owner.login,
   105                repo: context.payload.repository.name,
   106                tag_name: 'v' + version,
   107                previous_tag_name: tagFrom,
   108                target_commitish: branch,
   109              }))
   110  
   111              let release
   112              if (draft_found){
   113                console.log("Draft found")
   114                release = (await github.rest.repos.updateRelease({
   115                  owner: context.payload.repository.owner.login,
   116                  repo: context.payload.repository.name,
   117                  release_id: draft.id,
   118                  tag_name: 'v' + version,
   119                  target_commitish: branch,
   120                  name: 'v' + version,
   121                  body: release_notes.data.body + footer,
   122                  draft: true,
   123                }))
   124              } else {
   125                console.log("Draft not found")
   126                release = (await github.rest.repos.createRelease({
   127                  owner: context.payload.repository.owner.login,
   128                  repo: context.payload.repository.name,
   129                  tag_name: 'v' + version,
   130                  target_commitish: ref,
   131                  name: 'v' + version,
   132                  body: release_notes.data.body + footer,
   133                  draft: true,
   134                }))
   135              }
   136  
   137              console.log(`Release created: ${release.data.html_url}`)
   138              console.log(`Release notes: ${release_notes.data.body}`)