build: change ci script #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy React App | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - develop | |
| pull_request: | |
| branches: | |
| - main | |
| - develop | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout source code | |
| uses: actions/checkout@v2 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v2 | |
| with: | |
| node-version: "20" | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Create .env file from secret | |
| run: | | |
| echo "${{ secrets.APP_ENV }}" | base64 --decode > .env | |
| - name: Build the React app | |
| run: npm run build | |
| - name: Push built app to deployment repository | |
| env: | |
| GH_TOKEN: ${{ secrets.AUTO_ACTIONS }} | |
| run: | | |
| TARGET_REPO="ajou-chong/ajouchong-admin" | |
| CLONE_DIR="deploy-repo" | |
| DEPLOY_BRANCH="${GITHUB_REF##*/}" | |
| git clone --depth=1 https://x-access-token:${GH_TOKEN}@github.com/${TARGET_REPO}.git $CLONE_DIR | |
| cp ./* ./$CLONE_DIR/* | |
| cd $CLONE_DIR | |
| git config --global user.name "GitHub Actions" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| if git show-ref --verify --quiet refs/heads/${DEPLOY_BRANCH}; then | |
| git checkout ${DEPLOY_BRANCH} | |
| else | |
| git checkout -b ${DEPLOY_BRANCH} | |
| fi | |
| git add . | |
| git commit -m "Deploy app [${{ github.sha }}]" | |
| git push -f origin ${DEPLOY_BRANCH} |