-
Notifications
You must be signed in to change notification settings - Fork 30
105 lines (91 loc) · 3.39 KB
/
preview-release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
name: Preview Release
permissions:
contents: read
pull-requests: write
issues: write
statuses: write
# This is temporary for testing purposes
on: [push]
# on:
# issue_comment:
# types: [created]
jobs:
release:
# if: github.event.issue.pull_request && startsWith(github.event.comment.body, '[preview_deployment]')
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
# Get GitHub token via the CT Changesets App
- name: Generate GitHub token (via CT Changesets App)
id: generate_github_token
uses: tibdex/[email protected]
with:
app_id: ${{ secrets.CT_CHANGESETS_APP_ID }}
private_key: ${{ secrets.CT_CHANGESETS_APP_PEM }}
- name: Get branch of PR
uses: xt0rted/pull-request-comment-branch@v1
id: comment-branch
- name: Set latest commit status as pending
uses: myrotvorets/set-commit-status-action@master
with:
sha: ${{ steps.comment-branch.outputs.head_sha }}
token: ${{ steps.generate_github_token.outputs.token }}
status: pending
- name: Checkout PR branch
uses: actions/checkout@v2
with:
ref: ${{ steps.comment-branch.outputs.head_ref }}
token: ${{ steps.generate_github_token.outputs.token }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
registry-url: https://registry.npmjs.org/
scope: "@commercetools"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Installing dependencies and building packages
uses: ./.github/actions/ci
- name: Configure prerelease mode
run: |
git checkout ${{ steps.comment-branch.outputs.head_ref }}
pnpm changeset pre enter preview
env:
GITHUB_TOKEN: ${{ steps.generate_github_token.outputs.token }}
- name: Verson package in prerelease mode
run: |
pnpm changeset version
env:
GITHUB_TOKEN: ${{ steps.generate_github_token.outputs.token }}
- name: Publish prerelease packages to npm
run: |
pnpm changeset publish --tag preview
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Exit prerelease mode
run: |
pnpm changeset pre exit
env:
GITHUB_TOKEN: ${{ steps.generate_github_token.outputs.token }}
- name: Post workflow result on PR as a comment
uses: actions/github-script@v6
if: always()
with:
script: |
const name = '${{ github.workflow }}';
const url = '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}';
const success = '${{ job.status }}' === 'success';
const body = `Release workflow ${success ? 'succeeded ✅' : 'failed ❌'}\nSee details: ${url}`;
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
- name: Set latest commit status as ${{ job.status }}
uses: myrotvorets/set-commit-status-action@master
if: always()
with:
sha: ${{ steps.comment-branch.outputs.head_sha }}
token: ${{ steps.generate_github_token.outputs.token }}
status: ${{ job.status }}