Skip to content

Commit

Permalink
Simplify action inputs and change defaults (#7)
Browse files Browse the repository at this point in the history
* Simplify action inputs

* Update README.md
  • Loading branch information
manzoorwanijk authored Jan 17, 2024
1 parent 7d340c1 commit 90d51a7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 30 deletions.
43 changes: 20 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Brief description:
name: Build and Deploy Assets
on:
push:
branches: [master]
branches: [main]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
Expand All @@ -28,13 +28,12 @@ jobs:
run: npm install && npm run build

- name: Deploy
uses: manzoorwanijk/action-deploy-to-repo@v2
uses: manzoorwanijk/action-deploy-to-repo@v3
with:
src_dir: build
target_owner: <repo-owner>
target_repo: <repo-name>
target_repo: <org>/<repo>
target_dir: src/assets
target_branch: master # default
target_branch: main # default
access_token: ${{ secrets.GITHUB_ACCESS_TOKEN }}
# Optional
cleanup_command: "rm -rf assets/* && rm -f assets/asset-manifest.json"
Expand All @@ -46,7 +45,7 @@ jobs:
name: Build and Deploy Assets
on:
push:
branches: [master]
branches: [main]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
Expand All @@ -70,13 +69,12 @@ jobs:
run: npm install && npm run build

- name: Deploy
uses: manzoorwanijk/action-deploy-to-repo@v2
uses: manzoorwanijk/action-deploy-to-repo@v3
with:
src_dir: build
target_owner: <repo-owner>
target_repo: <repo-name>
target_repo: <org>/<repo>
target_dir: src/assets
target_branch: master # default
target_branch: main # default
cleanup_command: "rm -rf assets/* && rm -f assets/asset-manifest.json"
```
Expand All @@ -86,18 +84,17 @@ Apart from the required arguments, you should either set up SSH as shown in the
## Parameters
| Name | description | Required |
| ------------------- | ------------------------------------------------------------ | -------------------------- |
| `src_dir` | Relative path of the source directory. | **YES** |
| `target_owner` | GitHub username of the target repo owner. | **YES** |
| `target_repo` | Name of the target repo. | **YES** |
| `target_dir` | Relative path of the target directory. | **YES** |
| `target_branch` | Name of the branch on target repo. Default `master`. | |
| `access_token` | GitHub access token for the target repo. | **YES** (if not using SSH) |
| `git_user_email` | Email of the git user. | |
| `git_user_name` | Name of the git user. | |
| `cleanup_command` | The command(s) to run for clean up before copying the files. | |
| `precommit_command` | The command(s) to run before committing the files. | |
| `commit_msg` | Deployment commit message. | |
| Name | description | Required |
| ------------------- | ------------------------------------------------------------------------------ | -------------------------- |
| `src_dir` | Relative path of the source directory. | **YES** |
| `target_repo` | Target repository in the form of `<organization>/<repo>` e.g. `google/wireit`. | **YES** |
| `target_dir` | Relative path of the target directory. | **YES** |
| `target_branch` | Name of the branch on target repo. Default `main`. | |
| `access_token` | GitHub access token for the target repo. | **YES** (if not using SSH) |
| `git_user_email` | Email of the git user. | |
| `git_user_name` | Name of the git user. | |
| `cleanup_command` | The command(s) to run for clean up before copying the files. | |
| `precommit_command` | The command(s) to run before committing the files. | |
| `commit_msg` | Deployment commit message. | |

This action is inspired by [hpcodecraft/action-deploy-workspace-to-repo](https://github.com/hpcodecraft/action-deploy-workspace-to-repo)
11 changes: 4 additions & 7 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,22 @@ git config --global user.email "$GIT_USER_EMAIL"
git config --global user.name "$GIT_USER_NAME"

ACCESS_TOKEN="$INPUT_ACCESS_TOKEN"
TARGET_OWNER="$INPUT_TARGET_OWNER"
TARGET_REPO="$INPUT_TARGET_REPO"
TARGET_BRANCH="${INPUT_TARGET_BRANCH:-master}"
TARGET_BRANCH="${INPUT_TARGET_BRANCH:-main}"
CLEANUP_COMMAND="$INPUT_CLEANUP_COMMAND"
SRC_DIR="$INPUT_SRC_DIR"
TARGET_DIR="$INPUT_TARGET_DIR"
PRECOMMIT_COMMAND="$INPUT_PRECOMMIT_COMMAND"

REPOSITORY="$TARGET_OWNER/$TARGET_REPO"

# If access token is provided, use it
if [ ! -z "$ACCESS_TOKEN" ]; then
REPO_PATH="https://$ACCESS_TOKEN@github.com/$REPOSITORY.git"
REPO_PATH="https://$ACCESS_TOKEN@github.com/$TARGET_REPO.git"
else
# otherwise it's assumed that SSH is already set up
REPO_PATH="[email protected]:$REPOSITORY.git"
REPO_PATH="[email protected]:$TARGET_REPO.git"
fi

echo "⬇️ Cloning $REPOSITORY"
echo "⬇️ Cloning $TARGET_REPO"
CLONE_DIR="__${TARGET_REPO}__clone__"
cd $GITHUB_WORKSPACE
# Ensure that the clone path is clean
Expand Down

0 comments on commit 90d51a7

Please sign in to comment.