github.com/giantswarm/apiextensions/v2@v2.6.2/.github/workflows/zz_generated.create_release.yaml (about)

     1  # DO NOT EDIT. Generated with:
     2  #
     3  #    devctl gen workflows
     4  #
     5  name: Create Release
     6  on:
     7    push:
     8      branches:
     9        - 'legacy'
    10        - 'master'
    11        - 'release-v*.*.x'
    12        # "!" negates previous positive patterns so it has to be at the end.
    13        - '!release-v*.x.x'
    14  jobs:
    15    debug_info:
    16      name: Debug info
    17      runs-on: ubuntu-18.04
    18      steps:
    19        - name: Print github context JSON
    20          run: |
    21            cat <<EOF
    22            ${{ toJson(github) }}
    23            EOF
    24    gather_facts:
    25      name: Gather facts
    26      runs-on: ubuntu-18.04
    27      outputs:
    28        project_go_path: ${{ steps.get_project_go_path.outputs.path }}
    29        version: ${{ steps.get_version.outputs.version }}
    30      steps:
    31        - name: Get version
    32          id: get_version
    33          run: |
    34            title="$(echo "${{ github.event.head_commit.message }}" | head -n 1 -)"
    35            # Matches strings like:
    36            #
    37            #   - "release v1.2.3"
    38            #   - "release v1.2.3-r4"
    39            #   - "release v1.2.3 (#56)"
    40            #   - "release v1.2.3-r4 (#56)"
    41            #
    42            # And outputs version part (1.2.3).
    43            if echo $title | grep -qE '^release v[0-9]+\.[0-9]+\.[0-9]+([.-][^ .-][^ ]*)?( \(#[0-9]+\))?$' ; then
    44              version=$(echo $title | cut -d ' ' -f 2)
    45            fi
    46            version="${version#v}" # Strip "v" prefix.
    47            echo "version=\"$version\""
    48            echo "::set-output name=version::${version}"
    49        - name: Checkout code
    50          if: ${{ steps.get_version.outputs.version != '' }}
    51          uses: actions/checkout@v2
    52        - name: Get project.go path
    53          id: get_project_go_path
    54          if: ${{ steps.get_version.outputs.version != '' }}
    55          run: |
    56            path='./pkg/project/project.go'
    57            if [[ ! -f $path ]] ; then
    58              path=''
    59            fi
    60            echo "path=\"$path\""
    61            echo "::set-output name=path::${path}"
    62    install_semver:
    63      name: Install semver
    64      runs-on: ubuntu-18.04
    65      env:
    66        BINARY: "semver"
    67        URL: "https://raw.githubusercontent.com/fsaintjacques/semver-tool/3.0.0/src/semver"
    68      steps:
    69        - name: Key
    70          id: key
    71          run: |
    72            cache_dir="/opt/cache"
    73            cache_key="install-${BINARY}-${URL}"
    74            echo "::set-output name=binary::${BINARY}"
    75            echo "::set-output name=cache_dir::${cache_dir}"
    76            echo "::set-output name=cache_key::${cache_key}"
    77            echo "::set-output name=url::${URL}"
    78        - name: Cache
    79          id: cache
    80          uses: actions/cache@v1
    81          with:
    82            key: "${{ steps.key.outputs.cache_key }}"
    83            path: "${{ steps.key.outputs.cache_dir }}"
    84        - name: Download
    85          if: ${{ steps.cache.outputs.cache-hit != 'true' }}
    86          run: |
    87            # TODO check hash
    88            binary="${{ steps.key.outputs.binary }}"
    89            cache_dir="${{ steps.key.outputs.cache_dir }}"
    90            url="${{ steps.key.outputs.url }}"
    91            mkdir $cache_dir
    92            curl -fsSLo $cache_dir/$binary $url
    93            chmod +x $cache_dir/$binary
    94        - name: Smoke test
    95          run: |
    96            ${{ steps.key.outputs.cache_dir }}/${{ steps.key.outputs.binary }} --version
    97        - name: Upload artifact
    98          uses: actions/upload-artifact@v1
    99          with:
   100            name: "${{ steps.key.outputs.binary }}"
   101            path: "${{ steps.key.outputs.cache_dir }}/${{ steps.key.outputs.binary }}"
   102    update_project_go:
   103      name: Update project.go
   104      runs-on: ubuntu-18.04
   105      if: ${{ needs.gather_facts.outputs.version != '' && needs.gather_facts.outputs.project_go_path != ''}}
   106      needs:
   107        - gather_facts
   108        - install_semver
   109      steps:
   110        - name: Download semver artifact to /opt/bin
   111          uses: actions/download-artifact@v2
   112          with:
   113            name: semver
   114            path: /opt/bin
   115        - name: Prepare /opt/bin
   116          run: |
   117            chmod +x /opt/bin/*
   118            echo "::add-path::/opt/bin"
   119        - name: Checkout code
   120          uses: actions/checkout@v2
   121        - name: Update project.go
   122          id: update_project_go
   123          run: |
   124            file="${{ needs.gather_facts.outputs.project_go_path }}"
   125            version="${{ needs.gather_facts.outputs.version }}"
   126            new_version="$(semver bump patch $version)-dev"
   127            echo "version=\"$version\" new_version=\"$new_version\""
   128            echo "::set-output name=new_version::${new_version}"
   129            sed -Ei "s/(version[[:space:]]*=[[:space:]]*)\"${version}\"/\1\"${new_version}\"/" $file
   130            if git diff --exit-code $file ; then
   131              echo "error: no changes in \"$file\"" >&2
   132              exit 1
   133            fi
   134        - name: Commit changes
   135          run: |
   136            file="${{ needs.gather_facts.outputs.project_go_path }}"
   137            git config --local user.email "action@github.com"
   138            git config --local user.name "GitHub Action"
   139            git add $file
   140            git commit -m "pkg/project: bump version to ${{ steps.update_project_go.outputs.new_version }}"
   141        - name: Push changes
   142          env:
   143            REMOTE_REPO: "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git"
   144          run: |
   145            git push "${REMOTE_REPO}" HEAD:${{ github.ref }}
   146    create_release:
   147      name: Create release
   148      runs-on: ubuntu-18.04
   149      needs:
   150        - gather_facts
   151      if: ${{ needs.gather_facts.outputs.version }}
   152      outputs:
   153        upload_url: ${{ steps.create_gh_release.outputs.upload_url }}
   154      steps:
   155        - name: Checkout code
   156          uses: actions/checkout@v2
   157          with:
   158            ref: ${{ github.sha }}
   159        - name: Ensure correct version in project.go
   160          if: ${{ needs.gather_facts.outputs.project_go_path != ''}}
   161          run: |
   162            file="${{ needs.gather_facts.outputs.project_go_path }}"
   163            version="${{ needs.gather_facts.outputs.version }}"
   164            grep -qE "version[[:space:]]*=[[:space:]]*\"$version\"" $file
   165        - name: Create tag
   166          run: |
   167            version="${{ needs.gather_facts.outputs.version }}"
   168            git config --local user.name "github-actions"
   169            git tag "v$version" ${{ github.sha }}
   170        - name: Push tag
   171          env:
   172            REMOTE_REPO: "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git"
   173          run: |
   174            git push "${REMOTE_REPO}" --tags
   175        - name: Create release
   176          id: create_gh_release
   177          uses: actions/create-release@v1
   178          env:
   179            GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
   180          with:
   181            tag_name: "v${{ needs.gather_facts.outputs.version }}"
   182            release_name: "v${{ needs.gather_facts.outputs.version }}"