github.com/spinnaker/spin@v1.30.0/.github/workflows/release.yml (about)

     1  name: Release
     2  
     3  on:
     4    push:
     5      tags:
     6      - "v[0-9]+.[0-9]+.[0-9]+"
     7      - "v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+"
     8  
     9  env:
    10    CONTAINER_REGISTRY: us-docker.pkg.dev/spinnaker-community/docker
    11  
    12  jobs:
    13    lint:
    14      runs-on: ubuntu-latest
    15      steps:
    16      - name: Checkout code
    17        uses: actions/checkout@v3
    18      - uses: actions/setup-go@v4
    19        with:
    20          go-version-file: go.mod
    21          cache: false
    22      - name: Ensure code formatting and style is consistent
    23        uses: golangci/golangci-lint-action@v3
    24        with:
    25          version: v1.45.2
    26  
    27    release:
    28      runs-on: ubuntu-latest
    29      steps:
    30        - uses: actions/checkout@v3
    31          with:
    32            fetch-depth: 0
    33        - name: Assemble release info
    34          id: release_info
    35          env:
    36            GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    37          run: |
    38            . .github/workflows/release_info.sh ${{ github.event.repository.full_name }}
    39            echo CHANGELOG=$(echo -e "${CHANGELOG}") >> $GITHUB_OUTPUT
    40            echo SKIP_RELEASE="${SKIP_RELEASE}" >> $GITHUB_OUTPUT
    41            echo IS_CANDIDATE="${IS_CANDIDATE}" >> $GITHUB_OUTPUT
    42            echo RELEASE_VERSION="${RELEASE_VERSION}" >> $GITHUB_OUTPUT
    43        - name: Prepare build variables
    44          id: build_variables
    45          run: |
    46            echo REPO="${GITHUB_REPOSITORY##*/}" >> $GITHUB_OUTPUT
    47            echo VERSION="$(git rev-parse --short HEAD)-$(date --utc +'%Y%m%d%H%M')" >> $GITHUB_OUTPUT
    48  
    49        - uses: actions/setup-go@v4
    50          with:
    51            go-version-file: go.mod
    52            cache: false
    53        - uses: actions/cache@v3
    54          with:
    55            path: ~/go/pkg/mod
    56            key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
    57            restore-keys: |
    58              ${{ runner.os }}-go-
    59        - name: Fetch dependencies
    60          run: go get -d -v
    61        - name: Test
    62          run: go test -v ./...
    63        - name: Build binaries
    64          env:
    65            LDFLAGS: "-X github.com/spinnaker/spin/version.Version=${{ steps.release_info.outputs.RELEASE_VERSION }}"
    66          run: |
    67            GOARCH=amd64 GOOS=darwin go build -ldflags "${LDFLAGS}" -o dist/${{ steps.release_info.outputs.RELEASE_VERSION }}/darwin/amd64/spin .
    68            GOARCH=amd64 GOOS=linux go build -ldflags "${LDFLAGS}" -o dist/${{ steps.release_info.outputs.RELEASE_VERSION }}/linux/amd64/spin .
    69            GOARCH=arm64 GOOS=linux go build -ldflags "${LDFLAGS}" -o dist/${{ steps.release_info.outputs.RELEASE_VERSION }}/linux/arm64/spin .
    70            GOARCH=amd64 GOOS=windows go build -ldflags "${LDFLAGS}" -o dist/${{ steps.release_info.outputs.RELEASE_VERSION }}/windows/amd64/spin.exe .
    71            GOARCH=arm64 GOOS=darwin go build -ldflags "${LDFLAGS}" -o dist/${{ steps.release_info.outputs.RELEASE_VERSION }}/darwin/arm64/spin .
    72            dist/${{ steps.release_info.outputs.RELEASE_VERSION }}/linux/amd64/spin --version
    73        - name: Login to Google Cloud
    74          # Only run this on repositories in the 'spinnaker' org, not on forks.
    75          if: startsWith(github.repository, 'spinnaker/')
    76          uses: 'google-github-actions/auth@v1'
    77          # use service account flow defined at: https://github.com/google-github-actions/upload-cloud-storage#authenticating-via-service-account-key-json
    78          with:
    79            credentials_json: '${{ secrets.GAR_JSON_KEY }}'
    80        - name: Upload spin CLI binaries to GCS
    81          # Only run this on repositories in the 'spinnaker' org, not on forks.
    82          if: startsWith(github.repository, 'spinnaker/')
    83          uses: 'google-github-actions/upload-cloud-storage@v1'
    84          with:
    85            path: 'dist/'
    86            destination: 'spinnaker-artifacts/spin'
    87            parent: false
    88        - name: Determine latest spin CLI version and write to '(MAJOR.MINOR.x-)latest' files
    89          run: |
    90            gcs_latest="$(curl -s https://storage.googleapis.com/spinnaker-artifacts/spin/latest)"
    91            release=${{ steps.release_info.outputs.RELEASE_VERSION }}
    92            # SemVer sort 1.22.0 as later than 1.21.1
    93            latest="$(printf "%s\n%s" "${gcs_latest}" "${release}" | sort -V | tail -n1)"
    94  
    95            cat <<EOF
    96            gcs_latest: $gcs_latest
    97            release: $release
    98            latest: $latest
    99            EOF
   100  
   101            mkdir -p dist/latests
   102            echo "$latest" > dist/latests/latest
   103  
   104            # Bump latest version in MAJOR.MINOR
   105            major_minor="$(echo "$release" | cut -d '.' -f1-2)"
   106            echo "$release" > dist/latests/"${major_minor}.x-latest"
   107        - name: Upload latest version reference files
   108          # Only run this on repositories in the 'spinnaker' org, not on forks.
   109          if: startsWith(github.repository, 'spinnaker/')
   110          # See: https://spinnaker.io/docs/setup/other_config/spin/
   111          uses: 'google-github-actions/upload-cloud-storage@v1'
   112          with:
   113            path: 'dist/latests'
   114            destination: 'spinnaker-artifacts/spin'
   115            parent: false
   116  
   117        - name: Login to GAR
   118          # Only run this on repositories in the 'spinnaker' org, not on forks.
   119          if: startsWith(github.repository, 'spinnaker/')
   120          uses: docker/login-action@v2
   121          # use service account flow defined at: https://github.com/docker/login-action#service-account-based-authentication-1
   122          with:
   123            registry: us-docker.pkg.dev
   124            username: _json_key
   125            password: ${{ secrets.GAR_JSON_KEY }}
   126        - name: Build and publish container image
   127          # Only run this on repositories in the 'spinnaker' org, not on forks.
   128          if: startsWith(github.repository, 'spinnaker/')
   129          uses: docker/build-push-action@v4
   130          with:
   131            context: .
   132            file: Dockerfile
   133            push: true
   134            build-args: |
   135              "VERSION=${{ steps.release_info.outputs.RELEASE_VERSION }}"
   136            tags: |
   137              "${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.release_info.outputs.RELEASE_VERSION }}"
   138              "${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.release_info.outputs.RELEASE_VERSION }}-${{ steps.build_variables.outputs.VERSION }}"
   139  
   140        - name: Create release
   141          if: steps.release_info.outputs.SKIP_RELEASE == 'false'
   142          uses: softprops/action-gh-release@v1
   143          with:
   144            body: |
   145              ${{ steps.release_info.outputs.CHANGELOG }}
   146            draft: false
   147            name: ${{ github.event.repository.name }} ${{ github.ref_name }}
   148            prerelease: ${{ steps.release_info.outputs.IS_CANDIDATE }}
   149            tag_name: ${{ github.ref }}
   150            token: ${{ secrets.GITHUB_TOKEN }}