Skip to content

Commit df2b1ad

Browse files
feat: [UEPR-43] Added workflow for publishing packages
1 parent aa00be0 commit df2b1ad

File tree

5 files changed

+179
-1
lines changed

5 files changed

+179
-1
lines changed

.github/workflows/publish.yml

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: Publish
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
ci:
9+
uses: ./.github/workflows/ci.yml
10+
cd:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-node@v4
15+
with:
16+
cache: 'npm'
17+
node-version-file: '.nvmrc'
18+
19+
- name: Config GitHub user
20+
shell: bash
21+
run: |
22+
git config --global user.name 'GitHub Actions'
23+
git config --global user.email 'github-actions@localhost'
24+
25+
- name: Update the version in the package files
26+
shell: bash
27+
run: |
28+
GIT_TAG="${{github.event.release.tag_name}}"
29+
NEW_VERSION="${GIT_TAG/v/}"
30+
31+
bash ./scripts/update-dependencies-with-tag-versions.sh "$NEW_VERSION"
32+
git add package* && git commit -m "Release $NEW_VERSION"
33+
34+
- name: Install dependencies
35+
run: npm ci
36+
37+
- name: Build packages
38+
run: npm run build
39+
40+
- name: Publish scratch-svg-renderer
41+
run: npm publish --access=public --workspace=@scratch/scratch-svg-renderer
42+
env:
43+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
44+
45+
- name: Publish scratch-render
46+
run: npm publish --access=public --workspace=@scratch/scratch-render
47+
env:
48+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
49+
50+
- name: Publish scratch-vm
51+
run: npm publish --access=public --workspace=@scratch/scratch-vm
52+
env:
53+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
54+
55+
- name: Publish scratch-gui
56+
run: npm publish --access=public --workspace=@scratch/scratch-gui
57+
env:
58+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
59+
60+
- name: Push to develop
61+
shell: bash
62+
run: |
63+
git fetch origin develop
64+
65+
TAG_NAME="${{github.event.release.tag_name}}"
66+
LAST_COMMIT_ID="$(git rev-parse $TAG_NAME)"
67+
DEVELOP_COMMIT_ID="$(git rev-parse origin/develop)"
68+
69+
if [ "$LAST_COMMIT_ID" = "$DEVELOP_COMMIT_ID" ]; then
70+
git push origin HEAD:develop
71+
else
72+
echo "Not pushing to develop because the tag we're operating on is behind"
73+
fi
74+
75+
# See https://stackoverflow.com/a/24849501
76+
- name: Change connected commit on release
77+
shell: bash
78+
run: |
79+
git tag -f "${{github.event.release.tag_name}}" HEAD
80+
git push -f origin "refs/tags/${{github.event.release.tag_name}}"
81+
82+
- name: Deploy scratch-svg-renderer to GitHub Pages
83+
uses: peaceiris/actions-gh-pages@v4
84+
with:
85+
github_token: ${{ secrets.GITHUB_TOKEN }}
86+
publish_dir: ./playground
87+
destination_dir: scratch-svg-renderer
88+
full_commit_message: "Build for ${{ github.sha }} ${{ github.event.head_commit.message }}"
89+
90+
- name: Deploy scratch-render to GitHub Pages
91+
uses: peaceiris/actions-gh-pages@v4
92+
with:
93+
github_token: ${{ secrets.GITHUB_TOKEN }}
94+
publish_dir: ./playground
95+
destination_dir: scratch-render
96+
full_commit_message: "Build for ${{ github.sha }} ${{ github.event.head_commit.message }}"
97+
98+
- name: Deploy scratch-vm to GitHub Pages
99+
uses: peaceiris/actions-gh-pages@v4
100+
with:
101+
github_token: ${{ secrets.GITHUB_TOKEN }}
102+
publish_dir: ./playground
103+
destination_dir: scratch-vm
104+
full_commit_message: "Build for ${{ github.sha }} ${{ github.event.head_commit.message }}"
105+
106+
- name: Deploy scratch-gui to GitHub Pages
107+
uses: peaceiris/actions-gh-pages@v4
108+
with:
109+
github_token: ${{ secrets.GITHUB_TOKEN }}
110+
publish_dir: ./build
111+
destination_dir: scratch-gui
112+
full_commit_message: "Build for ${{ github.sha }} ${{ github.event.head_commit.message }}"
113+
needs:
114+
- ci

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"scripts": {
1313
"refresh-gh-workflow": "ts-node scripts/build-gha-workflows.ts",
1414
"build-monorepo": "bash ./scripts/build-monorepo.sh",
15-
"prepare": "husky install"
15+
"prepare": "husky install",
16+
"build": "bash ./scripts/build-packages.sh"
1617
},
1718
"config": {
1819
"commitizen": {

scripts/build-packages.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
cd ./packages/scratch-svg-renderer
4+
npm run build || return 1
5+
cd -
6+
7+
cd ./packages/scratch-render
8+
npm run build || return 1
9+
cd -
10+
11+
cd ./packages/scratch-vm
12+
npm run build || return 1
13+
cd -
14+
15+
cd ./packages/scratch-gui
16+
npm run prepublish
17+
NODE_ENV=production npm run build || return 1
18+
cd -

scripts/git-batch-push.sh

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/bin/bash
2+
13
DEST_BRANCHES="
24
develop,250 \
35
scratch-android,250 \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
3+
ALL_PACKAGES="
4+
scratch-gui \
5+
scratch-render \
6+
scratch-svg-renderer \
7+
scratch-vm \
8+
"
9+
NPM_VERSION=$1
10+
11+
edit_json () {
12+
command=$1
13+
file_name=$2
14+
tmp_file_name="$file_name.tmp"
15+
16+
jq "$command" "$file_name" > "$tmp_file_name"
17+
mv "$tmp_file_name" "$file_name"
18+
}
19+
20+
for PACKAGE in $ALL_PACKAGES; do
21+
cd "./packages/$PACKAGE"
22+
23+
npm version "$NPM_VERSION" --allow-same-version --git-tag-version=false --workspaces=false
24+
25+
for DEPENDENCY in $ALL_PACKAGES; do
26+
DEPENDENCY="@scratch/$DEPENDENCY"
27+
28+
if jq -e .dependencies.\"$DEPENDENCY\" ./package.json > /dev/null; then
29+
edit_json ".dependencies.\"$DEPENDENCY\" |= \"$NPM_VERSION\"" ./package.json
30+
fi
31+
if jq -e .devDependencies.\"$DEPENDENCY\" ./package.json > /dev/null > /dev/null; then
32+
edit_json ".devDependencies.\"$DEPENDENCY\" |= \"$NPM_VERSION\"" ./package.json
33+
fi
34+
if jq -e .optionalDependencies.\"$DEPENDENCY\" ./package.json > /dev/null > /dev/null; then
35+
edit_json ".optionalDependencies.\"$DEPENDENCY\" |= \"$NPM_VERSION\"" ./package.json
36+
fi
37+
if jq -e .peerDependencies.\"$DEPENDENCY\" ./package.json > /dev/null > /dev/null; then
38+
edit_json ".peerDependencies.\"$DEPENDENCY\" |= \"$NPM_VERSION\"" ./package.json
39+
fi
40+
done
41+
42+
cd -
43+
done

0 commit comments

Comments
 (0)