github.com/openshift-online/ocm-sdk-go@v0.1.473/.github/workflows/publish-release.yaml (about)

     1  #
     2  # Copyright (c) 2021 Red Hat, Inc.
     3  #
     4  # Licensed under the Apache License, Version 2.0 (the "License");
     5  # you may not use this file except in compliance with the License.
     6  # You may obtain a copy of the License at
     7  #
     8  #   http://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  # Unless required by applicable law or agreed to in writing, software
    11  # distributed under the License is distributed on an "AS IS" BASIS,
    12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  #
    16  
    17  name: Publish release
    18  
    19  on:
    20    push:
    21      tags:
    22      - v*
    23  
    24  jobs:
    25  
    26    release:
    27      name: Publish release
    28      runs-on: ubuntu-latest
    29      steps:
    30      - name: Checkout the source
    31        uses: actions/checkout@v2
    32  
    33      - name: Setup Python
    34        uses: actions/setup-python@v5
    35        with:
    36          python-version: '3.10'
    37          cache: 'pip'
    38  
    39      - name: Install Python modules
    40        run: pip install -r .github/workflows/requirements.txt
    41  
    42      - name: Create release
    43        shell: python
    44        run: |
    45          import re
    46          import requests
    47  
    48          # Get the context and secret data that we will need:
    49          repository = "${{ github.repository }}"
    50          reference = "${{ github.ref }}"
    51          token = "${{ secrets.GITHUB_TOKEN }}"
    52  
    53          # Calculate the version number:
    54          version = re.sub(r"^refs/tags/v(.*)$", r"\1", reference)
    55  
    56          # Get the list of changes:
    57          body = ""
    58          with open("CHANGES.md", "r") as stream:
    59              while True:
    60                  line = stream.readline()
    61                  if line == "" or line.startswith("## " + version):
    62                      break
    63              while True:
    64                  line = stream.readline()
    65                  if line == "" or line.startswith("## "):
    66                      break
    67                  body += line
    68  
    69          # Send the request to create the release:
    70          response = requests.post(
    71              headers={
    72                  "Authorization": f"Bearer {token}",
    73                  "Content-Type": "application/json",
    74                  "Accept": "application/json",
    75              },
    76              json={
    77                  "tag_name": f"v{version}",
    78                  "name": f"Release {version}",
    79                  "body": body,
    80              },
    81              url=(
    82                  "https://api.github.com"
    83                  f"/repos/{repository}/releases"
    84              ),
    85          )
    86          response.raise_for_status()