-
Notifications
You must be signed in to change notification settings - Fork 73
123 lines (112 loc) · 4.91 KB
/
npm-publish.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
name: Node.js Package
on:
pull_request:
types:
- closed
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: yarn ci
check-version:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
outputs:
core-version-updated: ${{ steps.compare-versions.outputs.core-version-updated }}
react-version-updated: ${{ steps.compare-versions.outputs.react-version-updated }}
contracts-version-updated: ${{ steps.compare-versions.outputs.react-version-updated }}
steps:
- name: Checkout main branch at commit before merge
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.sha }}
- name: Get package version from main branch before merge
id: pre-merge-version
run: |
CORE_PRE_MERGE_VERSION=$(node -p "require('./packages/module/package.json').version")
REACT_PRE_MERGE_VERSION=$(node -p "require('./packages/react/package.json').version")
CONTRACTS_PRE_MERGE_VERSION=$(node -p "require('./packages/contracts/package.json').version")
echo "core_pre_merge_version=$CORE_PRE_MERGE_VERSION" >> "$GITHUB_OUTPUT"
echo "react_pre_merge_version=$REACT_PRE_MERGE_VERSION" >> "$GITHUB_OUTPUT"
echo "react_pre_merge_version=$CONTRACTS_PRE_MERGE_VERSION" >> "$GITHUB_OUTPUT"
- name: Checkout main branch at commit after merge
uses: actions/checkout@v4
with:
ref: 'main'
- name: Get package version from main branch after merge
id: post-merge-version
run: |
CORE_POST_MERGE_VERSION=$(node -p "require('./packages/module/package.json').version")
REACT_POST_MERGE_VERSION=$(node -p "require('./packages/react/package.json').version")
CONTRACTS_POST_MERGE_VERSION=$(node -p "require('./packages/contracts/package.json').version")
echo "core_post_merge_version=$CORE_POST_MERGE_VERSION" >> "$GITHUB_OUTPUT"
echo "react_post_merge_version=$REACT_POST_MERGE_VERSION" >> "$GITHUB_OUTPUT"
echo "react_post_merge_version=$CONTRACTS_POST_MERGE_VERSION" >> "$GITHUB_OUTPUT"
- name: Compare versions
id: compare-versions
run: |
if [[ "${{ steps.pre-merge-version.outputs.core_pre_merge_version }}" != "${{ steps.post-merge-version.outputs.core_post_merge_version }}" ]]; then
echo "core-version-updated=true" >> "$GITHUB_OUTPUT"
else
echo "core-version-updated=false" >> "$GITHUB_OUTPUT"
fi
if [[ "${{ steps.pre-merge-version.outputs.react_pre_merge_version }}" != "${{ steps.post-merge-version.outputs.react_post_merge_version }}" ]]; then
echo "react-version-updated=true" >> "$GITHUB_OUTPUT"
else
echo "react-version-updated=false" >> "$GITHUB_OUTPUT"
fi
if [[ "${{ steps.pre-merge-version.outputs.contracts_pre_merge_version }}" != "${{ steps.post-merge-version.outputs.contracts_post_merge_version }}" ]]; then
echo "contracts-version-updated=true" >> "$GITHUB_OUTPUT"
else
echo "contracts-version-updated=false" >> "$GITHUB_OUTPUT"
fi
publish-meshsdk-core:
needs: [build, check-version]
if: needs.check-version.outputs.core-version-updated == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org/
- run: yarn ci
- run: cd packages/module && npm publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
publish-meshsdk-react:
needs: [build, check-version]
if: needs.check-version.outputs.react-version-updated == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org/
- run: yarn ci
- run: cd packages/react && npm publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
publish-meshsdk-contracts:
needs: [build, check-version]
if: needs.check-version.outputs.contracts-version-updated == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org/
- run: yarn ci
- run: cd packages/contracts && npm publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}