Skip to content

Commit

Permalink
gh/actions: refactor out action to deploy branches (#3433)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov authored Dec 20, 2021
1 parent 3ab82f4 commit 71dd289
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 78 deletions.
2 changes: 0 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
/coverage
/npmDist
/denoDist
/npm
/deno

# Ignore TS files inside integration test
/integrationTests/ts/*.ts
52 changes: 52 additions & 0 deletions .github/actions/deploy-dir-as-branch/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: 'Deploy specified directory as a branch'
description: 'This action deploys directory as branch.'
inputs:
src_dir:
required: true
target_branch:
required: true
runs:
using: 'composite'
steps:
- name: Creating temporary directory to clone the branch
shell: bash
run: |
BRANCH_DIR=$(mktemp -d "`pwd`/cloned_${{ inputs.target_branch }}_XXXXXX")
echo "BRANCH_DIR=$BRANCH_DIR" >> $GITHUB_ENV
- name: Checkout `${{ inputs.target_branch }}` branch
uses: actions/checkout@v2
with:
ref: ${{ inputs.target_branch }}
path: ${{ env.BRANCH_DIR }}

- name: Publish `${{ inputs.target_branch }}` branch
working-directory: ${{ env.BRANCH_DIR }}
shell: bash
run: |
echo '::echo::on'
echo '::group::Remove existing files first'
git rm -r .
echo '::endgroup::'
echo '::group::Move necessary files'
cp -vnR '${{ github.workspace }}/${{ inputs.src_dir }}/.' .
echo '::endgroup::'
git add -A
if git diff --staged --quiet; then
echo 'Nothing to publish'
else
git config user.name 'GitHub Action Script'
git config user.email '[email protected]'
git commit -a -m 'Deploy ${{ github.sha }} to '${{ inputs.target_branch }}' branch'
git push
echo 'Pushed'
fi
- name: Remove cloned branch
if: ${{ always() }}
shell: bash
run: 'rm -rf $BRANCH_DIR'
14 changes: 8 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,10 @@ jobs:
run: npm run build:npm

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

deploy-to-deno-branch:
name: Deploy to `deno` branch
Expand All @@ -272,6 +273,7 @@ jobs:
run: npm run build:deno

- name: Deploy to `deno` branch
run: npm run gitpublish:deno
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: ./.github/actions/deploy-dir-as-branch
with:
src_dir: denoDist
target_branch: deno
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@
/coverage
/npmDist
/denoDist
/npm
/deno
2 changes: 0 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@
/coverage
/npmDist
/denoDist
/npm
/deno
66 changes: 0 additions & 66 deletions resources/gitpublish.sh

This file was deleted.

0 comments on commit 71dd289

Please sign in to comment.