Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh/actions: refactor out action to deploy branches #3433

Merged
merged 1 commit into from Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions .eslintignore
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
@@ -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 'please@open.issue'

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
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
Expand Up @@ -12,5 +12,3 @@
/coverage
/npmDist
/denoDist
/npm
/deno
2 changes: 0 additions & 2 deletions .prettierignore
Expand Up @@ -5,5 +5,3 @@
/coverage
/npmDist
/denoDist
/npm
/deno
66 changes: 0 additions & 66 deletions resources/gitpublish.sh

This file was deleted.