|
| 1 | +# Copyright 2020 The Knative Authors. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +# This file is automagically synced here from github.com/knative-sandbox/.github |
| 16 | +# repo by knobots: https://github.com/knative-sandbox/knobots and will be overwritten. |
| 17 | + |
| 18 | +name: 'Releasability' |
| 19 | + |
| 20 | +on: |
| 21 | + schedule: |
| 22 | + - cron: '0 1 * * 1-5' # 6am Pacific, weekdays. |
| 23 | + |
| 24 | + workflow_dispatch: # Manual trigger. |
| 25 | + inputs: |
| 26 | + releaseFamily: |
| 27 | + description: 'Release? (vX.Y)' |
| 28 | + slackChannel: |
| 29 | + description: 'Slack Channel? (release-#)' |
| 30 | + |
| 31 | +jobs: |
| 32 | + releasability: |
| 33 | + name: Releasability |
| 34 | + runs-on: 'ubuntu-latest' |
| 35 | + |
| 36 | + env: |
| 37 | + ######################################### |
| 38 | + # Update this section each release. # |
| 39 | + RELEASE: 'v0.24' |
| 40 | + SLACK_CHANNEL: 'release-24' |
| 41 | + ######################################### |
| 42 | + |
| 43 | + steps: |
| 44 | + - name: Defaults |
| 45 | + run: | |
| 46 | + # If manual trigger sent releaseFamily and slackChannel, then override them |
| 47 | + if [[ "${{ github.event.inputs.releaseFamily }}" != "" ]]; then |
| 48 | + echo "RELEASE=${{ github.event.inputs.releaseFamily }}" >> $GITHUB_ENV |
| 49 | + fi |
| 50 | + if [[ "${{ github.event.inputs.slackChannel }}" != "" ]]; then |
| 51 | + echo "SLACK_CHANNEL=${{ github.event.inputs.slackChannel }}" >> $GITHUB_ENV |
| 52 | + fi |
| 53 | + if [[ "${{ secrets.SLACK_WEBHOOK }}" != "" ]]; then |
| 54 | + echo "SLACK_WEBHOOK=exists" >> $GITHUB_ENV |
| 55 | + fi |
| 56 | +
|
| 57 | + - name: Set up Go 1.16.x |
| 58 | + uses: actions/setup-go@v2 |
| 59 | + with: |
| 60 | + go-version: 1.16.x |
| 61 | + |
| 62 | + - name: Install Dependencies |
| 63 | + run: GO111MODULE=on go get knative.dev/test-infra/buoy@main |
| 64 | + |
| 65 | + - name: Check out code |
| 66 | + uses: actions/checkout@v2 |
| 67 | + |
| 68 | + - name: Exists |
| 69 | + id: exists |
| 70 | + run: | |
| 71 | + EXISTS=0 |
| 72 | + buoy exists go.mod --release ${RELEASE} --verbose || EXISTS=$? |
| 73 | + if [[ "$EXISTS" -eq "0" ]]; then |
| 74 | + EXISTS=true |
| 75 | + else |
| 76 | + EXISTS=false |
| 77 | + fi |
| 78 | + echo ::set-output name=release-branch::${EXISTS} |
| 79 | +
|
| 80 | + - name: Check |
| 81 | + if: steps.exists.outputs.release-branch == 'false' |
| 82 | + run: | |
| 83 | + # The following pushes the stdout of buoy into $CHECK_MESSAGE |
| 84 | + CHECK=0 |
| 85 | + echo 'CHECK_MESSAGE<<EOF' >> $GITHUB_ENV |
| 86 | + buoy check go.mod --release ${RELEASE} --domain knative.dev --verbose >> $GITHUB_ENV 2>&1 || CHECK=$? |
| 87 | + echo 'EOF' >> $GITHUB_ENV |
| 88 | +
|
| 89 | + # We just captured the return code of the buoy call, test it to see |
| 90 | + # if we should continue validating. The next steps short circuit if |
| 91 | + # we already know we are not ready for a release. |
| 92 | + if [[ "$CHECK" -eq "0" ]]; then |
| 93 | + echo 'current=true' >> $GITHUB_ENV |
| 94 | + else |
| 95 | + echo 'current=false' >> $GITHUB_ENV |
| 96 | + fi |
| 97 | +
|
| 98 | + - name: Upgrade |
| 99 | + if: steps.exists.outputs.release-branch == 'false' && env.current == 'true' |
| 100 | + run: | |
| 101 | + # if update deps returns un-successful, then mark current to false. |
| 102 | + if ! ./hack/update-deps.sh --release ${RELEASE} --upgrade; then |
| 103 | + echo "VERIFY_MESSAGE=Unable to update deps for ${{ github.repository }}." >> $GITHUB_ENV |
| 104 | + echo 'current=false' >> $GITHUB_ENV |
| 105 | + fi |
| 106 | +
|
| 107 | + - name: Verify |
| 108 | + if: steps.exists.outputs.release-branch == 'false' && env.current == 'true' |
| 109 | + run: | |
| 110 | + # If we don't run `git status` before the "git diff-index" it seems |
| 111 | + # to list every file that's been touched by codegen. |
| 112 | + git status |
| 113 | +
|
| 114 | + CHANGED="$(git diff-index --name-only HEAD --)" |
| 115 | +
|
| 116 | + # If we see no changes after the upgrade, then we are up to date. |
| 117 | + if [[ "$CHANGED" == "" ]]; then |
| 118 | + echo "VERIFY_MESSAGE=${{ github.repository }} up to date." >> $GITHUB_ENV |
| 119 | + else |
| 120 | + echo "VERIFY_MESSAGE=${{ github.repository }} is out of date." >> $GITHUB_ENV |
| 121 | + echo "The following files are changed: $CHANGED" |
| 122 | + echo 'current=false' >> $GITHUB_ENV |
| 123 | + fi |
| 124 | +
|
| 125 | + - name: Status GO |
| 126 | + if: steps.exists.outputs.release-branch == 'false' && env.current == 'true' |
| 127 | + run: | |
| 128 | + echo 'SLACK_COLOR=#098e00' >> $GITHUB_ENV |
| 129 | + echo 'SLACK_TITLE=Releasability for ${{ github.repository }} @ ${{ env.RELEASE }} is GO!' >> $GITHUB_ENV |
| 130 | +
|
| 131 | + - name: Status NO-GO |
| 132 | + if: steps.exists.outputs.release-branch == 'false' && env.current == 'false' |
| 133 | + run: | |
| 134 | + echo 'SLACK_COLOR=#8E1600' >> $GITHUB_ENV |
| 135 | + echo 'SLACK_TITLE=Releasability for ${{ github.repository }} @ ${{ env.RELEASE }} is NO-GO!' >> $GITHUB_ENV |
| 136 | +
|
| 137 | + - name: Post status to Slack |
| 138 | + # Note: using env.SLACK_WEBHOOK here because secrets are not allowed in the if block. |
| 139 | + if: env.SLACK_WEBHOOK != '' && steps.exists.outputs.release-branch == 'false' |
| 140 | + |
| 141 | + env: |
| 142 | + SLACK_ICON: http://github.com/knative.png?size=48 |
| 143 | + SLACK_USERNAME: github-actions |
| 144 | + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} |
| 145 | + MSG_MINIMAL: 'true' |
| 146 | + SLACK_MESSAGE: | |
| 147 | + ${{ env.CHECK_MESSAGE }} |
| 148 | + ${{ env.VERIFY_MESSAGE }} |
| 149 | + For detailed logs: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 150 | +
|
| 151 | + - name: Fail if NO-GO |
| 152 | + if: steps.exists.outputs.release-branch == 'false' && env.current == 'false' |
| 153 | + run: | |
| 154 | + # When we have figured out that things are NO-GO, we intentionally fail the job |
| 155 | + # so that the status badge shows up red and we can use the badges to create a |
| 156 | + # releasability dashboard for all of the repos. |
| 157 | + exit 1 |
0 commit comments