-
Notifications
You must be signed in to change notification settings - Fork 866
162 lines (155 loc) · 5.17 KB
/
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
name: Release Version
on:
push:
branches: ["main"]
tags: ["v*"]
jobs:
build:
runs-on: ubuntu-latest
environment: release
steps:
- name: extract tag
id: extract_tag
uses: actions/github-script@v6
with:
script: |
const prefix = 'refs/tags/';
const ref = context.ref;
return ref.startsWith(prefix) ? ref.substring(prefix.length) : '';
result-encoding: string
- uses: actions/checkout@v3
- name: cache node_modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 14.x
- name: setup global dependencies
run: |
npm install yarn -g
npm install [email protected] -g
- name: install repo dependencies
run: |
yarn install --registry="https://registry.yarnpkg.com"
- name: npm version
run: |
zx scripts/workflow/set-package-version.mjs
env:
TAG: ${{steps.extract_tag.outputs.result}}
- name: build
run: |
yarn build:all
- name: upload build
uses: actions/upload-artifact@v3
with:
name: build
path: |
packages/*/dist/**
packages/*/es/**
package.json
release_npm:
if: ${{ startsWith(github.ref, 'refs/tags/') }}
needs: [build]
environment: release
runs-on: ubuntu-latest
steps:
- name: extract tag
id: extract_tag
uses: actions/github-script@v6
with:
script: |
const prefix = 'refs/tags/';
const ref = context.ref;
return ref.startsWith(prefix) ? ref.substring(prefix.length) : '';
result-encoding: string
- uses: actions/checkout@v3
with:
ref: 'main'
- name: use Node.js
uses: actions/setup-node@v3
with:
node-version: 14.x
- name: cache node_modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: setup git
run: |
git config --global user.name ${{ github.actor }}
git config --global user.email ${{ github.actor }}@users.noreply.github.com
git fetch --tags
git pull
- name: setup global deps
run: |
npm install yarn -g
npm install [email protected] -g
- name: install repo deps
run: |
yarn install --registry="https://registry.yarnpkg.com"
- name: download build
uses: actions/download-artifact@v3
with:
name: build
- name: npm version
run: |
zx scripts/workflow/set-package-version.mjs
env:
TAG: ${{steps.extract_tag.outputs.result}}
- name: setup npm
run: |
npm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN}"
echo "ls -a ${{ github.workspace }}"
ls -a ${{ github.workspace }}
env:
CI: true
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: publish
run: |
zx scripts/workflow/npm-publish.mjs
- name: push to release branch
uses: EndBug/add-and-commit@v9
with:
add: "."
default_author: github_actor
fetch: true
new_branch: release
push: '--set-upstream origin release --force'
message: 'Auto Publish npm version ${{steps.extract_tag.outputs.result}}'
- name: create PR from back to main
uses: actions/github-script@v6
env:
RELEASED_VERSION: ${{steps.extract_tag.outputs.result}}
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const base = "main";
const head = "release";
const title = "new version published: " + process.env.RELEASED_VERSION;
const body = "";
github.rest.pulls.create({
owner,
repo,
base,
head,
title,
body
});