github.com/hernad/nomad@v1.6.112/.github/workflows/release.yml (about)

     1  name: Release
     2  
     3  on:
     4    workflow_dispatch:
     5      inputs:
     6        version:
     7          description: 'The version being released'
     8          required: true
     9          type: string
    10        update-changelog:
    11          description: 'Update CHANGELOG'
    12          required: true
    13          type: boolean
    14          default: false
    15        notification-channel:
    16          description: 'Slack channel to use for notifications'
    17          required: false
    18          type: string
    19          default: 'CUYKT2A73'
    20  
    21  env:
    22    GO_TAGS: "release"
    23  
    24  jobs:
    25    prepare-release:
    26      runs-on: ${{ endsWith(github.repository, '-enterprise') && fromJSON('["self-hosted", "ondemand", "linux"]') || 'ubuntu-20.04' }}
    27      outputs:
    28        build-ref: ${{ steps.commit-change-push.outputs.build-ref }}
    29      steps:
    30        - name: Prevent running from main
    31          if: ${{ github.ref_name == 'main' }}
    32          run: |-
    33            echo "::error::Workflow not allowed to run from ${{ github.ref_name }}"
    34            exit 1
    35  
    36        - name: Print release info
    37          run: |-
    38            echo "::notice::Release v${{ github.event.inputs.version }} from branch ${{ github.ref_name }}"
    39  
    40        - name: Install semver CLI
    41          run: |-
    42            local_bin="${HOME}/.local/bin"
    43            mkdir -p "${local_bin}"
    44            curl -L --output "${local_bin}/semver" \
    45              https://raw.githubusercontent.com/fsaintjacques/semver-tool/3.3.0/src/semver
    46            chmod +x "${local_bin}/semver"
    47            echo "${local_bin}" >> "$GITHUB_PATH"
    48  
    49        - name: Validate release version
    50          run: |-
    51            if [ "$(semver validate ${{ github.event.inputs.version }})" == "invalid" ]; then
    52              echo "::error::Version ${{ github.event.inputs.version }} is invalid"
    53              exit 1
    54            fi
    55        - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
    56        - uses: ./.github/actions/vault-secrets
    57          with:
    58            paths: |-
    59              kv/data/github/hashicorp/nomad-enterprise/gha ELEVATED_GITHUB_TOKEN ;
    60        - name: Git config token
    61          if: endsWith(github.repository, '-enterprise')
    62          run: git config --global url.'https://${{ env.ELEVATED_GITHUB_TOKEN }}@github.com'.insteadOf 'https://github.com'
    63        - name: Git config user/name
    64          run: |-
    65            git config --global user.email "github-team-nomad-core@hashicorp.com"
    66            git config --global user.name "hc-github-team-nomad-core"
    67  
    68        - name: Determine Go version
    69          id: get-go-version
    70          # We use .go-version as our source of truth for current Go
    71          # version, because "goenv" can react to it automatically.
    72          run: |
    73            echo "Building with Go $(cat .go-version)"
    74            echo "go-version=$(cat .go-version)" >> "$GITHUB_OUTPUT"
    75  
    76        - name: Setup go
    77          uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0
    78          with:
    79            go-version: ${{ steps.get-go-version.outputs.go-version }}
    80  
    81        - name: Setup node and yarn
    82          uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
    83          with:
    84            node-version: "18"
    85            cache-dependency-path: "ui/yarn.lock"
    86  
    87        - name: Install Yarn
    88          run: |
    89            npm install -g yarn
    90  
    91        - name: Install dependencies
    92          run: |
    93            make deps
    94  
    95        - name: Update notification channel
    96          id: notification-channel
    97          if: ${{ github.event.inputs.notification-channel != '' }}
    98          run: |
    99            sed -i.bak -e 's|\(notification_channel * = *"\)[^"]*|\1${{ github.event.inputs.notification-channel }}|g' .release/ci.hcl
   100            rm -rf .release/ci.hcl.bak
   101            git diff --color=always .release/ci.hcl
   102  
   103        - name: Update version file
   104          run: |
   105            NOMAD_VERSION="${{ github.event.inputs.version }}"
   106            NOMAD_MAIN_VERSION=$(semver get release "$NOMAD_VERSION")
   107            NOMAD_PRERELEASE_VERSION=$(semver get prerel "$NOMAD_VERSION")
   108  
   109            echo "updating version to ${NOMAD_MAIN_VERSION}-${NOMAD_PRERELEASE_VERSION}"
   110  
   111            sed -i.bak -e "s|\(Version * = *\"\)[^\"]*|\1${NOMAD_MAIN_VERSION}|g" version/version.go
   112            sed -i.bak -e "s|\(VersionPrerelease * = *\"\)[^\"]*|\1${NOMAD_PRERELEASE_VERSION}|g" version/version.go
   113            rm -rf version/version.go.bak
   114            git diff --color=always version/version.go
   115  
   116        - name: Update changelog
   117          if: ${{ github.event.inputs.update-changelog == 'true' }}
   118          run: |
   119            echo "::group::Fetch all git repo"
   120            git fetch --unshallow
   121            echo "::endgroup::"
   122  
   123            echo -e "## ${{ github.event.inputs.version }} ($(date '+%B %d, %Y'))\n$(make changelog)\n\n$(cat CHANGELOG.md)" > CHANGELOG.md
   124            git diff --color=always CHANGELOG.md
   125  
   126        - name: Generate static assets
   127          id: generate-static-assets
   128          run: |
   129            make prerelease
   130  
   131        - name: Commit and push changes
   132          id: commit-change-push
   133          run: |
   134            git add -A .
   135            find . -name '*.generated.go' -not -path './vendor/*' -exec git add -f '{}' \;
   136            if ! git diff-index --quiet HEAD --; then
   137              git commit --message "Generate files for ${{ github.event.inputs.version }} release"
   138              git push origin "$(git rev-parse --abbrev-ref HEAD)"
   139              echo "committing generated files"
   140            else
   141              echo "no files were updated"
   142            fi
   143            echo "build-ref=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
   144  
   145        - name: Invoke build workflow
   146          id: invoke-build
   147          env:
   148            GH_TOKEN: ${{ env.ELEVATED_GITHUB_TOKEN || secrets.ELEVATED_GITHUB_TOKEN }}
   149          run: |
   150            gh workflow run build.yml --ref ${{ github.ref_name }} --field build-ref=${{ steps.commit-change-push.outputs.build-ref }} --field make-prerelease=false
   151  
   152        - name: Revert notification channel
   153          if: ${{ github.event.inputs.notification-channel != '' }}
   154          run: |
   155            git reset ${{ github.sha }} -- .release/ci.hcl
   156  
   157            # git reset will place the original file content in the staging area
   158            # and leave the changes since then unstaged, so call git restore to
   159            # discard these changes and use --cached to display the diff in the
   160            # staging area.
   161            git restore .release/ci.hcl
   162            git diff --cached --color=always .release/ci.hcl
   163  
   164        - name: Update version file
   165          run: |
   166            # Only bump the Version value if this is not a pre-release.
   167            # For final releases we want `nomad -version` to display the next
   168            # version to indicate that the current release is done.
   169            if [ -z "$(semver get prerel ${{ github.event.inputs.version }})" ]; then
   170              next_version=$(semver bump patch ${{ github.event.inputs.version }})
   171              sed -i.bak -e "s|\(Version * = *\"\)[^\"]*|\1${next_version}|g" version/version.go
   172            fi
   173            # Set the VersionPrerelease variable back to dev.
   174            sed -i.bak -e "s|\(VersionPrerelease * = *\"\)[^\"]*|\1dev|g" version/version.go
   175            rm -rf version/version.go.bak
   176            git diff --color=always version/version.go
   177  
   178        - name: Update LAST_RELEASE
   179          run: |
   180            # LAST_RELEASE is used to generate the new CHANGELOG entries, so it's
   181            # only updated for final releases.
   182            if [ -z "$(semver get prerel ${{ github.event.inputs.version }})" ]; then
   183              sed -i.bak -re "s|^(LAST_RELEASE\s+\?=\s+v).*$|\1${{ github.event.inputs.version }}|g" GNUmakefile
   184              rm -fr GNUmakefile.bak
   185              git diff --color=always GNUmakefile
   186            else
   187              echo "Version ${{ github.event.inputs.version }} is a prerelease, skipping update of LAST_RELEASE"
   188            fi
   189  
   190        - name: Remove generated files
   191          run: |
   192            # These generated files are only needed when building the final
   193            # binary and should be not be present in the repository afterwards.
   194            find . -name '*.generated.go' -print0 | xargs -0 git rm
   195            git status
   196  
   197        - name: Commit post-release changes
   198          run: |
   199            # Display staged and unstaged diffs, skipping deleted files to avoid
   200            # cluttering the output with the generated files.
   201            git diff --diff-filter=d --color=always HEAD
   202            git add -A .
   203            if ! git diff-index --quiet HEAD --; then
   204              git commit --message 'Prepare for next release'
   205              git push origin "$(git rev-parse --abbrev-ref HEAD)"
   206            else
   207              echo "no files were updated"
   208            fi
   209  
   210  permissions:
   211    contents: write
   212    id-token: write