Build and Deploy React App #14
This file contains 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: Build and Deploy React App | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
env: | |
PAT: ${{ secrets.PAT }} | |
PRIVATE_REPO_URL: ${{ secrets.PRIVATE_REPO_URL }} | |
USER_EMAIL: ${{ secrets.USER_EMAIL }} | |
CLIENT_ENV: ${{ secrets.CLIENT_ENV }} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Create env files | |
run: | | |
cd client && cat <<EOL > .env | |
$CLIENT_ENV | |
EOL | |
rm -f .env.example | |
- name: Install dependencies | |
run: | | |
cd client | |
ls -a | |
cat .env | |
npm install | |
- name: Build React app | |
run: | | |
cd client | |
npm run build | |
env: | |
CI: false | |
NODE_ENV: production | |
- name: Copy React build to api folder | |
run: | | |
cp -r client/build api | |
- name: Clone Private Repo | |
uses: actions/checkout@v4 | |
with: | |
repository: ${{ env.PRIVATE_REPO_URL }} | |
token: ${{ env.PAT }} | |
path: private-repo | |
- name: Remove all files in private repo | |
run: | | |
rm -rf private-repo/* | |
- name: Copy api folder to private repo | |
run: | | |
cp -r api/* private-repo/ | |
- name: Configure Git | |
run: | | |
git config --global user.name 'GitHub Actions' | |
git config --global user.email ${{ env.USER_EMAIL }} | |
- name: Commit and Push changes | |
run: | | |
cd private-repo | |
git add . | |
if git diff-index --quiet HEAD --; then | |
echo "No changes to commit" | |
else | |
commit_message="Update files - $(date +'%Y%m%d%H%M%S')" | |
git commit -m "$commit_message" | |
git push origin main | |
fi |