github.com/argoproj/argo-cd@v1.8.7/.github/workflows/release.yaml (about)

     1  name: Create ArgoCD release
     2  on:
     3    push:
     4      tags:
     5        - 'release-v*'
     6        - '!release-v1.5*'
     7        - '!release-v1.4*'
     8        - '!release-v1.3*'
     9        - '!release-v1.2*'
    10        - '!release-v1.1*'
    11        - '!release-v1.0*'
    12        - '!release-v0*'
    13  jobs:
    14    prepare-release:
    15      name: Perform automatic release on trigger ${{ github.ref }}
    16      runs-on: ubuntu-latest
    17      env:
    18        # The name of the tag as supplied by the GitHub event
    19        SOURCE_TAG: ${{ github.ref }}
    20        # The image namespace where Docker image will be published to
    21        IMAGE_NAMESPACE: argoproj
    22        # Whether to create & push image and release assets
    23        DRY_RUN: false
    24        # Whether a draft release should be created, instead of public one
    25        DRAFT_RELEASE: false
    26        # Whether to update homebrew with this release as well
    27        # Set RELEASE_HOMEBREW_TOKEN secret in repository for this to work - needs
    28        # access to public repositories
    29        UPDATE_HOMEBREW: false
    30        # Name of the GitHub user for Git config
    31        GIT_USERNAME: argo-bot
    32        # E-Mail of the GitHub user for Git config
    33        GIT_EMAIL: argoproj@gmail.com
    34      steps:
    35        - name: Checkout code
    36          uses: actions/checkout@v2
    37          with:
    38            fetch-depth: 0
    39            token: ${{ secrets.GITHUB_TOKEN }}
    40  
    41        - name: Check if the published tag is well formed and setup vars
    42          run: |
    43            set -xue
    44            # Target version must match major.minor.patch and optional -rcX suffix
    45            # where X must be a number.
    46            TARGET_VERSION=${SOURCE_TAG#*release-v}
    47            if ! echo "${TARGET_VERSION}" | egrep '^[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)*$'; then
    48              echo "::error::Target version '${TARGET_VERSION}' is malformed, refusing to continue." >&2
    49              exit 1
    50            fi
    51  
    52            # Target branch is the release branch we're going to operate on
    53            # Its name is 'release-<major>.<minor>'
    54            TARGET_BRANCH="release-${TARGET_VERSION%\.[0-9]*}"
    55  
    56            # The release tag is the source tag, minus the release- prefix
    57            RELEASE_TAG="${SOURCE_TAG#*release-}"
    58  
    59            # Whether this is a pre-release (indicated by -rc suffix)
    60            PRE_RELEASE=false
    61            if echo "${RELEASE_TAG}" | egrep -- '-rc[0-9]+$'; then
    62              PRE_RELEASE=true
    63            fi
    64  
    65            # We must not have a release trigger within the same release branch,
    66            # because that means a release for this branch is already running.
    67            if git tag -l | grep "release-v${TARGET_VERSION%\.[0-9]*}" | grep -v "release-v${TARGET_VERSION}"; then
    68              echo "::error::Another release for branch ${TARGET_BRANCH} is currently in progress."
    69              exit 1
    70            fi
    71  
    72            # Ensure that release do not yet exist
    73            if git rev-parse ${RELEASE_TAG}; then
    74              echo "::error::Release tag ${RELEASE_TAG} already exists in repository. Refusing to continue."
    75              exit 1
    76            fi
    77  
    78            # Make the variables available in follow-up steps
    79            echo "TARGET_VERSION=${TARGET_VERSION}" >> $GITHUB_ENV
    80            echo "TARGET_BRANCH=${TARGET_BRANCH}" >> $GITHUB_ENV
    81            echo "RELEASE_TAG=${RELEASE_TAG}" >> $GITHUB_ENV
    82            echo "PRE_RELEASE=${PRE_RELEASE}" >> $GITHUB_ENV
    83  
    84        - name: Check if our release tag has a correct annotation
    85          run: |
    86            set -ue
    87            # Fetch all tag information as well
    88            git fetch --prune --tags --force
    89  
    90            echo "=========== BEGIN COMMIT MESSAGE ============="
    91            git show ${SOURCE_TAG}
    92            echo "============ END COMMIT MESSAGE =============="
    93            
    94            # Quite dirty hack to get the release notes from the annotated tag
    95            # into a temporary file.
    96            RELEASE_NOTES=$(mktemp -p /tmp release-notes.XXXXXX)
    97  
    98            prefix=true
    99            begin=false
   100            git show ${SOURCE_TAG} | while read line; do
   101              # Whatever is in commit history for the tag, we only want that
   102              # annotation from our tag. We discard everything else.
   103              if test "$begin" = "false"; then
   104                if echo "$line" | grep -q "tag ${SOURCE_TAG#refs/tags/}"; then begin="true"; fi
   105                continue
   106              fi
   107              if test "$prefix" = "true"; then
   108                    if test -z "$line"; then prefix=false; fi
   109              else
   110                    if echo "$line" | egrep -q '^commit [0-9a-f]+'; then
   111                            break
   112                    fi
   113                    echo "$line" >> ${RELEASE_NOTES}
   114              fi
   115            done
   116  
   117            # For debug purposes
   118            echo "============BEGIN RELEASE NOTES================="
   119            cat ${RELEASE_NOTES}
   120            echo "=============END RELEASE NOTES=================="
   121  
   122            # Too short release notes are suspicious. We need at least 100 bytes.
   123            relNoteLen=$(stat -c '%s' $RELEASE_NOTES)
   124            if test $relNoteLen -lt 100; then
   125              echo "::error::No release notes provided in tag annotation (or tag is not annotated)"
   126              exit 1
   127            fi
   128  
   129            # Check for magic string '## Quick Start' in head of release notes
   130            if ! head -2 ${RELEASE_NOTES} | grep -iq '## Quick Start'; then
   131              echo "::error::Release notes seem invalid, quick start section not found."
   132              exit 1
   133            fi
   134  
   135            # We store path to temporary release notes file for later reading, we
   136            # need it when creating release.
   137            echo "RELEASE_NOTES=${RELEASE_NOTES}" >> $GITHUB_ENV
   138  
   139        - name: Setup Golang
   140          uses: actions/setup-go@v1
   141          with:
   142            go-version: '1.14.12'
   143  
   144        - name: Setup Git author information
   145          run: |
   146            set -ue
   147            git config --global user.email "${GIT_EMAIL}"
   148            git config --global user.name "${GIT_USERNAME}"
   149  
   150        - name: Checkout corresponding release branch
   151          run: |
   152            set -ue
   153            echo "Switching to release branch '${TARGET_BRANCH}'"
   154            if ! git checkout ${TARGET_BRANCH}; then
   155              echo "::error::Checking out release branch '${TARGET_BRANCH}' for target version '${TARGET_VERSION}' (tagged '${RELEASE_TAG}') failed. Does it exist in repo?"
   156              exit 1
   157            fi
   158  
   159        - name: Create VERSION information
   160          run: |
   161            set -ue
   162            echo "Bumping version from $(cat VERSION) to ${TARGET_VERSION}"
   163            echo "${TARGET_VERSION}" > VERSION
   164            git commit -m "Bump version to ${TARGET_VERSION}" VERSION
   165  
   166        - name: Generate new set of manifests
   167          run: |
   168            set -ue
   169            make install-codegen-tools-local
   170            helm2 init --client-only
   171            make manifests-local VERSION=${TARGET_VERSION}
   172            git diff
   173            git commit manifests/ -m "Bump version to ${TARGET_VERSION}"
   174  
   175        - name: Create the release tag
   176          run: |
   177            set -ue
   178            echo "Creating release ${RELEASE_TAG}"
   179            git tag ${RELEASE_TAG}
   180  
   181        - name: Build Docker image for release
   182          run: |
   183            set -ue
   184            git clean -fd
   185            mkdir -p dist/
   186            make image IMAGE_TAG="${TARGET_VERSION}" DOCKER_PUSH=false
   187            make release-cli
   188            chmod +x ./dist/argocd-linux-amd64
   189            ./dist/argocd-linux-amd64 version --client
   190          if: ${{ env.DRY_RUN != 'true' }}
   191  
   192        - name: Push docker image to repository
   193          env:
   194            DOCKER_USERNAME: ${{ secrets.RELEASE_DOCKERHUB_USERNAME }}
   195            DOCKER_TOKEN: ${{ secrets.RELEASE_DOCKERHUB_TOKEN }}
   196          run: |
   197            set -ue
   198            docker login --username "${DOCKER_USERNAME}" --password "${DOCKER_TOKEN}"
   199            docker push ${IMAGE_NAMESPACE}/argocd:v${TARGET_VERSION}
   200          if: ${{ env.DRY_RUN != 'true' }}
   201  
   202        - name: Read release notes file
   203          id: release-notes
   204          uses: juliangruber/read-file-action@v1
   205          with: 
   206            path: ${{ env.RELEASE_NOTES }}
   207  
   208        - name: Push changes to release branch
   209          run: |
   210            set -ue
   211            git push origin ${TARGET_BRANCH}
   212            git push origin ${RELEASE_TAG}
   213  
   214        - name: Create GitHub release
   215          uses: actions/create-release@v1
   216          env:
   217            GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
   218          id: create_release
   219          with:
   220            tag_name: ${{ env.RELEASE_TAG }}
   221            release_name: ${{ env.RELEASE_TAG }}
   222            draft: ${{ env.DRAFT_RELEASE }}
   223            prerelease: ${{ env.PRE_RELEASE }}
   224            body: ${{ steps.release-notes.outputs.content }}
   225  
   226        - name: Upload argocd-linux-amd64 binary to release assets
   227          uses: actions/upload-release-asset@v1
   228          env:
   229            GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
   230          with:
   231            upload_url: ${{ steps.create_release.outputs.upload_url }}
   232            asset_path: ./dist/argocd-linux-amd64
   233            asset_name: argocd-linux-amd64
   234            asset_content_type: application/octet-stream
   235          if: ${{ env.DRY_RUN != 'true' }}
   236  
   237        - name: Upload argocd-darwin-amd64 binary to release assets
   238          uses: actions/upload-release-asset@v1
   239          env:
   240            GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
   241          with:
   242            upload_url: ${{ steps.create_release.outputs.upload_url }}
   243            asset_path: ./dist/argocd-darwin-amd64
   244            asset_name: argocd-darwin-amd64
   245            asset_content_type: application/octet-stream
   246          if: ${{ env.DRY_RUN != 'true' }}
   247  
   248        - name: Upload argocd-windows-amd64 binary to release assets
   249          uses: actions/upload-release-asset@v1
   250          env:
   251            GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
   252          with:
   253            upload_url: ${{ steps.create_release.outputs.upload_url }}
   254            asset_path: ./dist/argocd-windows-amd64.exe
   255            asset_name: argocd-windows-amd64.exe
   256            asset_content_type: application/octet-stream
   257          if: ${{ env.DRY_RUN != 'true' }}
   258  
   259        - name: Update homebrew formula
   260          env:
   261            HOMEBREW_TOKEN: ${{ secrets.RELEASE_HOMEBREW_TOKEN }}
   262          uses: dawidd6/action-homebrew-bump-formula@v3
   263          with:
   264            token: ${{env.HOMEBREW_TOKEN}}
   265            formula: argocd
   266          if: ${{ env.HOMEBREW_TOKEN != '' && env.UPDATE_HOMEBREW == 'true' && env.PRE_RELEASE != 'true' }}
   267  
   268        - name: Delete original request tag from repository
   269          run: |
   270            set -ue
   271            git push --delete origin ${SOURCE_TAG}
   272          if: ${{ always() }}