|
| 1 | +name: "[Dispatch] Release" |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + tag: |
| 7 | + description: '`vx.y.z` 형태로 버전을 입력해주세요.' |
| 8 | + required: true |
| 9 | + default: v1.0.0 |
| 10 | + |
| 11 | +env: |
| 12 | + TAG: ${{ github.event.inputs.tag }} |
| 13 | + SLACK_WEBHOOK_URL: ${{secrets.SLACK_WEBHOOK_URL}} |
| 14 | + |
| 15 | +jobs: |
| 16 | + owner_check: |
| 17 | + if: github.repository_owner == 'cloudforet-io' |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - run: echo ${{ github.repository_owner }} |
| 21 | + condition_check: |
| 22 | + if: github.repository_owner == 'cloudforet-io' |
| 23 | + runs-on: ubuntu-latest |
| 24 | + needs: owner_check |
| 25 | + steps: |
| 26 | + - name: check version format |
| 27 | + run: | |
| 28 | + if [[ !(${{ env.TAG }} =~ ^v[0-9]\.[0-9]?[0-9]\.[0-9]?[0-9]$) ]]; |
| 29 | + then |
| 30 | + echo "You entered an incorrect version format." |
| 31 | + exit 1 |
| 32 | + fi |
| 33 | + - name: debugging |
| 34 | + run: | |
| 35 | + echo "major=$(echo ${{env.TAG}} | cut -c 2- | cut -d'.' -f1)" |
| 36 | + echo "minor=$(echo ${{env.TAG}} | cut -c 2- | cut -d'.' -f2)" |
| 37 | + echo "patch=$(echo ${{env.TAG}} | cut -c 2- | cut -d'.' -f3)" |
| 38 | + - name: notice when job fails |
| 39 | + if: failure() |
| 40 | + uses: 8398a7/action-slack@v3.2.0 |
| 41 | + with: |
| 42 | + status: ${{job.status}} |
| 43 | + fields: repo,workflow,job |
| 44 | + author_name: Github Action Slack |
| 45 | + |
| 46 | + update_master_branch_version_file: |
| 47 | + needs: condition_check |
| 48 | + runs-on: ubuntu-latest |
| 49 | + steps: |
| 50 | + - uses: actions/checkout@v2 |
| 51 | + with: |
| 52 | + token: ${{ secrets.PAT_TOKEN }} |
| 53 | + - name: get versions |
| 54 | + run: | |
| 55 | + echo "old_version=$(cat src/VERSION)" >> $GITHUB_ENV |
| 56 | + echo "old_major=$(cat src/VERSION | cut -c 2- | cut -d'.' -f1)" >> $GITHUB_ENV |
| 57 | + echo "old_minor=$(cat src/VERSION | cut -c 2- | cut -d'.' -f2)" >> $GITHUB_ENV |
| 58 | + echo "old_patch=$(cat src/VERSION | cut -c 2- | cut -d'.' -f3)" >> $GITHUB_ENV |
| 59 | + echo "new_major=$(echo ${{ env.TAG }} | cut -c 2- | cut -d'.' -f1)" >> $GITHUB_ENV |
| 60 | + echo "new_minor=$(echo ${{ env.TAG }} | cut -c 2- | cut -d'.' -f2)" >> $GITHUB_ENV |
| 61 | + echo "new_patch=$(echo ${{ env.TAG }} | cut -c 2- | cut -d'.' -f3)" >> $GITHUB_ENV |
| 62 | + - name: compare versions |
| 63 | + run: | |
| 64 | + if [ ${{ env.TAG }} -eq ${{ env.old_version }} ]; |
| 65 | + then |
| 66 | + echo "New version cannot be the same as old version." |
| 67 | + exit 1 |
| 68 | + elif [ ${{ env.old_major }} -gt ${{ env.new_major }} ]; |
| 69 | + then |
| 70 | + echo "Old major version cannot be greater than new major version" |
| 71 | + exit 1 |
| 72 | + elif [ ${{ env.old_minor }} -gt ${{ env.new_minor }} ]; |
| 73 | + then |
| 74 | + echo "Old minor version cannot be greater than new minor version" |
| 75 | + exit 1 |
| 76 | + elif [ ${{ env.old_minor }} -eq ${{ env.new_minor }} ]; |
| 77 | + then |
| 78 | + if [ ${{ env.old_patch }} -ge ${{ env.new_patch }} ]; |
| 79 | + then |
| 80 | + echo "Old patch version cannot be greater than new patch version in same minor version" |
| 81 | + exit 1 |
| 82 | + else |
| 83 | + echo "version=${{ env.TAG }}" |
| 84 | + fi |
| 85 | + else |
| 86 | + echo "version=${{ env.TAG }}" |
| 87 | + fi |
| 88 | + - name: update version file |
| 89 | + run: | |
| 90 | + echo ${{ env.TAG }} > src/VERSION |
| 91 | + git config user.name github-actions |
| 92 | + git config user.email github-actions@github.com |
| 93 | + git add . |
| 94 | + git commit -m "[CI/CD] release version ${{ env.TAG }}" |
| 95 | + - name: push changes |
| 96 | + uses: ad-m/github-push-action@master |
| 97 | + with: |
| 98 | + github_token: ${{ secrets.PAT_TOKEN }} |
| 99 | + branch: master |
| 100 | + - name: notice when job fails |
| 101 | + if: failure() |
| 102 | + uses: 8398a7/action-slack@v3.2.0 |
| 103 | + with: |
| 104 | + status: ${{job.status}} |
| 105 | + fields: repo,workflow,job |
| 106 | + author_name: Github Action Slack |
| 107 | + |
| 108 | + tagging: |
| 109 | + needs: update_master_branch_version_file |
| 110 | + runs-on: ubuntu-latest |
| 111 | + steps: |
| 112 | + - uses: actions/checkout@v2 |
| 113 | + with: |
| 114 | + token: ${{ secrets.PAT_TOKEN }} |
| 115 | + - name: git tagging |
| 116 | + run: | |
| 117 | + git tag ${{ env.TAG }} |
| 118 | + git push origin "${{ env.TAG }}" |
| 119 | + - name: notice when job fails |
| 120 | + if: failure() |
| 121 | + uses: 8398a7/action-slack@v3.2.0 |
| 122 | + with: |
| 123 | + status: ${{job.status}} |
| 124 | + fields: repo,workflow,job |
| 125 | + author_name: Github Action Slack |
| 126 | + |
| 127 | + docker: |
| 128 | + needs: tagging |
| 129 | + runs-on: ubuntu-latest |
| 130 | + steps: |
| 131 | + - uses: actions/checkout@v2 |
| 132 | + - name: get version |
| 133 | + run: | |
| 134 | + echo "VERSION=$(echo ${{ env.TAG }} | cut -c 2-)" >> $GITHUB_ENV |
| 135 | + - name: get service name |
| 136 | + run: | |
| 137 | + echo "SERVICE=$(echo ${{ github.repository }} | cut -d '/' -f2)" >> $GITHUB_ENV |
| 138 | + - name: Build and push to pyengine |
| 139 | + uses: docker/build-push-action@v1 |
| 140 | + with: |
| 141 | + path: . |
| 142 | + repository: pyengine/${{ env.SERVICE }} |
| 143 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 144 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 145 | + tags: ${{ env.VERSION }} |
| 146 | + - name: Build and push to spaceone |
| 147 | + uses: docker/build-push-action@v1 |
| 148 | + with: |
| 149 | + path: . |
| 150 | + repository: spaceone/${{ env.SERVICE }} |
| 151 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 152 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 153 | + tags: ${{ env.VERSION }} |
| 154 | + - name: Notice when job fails |
| 155 | + if: failure() |
| 156 | + uses: 8398a7/action-slack@v3.2.0 |
| 157 | + with: |
| 158 | + status: ${{job.status}} |
| 159 | + fields: repo,workflow,job |
| 160 | + author_name: Github Action Slack |
| 161 | + |
| 162 | + notification: |
| 163 | + needs: docker |
| 164 | + runs-on: ubuntu-latest |
| 165 | + steps: |
| 166 | + - name: Slack |
| 167 | + if: always() |
| 168 | + uses: 8398a7/action-slack@v3.2.0 |
| 169 | + with: |
| 170 | + status: ${{job.status}} |
| 171 | + fields: repo,message,commit,author,action,ref,workflow,job |
| 172 | + author_name: Github Action Slack |
0 commit comments