forked from scratchfoundation/scratch-blocks
-
Notifications
You must be signed in to change notification settings - Fork 42
166 lines (138 loc) · 5.23 KB
/
publish-npm-package.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
163
164
165
name: Publish Npm Package
on:
push:
branches: [ main ]
paths-ignore:
- 'README.md'
- '.github/*'
jobs:
check:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [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: Set up Python 2.7
run: |
sudo apt-get update
sudo apt-get install -y \
python2.7 python2.7-dev python2-pip-whl
sudo ln -sf python2.7 /usr/bin/python
export PYTHONPATH=`echo /usr/share/python-wheels/pip-*py2*.whl`
sudo --preserve-env=PYTHONPATH python -m pip install --upgrade pip setuptools wheel
sudo chown -R $USER /usr/local/lib/python2.7
- 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
- uses: nanasess/setup-chromedriver@v2
with:
chromedriver-version: '113.0.5672.63'
- name: Set test env
run: |
export DISPLAY=:99.0
tests/scripts/setup_linux_env.sh
sleep 2
- run: npm test
publish:
needs: check
runs-on: ubuntu-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 }}-
- name: Set up Python 2.7
run: |
sudo apt-get update
sudo apt-get install -y \
python2.7 python2.7-dev python2-pip-whl
sudo ln -sf python2.7 /usr/bin/python
export PYTHONPATH=`echo /usr/share/python-wheels/pip-*py2*.whl`
sudo --preserve-env=PYTHONPATH python -m pip install --upgrade pip setuptools wheel
sudo chown -R $USER /usr/local/lib/python2.7
- run: npm ci
- name: Update openblock-l10n
run: npm i --save openblock-l10n@latest
# Don't push translations to TX, just pull, The push step will be run by the distro repository.
# - name: Sync translations
# run: |
# export TX_TOKEN=${{ secrets.TX_TOKEN }}
# npm run translate
# npm run translate:update
- name: Pull translations
run: |
export TX_TOKEN=${{ secrets.TX_TOKEN }}
npm run translate
npm run translate:sync:translations
- uses: nanasess/setup-chromedriver@v2
with:
chromedriver-version: '113.0.5672.63'
- name: Set test env
run: |
export DISPLAY=:99.0
tests/scripts/setup_linux_env.sh
sleep 2
- run: npm test
- name: Check for modified files
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: Commit translations
if: ${{ steps.git-check.outputs.modified == 'true' }}
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 push --set-upstream origin-translation main
- name: Get package main version
id: package-version
uses: martinbeentjes/[email protected]
- name: Generate release version
run: |
echo "RELEASE_VERSION=${{ steps.package-version.outputs.current-version }}-prerelease.$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV
- name: Set package version
run: npm --no-git-tag-version version $RELEASE_VERSION
- name: Tag release
run: |
git tag $RELEASE_VERSION
git push https://x-access-token:${{ secrets.GH_TOKEN }}@github.com/$GITHUB_REPOSITORY $RELEASE_VERSION
- name: Deploy with gh-pages
run: |
git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
git apply gh-pages/patch
npm run prepublish
npm run deploy -- -u "github-actions-bot <[email protected]>"
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}