forked from scratchfoundation/scratch-gui
-
-
Notifications
You must be signed in to change notification settings - Fork 71
151 lines (128 loc) · 4.93 KB
/
publish-npm-package-and-deploy-gh-pages.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
name: Publish Npm Package And Deploy Github Pages
on:
push:
branches: [ develop, main, desktop ]
paths-ignore:
- 'README.md'
- '.github/*'
jobs:
check:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- run: npm ci
- name: Test
env:
JEST_JUNIT_OUTPUT_DIR: test-results/unit
run: |
npm run test:lint -- --quiet --output-file test-results/eslint/results.xml --format junit
npm run test:unit -- --reporters="default" --reporters="jest-junit" --coverage --coverageReporters=text --coverageReporters=lcov --maxWorkers="2"
- name: Build
env:
NODE_ENV: production
GA_ID: ${{ secrets.GA_ID }}
NODE_OPTIONS: --max-old-space-size=4000
run: npm run build
publish:
needs: check
runs-on: ubuntu-latest
env:
NPM_TAG: latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14.x'
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- run: npm ci
# Don't push translations to TX. The push step will be run by the distro repository.
# - name: Push i18n
# if: ${{ github.ref == 'refs/heads/main' }}
# run: |
# export TX_TOKEN=${{ secrets.TX_TOKEN }}
# npm run i18n:src
# npm run i18n:push
- name: Update openblock-l10n
if: ${{ github.ref == 'refs/heads/main' }}
run: npm i --save openblock-l10n@latest
- name: Check for modified files
if: ${{ github.ref == 'refs/heads/main' }}
id: git-check
# Check if there are any files update, but ignore the case where only package-lock.json is updated.
run: |
echo ::set-output name=modified::$(if [ -n "$(git status --porcelain)" ] && [ "$(git status --porcelain)" != " M package-lock.json" ]; then echo "true"; else echo "false"; fi)
- name: Update translations changes in GitHub repository
if: ${{ steps.git-check.outputs.modified == 'true' }}
id: git-push
run: |
git config --global user.name github-actions
git config --global user.email [email protected]
git add .
git commit -m '[skip ci] Update translations from transifex'
git remote add origin-translation https://x-access-token:${{ secrets.GH_TOKEN }}@github.com/$GITHUB_REPOSITORY
git pull
git push --set-upstream origin-translation main
- name: Build
env:
NODE_ENV: production
GA_ID: ${{ secrets.GA_ID }}
NODE_OPTIONS: --max-old-space-size=4000
run: npm run build
- name: Get package main version
if: ${{ github.ref == 'refs/heads/main' }}
id: package-version
uses: martinbeentjes/[email protected]
- name: Generate release version
if: ${{ github.ref == 'refs/heads/main' }}
run: |
echo "RELEASE_VERSION=${{ steps.package-version.outputs.current-version }}-prerelease.$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV
- name: Set package version
if: ${{ github.ref == 'refs/heads/main' }}
run: npm --no-git-tag-version version $RELEASE_VERSION
- name: Tag release
if: ${{ github.ref == 'refs/heads/main' }}
run: |
git tag $RELEASE_VERSION
git push https://x-access-token:${{ secrets.GH_TOKEN }}@github.com/$GITHUB_REPOSITORY $RELEASE_VERSION
- uses: JS-DevTools/npm-publish@v1
if: ${{ github.ref == 'refs/heads/main' }}
with:
token: ${{ secrets.NPM_TOKEN }}
- name: Get branch name
id: get-branch-name
run: echo ::set-output name=short_ref::${GITHUB_REF#refs/*/}
- name: Deploy
uses: peaceiris/[email protected]
with:
github_token: ${{ secrets.GH_TOKEN }}
publish_dir: ./build
destination_dir: ${{ steps.get-branch-name.outputs.short_ref }}