Skip to content

Commit 71dd289

Browse files
gh/actions: refactor out action to deploy branches (#3433)
1 parent 3ab82f4 commit 71dd289

File tree

6 files changed

+60
-78
lines changed

6 files changed

+60
-78
lines changed

.eslintignore

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
/coverage
55
/npmDist
66
/denoDist
7-
/npm
8-
/deno
97

108
# Ignore TS files inside integration test
119
/integrationTests/ts/*.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: 'Deploy specified directory as a branch'
2+
description: 'This action deploys directory as branch.'
3+
inputs:
4+
src_dir:
5+
required: true
6+
target_branch:
7+
required: true
8+
runs:
9+
using: 'composite'
10+
steps:
11+
- name: Creating temporary directory to clone the branch
12+
shell: bash
13+
run: |
14+
BRANCH_DIR=$(mktemp -d "`pwd`/cloned_${{ inputs.target_branch }}_XXXXXX")
15+
echo "BRANCH_DIR=$BRANCH_DIR" >> $GITHUB_ENV
16+
17+
- name: Checkout `${{ inputs.target_branch }}` branch
18+
uses: actions/checkout@v2
19+
with:
20+
ref: ${{ inputs.target_branch }}
21+
path: ${{ env.BRANCH_DIR }}
22+
23+
- name: Publish `${{ inputs.target_branch }}` branch
24+
working-directory: ${{ env.BRANCH_DIR }}
25+
shell: bash
26+
run: |
27+
echo '::echo::on'
28+
29+
echo '::group::Remove existing files first'
30+
git rm -r .
31+
echo '::endgroup::'
32+
33+
echo '::group::Move necessary files'
34+
cp -vnR '${{ github.workspace }}/${{ inputs.src_dir }}/.' .
35+
echo '::endgroup::'
36+
37+
git add -A
38+
if git diff --staged --quiet; then
39+
echo 'Nothing to publish'
40+
else
41+
git config user.name 'GitHub Action Script'
42+
git config user.email '[email protected]'
43+
44+
git commit -a -m 'Deploy ${{ github.sha }} to '${{ inputs.target_branch }}' branch'
45+
git push
46+
echo 'Pushed'
47+
fi
48+
49+
- name: Remove cloned branch
50+
if: ${{ always() }}
51+
shell: bash
52+
run: 'rm -rf $BRANCH_DIR'

.github/workflows/ci.yml

+8-6
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,10 @@ jobs:
243243
run: npm run build:npm
244244

245245
- name: Deploy to `npm` branch
246-
run: npm run gitpublish:npm
247-
env:
248-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
246+
uses: ./.github/actions/deploy-dir-as-branch
247+
with:
248+
src_dir: npmDist
249+
target_branch: npm
249250

250251
deploy-to-deno-branch:
251252
name: Deploy to `deno` branch
@@ -272,6 +273,7 @@ jobs:
272273
run: npm run build:deno
273274

274275
- name: Deploy to `deno` branch
275-
run: npm run gitpublish:deno
276-
env:
277-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
276+
uses: ./.github/actions/deploy-dir-as-branch
277+
with:
278+
src_dir: denoDist
279+
target_branch: deno

.gitignore

-2
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,3 @@
1212
/coverage
1313
/npmDist
1414
/denoDist
15-
/npm
16-
/deno

.prettierignore

-2
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,3 @@
55
/coverage
66
/npmDist
77
/denoDist
8-
/npm
9-
/deno

resources/gitpublish.sh

-66
This file was deleted.

0 commit comments

Comments
 (0)