11name : Preview Release
22
3+ permissions :
4+ contents : read
5+ pull-requests : write
6+ issues : write
7+ statuses : write
8+
39on :
410 issue_comment :
5- types :
6- - created
11+ types : [created]
712
813jobs :
914 release :
10- if : startsWith(github.event.comment.body, '[preview_deployment]')
15+ if : github.event.issue.pull_request && startsWith(github.event.comment.body, '[preview_deployment]')
1116 runs-on : ubuntu-latest
1217
1318 timeout-minutes : 15
@@ -20,33 +25,39 @@ jobs:
2025 with :
2126 app_id : ${{ secrets.CT_CHANGESETS_APP_ID }}
2227 private_key : ${{ secrets.CT_CHANGESETS_APP_PEM }}
28+
29+ - name : Get branch of PR
30+ uses : xt0rted/pull-request-comment-branch@v1
31+ id : comment-branch
32+
33+ - name : Set latest commit status as pending
34+ uses : myrotvorets/set-commit-status-action@master
35+ with :
36+ sha : ${{ steps.comment-branch.outputs.head_sha }}
37+ token : ${{ steps.generate_github_token.outputs.token }}
38+ status : pending
2339
24- - name : Checkout code
40+ - name : Checkout PR branch
2541 uses : actions/checkout@v2
2642 with :
43+ ref : ${{ steps.comment-branch.outputs.head_ref }}
2744 token : ${{ steps.generate_github_token.outputs.token }}
28-
29- - name : Fetch PR branch
30- run : |
31- git fetch origin ${{ github.event.issue.pull_request.head.ref }}
32- git checkout ${{ github.event.issue.pull_request.head.ref }}
45+
46+ - name : Setup Node.js
47+ uses : actions/setup-node@v3
48+ with :
49+ node-version : 18
50+ registry-url : https://registry.npmjs.org/
51+ scope : " @commercetools"
52+ env :
53+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
3354
3455 - name : Installing dependencies and building packages
3556 uses : ./.github/actions/ci
3657
37- - name : Creating .npmrc
38- run : |
39- cat << EOF > "$HOME/.npmrc"
40- provenance=true
41- 42- //registry.npmjs.org/:_authToken=$NPM_TOKEN
43- EOF
44- env :
45- NPM_TOKEN : ${{ secrets.NPM_TOKEN }}
46-
4758 - name : Configure prerelease mode
4859 run : |
49- git checkout ${{ github .head_ref }}
60+ git checkout ${{ steps.comment-branch.outputs .head_ref }}
5061 pnpm changeset pre enter preview
5162 env :
5263 GITHUB_TOKEN : ${{ steps.generate_github_token.outputs.token }}
6576 pnpm changeset pre exit
6677 env :
6778 GITHUB_TOKEN : ${{ steps.generate_github_token.outputs.token }}
79+ - name : Post workflow result on PR as a comment
80+ uses : actions/github-script@v6
81+ if : always()
82+ with :
83+ script : |
84+ const name = '${{ github.workflow }}';
85+ const url = '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}';
86+ const success = '${{ job.status }}' === 'success';
87+ const body = `Release workflow ${success ? 'succeeded ✅' : 'failed ❌'}\nSee details: ${url}`;
6888
89+ await github.rest.issues.createComment({
90+ issue_number: context.issue.number,
91+ owner: context.repo.owner,
92+ repo: context.repo.repo,
93+ body: body
94+ });
95+ - name : Set latest commit status as ${{ job.status }}
96+ uses : myrotvorets/set-commit-status-action@master
97+ if : always()
98+ with :
99+ sha : ${{ steps.comment-branch.outputs.head_sha }}
100+ token : ${{ steps.generate_github_token.outputs.token }}
101+ status : ${{ job.status }}
0 commit comments