|
1 | 1 | name: CD |
2 | 2 | on: |
3 | | - push: |
4 | | - branches: |
5 | | - - main |
6 | | - # When Pull Request is merged |
7 | | - # pull_request_target: |
8 | | - # types: [closed] |
| 3 | + pull_request: |
| 4 | + types: [closed] |
9 | 5 |
|
10 | 6 | jobs: |
11 | | - GetVersion: |
| 7 | + Pre-Check: |
| 8 | + if: | |
| 9 | + github.event.pull_request.merged && |
| 10 | + endsWith(github.event.pull_request.title, '/workflows/cd') && |
| 11 | + github.event.pull_request.user.login != 'polywrap-build-bot' |
12 | 12 | runs-on: ubuntu-latest |
13 | | - timeout-minutes: 60 |
14 | | - outputs: |
15 | | - version: ${{ env.RELEASE_VERSION }} |
16 | | - # if: | |
17 | | - # github.event.pull_request.user.login == 'polywrap-build-bot' && |
18 | | - # github.event.pull_request.merged == true |
19 | 13 | steps: |
20 | | - - name: Checkout code |
21 | | - uses: actions/checkout@v2 |
22 | | - # - name: Halt release if CI failed |
23 | | - # run: exit 1 |
24 | | - # if: ${{ github.event.workflow_run.conclusion == 'failure' }} |
| 14 | + - name: Checkout |
| 15 | + uses: actions/checkout@v3 |
| 16 | + with: |
| 17 | + ref: ${{github.event.pull_request.base.ref}} |
| 18 | + |
| 19 | + - name: Pull-Request Creator Is Publisher? |
| 20 | + run: | |
| 21 | + exists=$(echo $(grep -Fxcs ${CREATOR} .github/PUBLISHERS)) |
| 22 | + if [ "$exists" == "1" ] ; then |
| 23 | + echo IS_PUBLISHER=true >> $GITHUB_ENV |
| 24 | + else |
| 25 | + echo IS_PUBLISHER=false >> $GITHUB_ENV |
| 26 | + fi |
| 27 | + env: |
| 28 | + CREATOR: ${{github.event.pull_request.user.login}} |
| 29 | + |
| 30 | + - name: Creator Is Not Publisher... |
| 31 | + if: env.IS_PUBLISHER == 'false' |
| 32 | + uses: actions/github-script@0.8.0 |
| 33 | + with: |
| 34 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 35 | + script: | |
| 36 | + github.issues.createComment({ |
| 37 | + issue_number: context.issue.number, |
| 38 | + owner: context.repo.owner, |
| 39 | + repo: context.repo.repo, |
| 40 | + body: '${{github.event.pull_request.user.login}} is not a PUBLISHER. Please see the .github/PUBLISHERS file...' |
| 41 | + }) |
| 42 | +
|
25 | 43 | - name: Read VERSION into env.RELEASE_VERSION |
26 | 44 | run: echo RELEASE_VERSION=$(cat VERSION) >> $GITHUB_ENV |
27 | | - - name: Check if tag Exists |
| 45 | + |
| 46 | + - name: Tag Exists? |
28 | 47 | id: tag_check |
29 | 48 | shell: bash -ex {0} |
30 | 49 | run: | |
31 | 50 | GET_API_URL="https://api.github.com/repos/${{github.repository}}/git/ref/tags/${{env.RELEASE_VERSION}}" |
32 | 51 | http_status_code=$(curl -LI $GET_API_URL -o /dev/null -w '%{http_code}\n' -s \ |
33 | 52 | -H "Authorization: token ${GITHUB_TOKEN}") |
34 | 53 | if [ "$http_status_code" -ne "404" ] ; then |
35 | | - exit 1 |
| 54 | + echo TAG_EXISTS=true >> $GITHUB_ENV |
| 55 | + else |
| 56 | + echo TAG_EXISTS=false >> $GITHUB_ENV |
36 | 57 | fi |
37 | 58 | env: |
38 | 59 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
39 | 60 |
|
40 | | - Github-release: |
41 | | - name: Create Release |
42 | | - runs-on: ubuntu-latest |
43 | | - needs: |
44 | | - - GetVersion |
45 | | - steps: |
46 | | - - name: Checkout code |
47 | | - uses: actions/checkout@v2 |
48 | | - - name: print version with needs |
49 | | - run: echo ${{ needs.GetVersion.outputs.version }} |
50 | | - - id: changelog |
51 | | - name: "Generate release changelog" |
52 | | - uses: heinrichreimer/github-changelog-generator-action@v2.3 |
53 | | - with: |
54 | | - unreleasedOnly: true |
55 | | - unreleasedLabel: ${{ needs.GetVersion.outputs.version }} |
56 | | - token: ${{ secrets.GITHUB_TOKEN }} |
57 | | - continue-on-error: true |
58 | | - - name: Create Release |
59 | | - id: create_release |
60 | | - uses: actions/create-release@v1 |
61 | | - env: |
62 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 61 | + - name: Release Already Exists... |
| 62 | + if: env.TAG_EXISTS == 'true' |
| 63 | + uses: actions/github-script@0.8.0 |
63 | 64 | with: |
64 | | - tag_name: ${{ needs.GetVersion.outputs.version }} |
65 | | - release_name: Release ${{ needs.GetVersion.outputs.version }} |
66 | | - body: ${{ steps.changelog.outputs.changelog }} |
67 | | - draft: true |
68 | | - prerelease: false |
| 65 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 66 | + script: | |
| 67 | + github.issues.createComment({ |
| 68 | + issue_number: context.issue.number, |
| 69 | + owner: context.repo.owner, |
| 70 | + repo: context.repo.repo, |
| 71 | + body: '[Release Already Exists](https://api.github.com/repos/${{github.repository}}/git/ref/tags/${{env.RELEASE_VERSION}}) (`${{env.RELEASE_VERSION}}`)' |
| 72 | + }) |
69 | 73 |
|
70 | | - Dev-PR: |
71 | | - needs: |
72 | | - - GetVersion |
| 74 | + - name: Fail If Conditions Aren't Met... |
| 75 | + if: | |
| 76 | + env.IS_PUBLISHER != 'true' || |
| 77 | + env.TAG_EXISTS != 'false' |
| 78 | + run: exit 1 |
| 79 | + |
| 80 | + CD: |
| 81 | + needs: Pre-Check |
73 | 82 | runs-on: ubuntu-latest |
74 | 83 | steps: |
75 | 84 | - name: Checkout |
76 | 85 | uses: actions/checkout@v3 |
77 | 86 | with: |
78 | | - ref: dev |
79 | | - fetch-depth: 0 |
| 87 | + ref: ${{github.event.pull_request.base.ref}} |
| 88 | + |
| 89 | + - name: Set env.BUILD_BOT to Build Bot's Username |
| 90 | + run: echo BUILD_BOT=polywrap-build-bot >> $GITHUB_ENV |
| 91 | + |
| 92 | + - name: Read VERSION into env.RELEASE_VERSION |
| 93 | + run: echo RELEASE_VERSION=$(cat VERSION) >> $GITHUB_ENV |
| 94 | + |
| 95 | + - name: Building CD PR... |
| 96 | + uses: actions/github-script@0.8.0 |
| 97 | + with: |
| 98 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 99 | + script: | |
| 100 | + github.issues.createComment({ |
| 101 | + issue_number: context.issue.number, |
| 102 | + owner: context.repo.owner, |
| 103 | + repo: context.repo.repo, |
| 104 | + body: '[Building CD PR](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}) (`${{env.RELEASE_VERSION}}`)' |
| 105 | + }) |
| 106 | +
|
| 107 | + - name: Set up Python 3.10 |
| 108 | + uses: actions/setup-python@v4 |
| 109 | + with: |
| 110 | + python-version: "3.10" |
| 111 | + |
| 112 | + - name: Install poetry |
| 113 | + run: curl -sSL https://install.python-poetry.org | python3 - |
| 114 | + |
| 115 | + - name: Install tomlkit |
| 116 | + run: pip3 install tomlkit |
80 | 117 |
|
81 | 118 | - name: Set Git Identity |
82 | 119 | run: | |
83 | 120 | git config --global user.name '${{env.BUILD_BOT}}' |
84 | 121 | git config --global user.email '${{env.BUILD_BOT}}@users.noreply.github.com' |
85 | | - env: |
86 | | - GITHUB_TOKEN: ${{ secrets.POLYWRAP_BUILD_BOT_PAT }} |
87 | | - |
88 | | - - name: Merge main into dev |
89 | | - run: git merge origin/main |
90 | | - |
91 | | - - name: set env.RELEASE_FORKS to Release Forks' Organization |
92 | | - run: echo RELEASE_FORKS=polywrap-release-forks >> $GITHUB_ENV |
93 | 122 |
|
94 | | - - name: Set env.BUILD_BOT to Build Bot's Username |
95 | | - run: echo BUILD_BOT=polywrap-build-bot >> $GITHUB_ENV |
| 123 | + - name: Publish to PyPI |
| 124 | + run: python3 scripts/publish_packages.py |
| 125 | + env: |
| 126 | + POLYWRAP_BUILD_BOT_PYPI_PAT: ${{ secrets.POLYWRAP_BUILD_BOT_PYPI_PAT }} |
96 | 127 |
|
97 | | - - name: Read VERSION into env.RELEASE_VERSION |
98 | | - run: echo RELEASE_VERSION=$(cat VERSION) >> $GITHUB_ENV |
| 128 | + - name: Commit Changes |
| 129 | + run: | |
| 130 | + git add . |
| 131 | + git commit -m "chore: patch version to ${{env.RELEASE_VERSION}}" |
99 | 132 |
|
100 | | - # - name: Set up Python 3.10 |
101 | | - # uses: actions/setup-python@v4 |
102 | | - # with: |
103 | | - # python-version: "3.10" |
| 133 | + - name: Create Pull Request from dev to main |
| 134 | + id: cpr-cd |
| 135 | + uses: peter-evans/create-pull-request@v3 |
| 136 | + with: |
| 137 | + branch: cd/${{env.RELEASE_VERSION}} |
| 138 | + base: ${{github.event.pull_request.base.ref}} |
| 139 | + committer: GitHub <noreply@github.com> |
| 140 | + author: ${{env.BUILD_BOT}} <${{env.BUILD_BOT}}@users.noreply.github.com> |
| 141 | + commit-message: "chore: CD ${{env.RELEASE_VERSION}}" |
| 142 | + title: 'Python client CD (${{env.RELEASE_VERSION}})' |
| 143 | + body: | |
| 144 | + ## Python client CD (${{env.RELEASE_VERSION}}) |
104 | 145 |
|
105 | | - # - name: Install poetry |
106 | | - # run: curl -sSL https://install.python-poetry.org | python3 - |
| 146 | + - name: Release PR Created... |
| 147 | + uses: actions/github-script@0.8.0 |
| 148 | + with: |
| 149 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 150 | + script: | |
| 151 | + github.issues.createComment({ |
| 152 | + issue_number: context.issue.number, |
| 153 | + owner: context.repo.owner, |
| 154 | + repo: context.repo.repo, |
| 155 | + body: '**[Release PR Created](https://github.com/${{github.repository}}/pull/${{ steps.cpr-cd.outputs.pull-request-number }}) (`${{env.RELEASE_VERSION}}`)**' |
| 156 | + }) |
107 | 157 |
|
108 | | - # - name: Install tomlkit |
109 | | - # run: pip3 install tomlkit |
| 158 | + - name: Building POST CD PR... |
| 159 | + uses: actions/github-script@0.8.0 |
| 160 | + with: |
| 161 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 162 | + script: | |
| 163 | + github.issues.createComment({ |
| 164 | + issue_number: context.issue.number, |
| 165 | + owner: context.repo.owner, |
| 166 | + repo: context.repo.repo, |
| 167 | + body: '[Building POST CD PR](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}) (`${{env.RELEASE_VERSION}}`)' |
| 168 | + }) |
110 | 169 |
|
111 | | - # - name: Link Packages in dev branch |
112 | | - # run: python3 scripts/link_packages.py |
| 170 | + - name: Link Packages in dev branch |
| 171 | + run: python3 scripts/link_packages.py |
113 | 172 |
|
114 | | - - name: Create Pull Request |
115 | | - id: cpr |
| 173 | + - name: Create Pull Request from main to dev |
| 174 | + id: cpr-post-cd |
116 | 175 | uses: peter-evans/create-pull-request@v3 |
117 | 176 | with: |
118 | | - token: ${{ secrets.POLYWRAP_BUILD_BOT_PAT }} |
119 | | - push-to-fork: ${{env.RELEASE_FORKS}}/${{github.event.pull_request.base.repo.name}} |
120 | | - # branch: post-release/origin-${{env.RELEASE_VERSION}} |
121 | | - # base: origin/dev |
| 177 | + branch: cd/${{env.RELEASE_VERSION}} |
| 178 | + base: ${{github.event.pull_request.compare.ref}} |
122 | 179 | committer: GitHub <noreply@github.com> |
123 | 180 | author: ${{env.BUILD_BOT}} <${{env.BUILD_BOT}}@users.noreply.github.com> |
124 | | - commit-message: "DEV ${{env.RELEASE_VERSION}}" |
125 | | - title: 'Link packages in dev after (${{env.RELEASE_VERSION}})' |
| 181 | + commit-message: "chore: POST CD ${{env.RELEASE_VERSION}}" |
| 182 | + title: 'Python client POST CD (${{env.RELEASE_VERSION}})' |
126 | 183 | body: | |
127 | | - ## Link packages in dev after (${{env.RELEASE_VERSION}}) |
| 184 | + ## Python client POST CD (${{env.RELEASE_VERSION}}) |
| 185 | +
|
| 186 | + - name: POST CD PR Created... |
| 187 | + uses: actions/github-script@0.8.0 |
| 188 | + with: |
| 189 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 190 | + script: | |
| 191 | + github.issues.createComment({ |
| 192 | + issue_number: context.issue.number, |
| 193 | + owner: context.repo.owner, |
| 194 | + repo: context.repo.repo, |
| 195 | + body: '**[POST CD PR Created](https://github.com/${{github.repository}}/pull/${{ steps.cpr-post-cd.outputs.pull-request-number }}) (`${{env.RELEASE_VERSION}}`)**' |
| 196 | + }) |
| 197 | +
|
| 198 | + Github-release: |
| 199 | + name: Create Release |
| 200 | + runs-on: ubuntu-latest |
| 201 | + steps: |
| 202 | + - name: Checkout code |
| 203 | + uses: actions/checkout@v3 |
| 204 | + - name: Read VERSION into env.RELEASE_VERSION |
| 205 | + run: echo RELEASE_VERSION=$(cat VERSION) >> $GITHUB_ENV |
| 206 | + - id: changelog |
| 207 | + name: "Generate release changelog" |
| 208 | + uses: heinrichreimer/github-changelog-generator-action@v2.3 |
| 209 | + with: |
| 210 | + unreleasedOnly: true |
| 211 | + unreleasedLabel: ${{ env.RELEASE_VERSION }} |
| 212 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 213 | + continue-on-error: true |
| 214 | + - name: Create Release |
| 215 | + id: create_release |
| 216 | + uses: actions/create-release@v1 |
| 217 | + env: |
| 218 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 219 | + with: |
| 220 | + tag_name: ${{ env.RELEASE_VERSION }} |
| 221 | + release_name: Release ${{ env.RELEASE_VERSION }} |
| 222 | + body: ${{ steps.changelog.outputs.changelog }} |
| 223 | + draft: true |
| 224 | + prerelease: true |
0 commit comments