Build React Project and Commit #4
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 React Project and Commit | |
on: | |
push: | |
branches: | |
- master | |
paths: | |
- "frontend/**" | |
workflow_dispatch: | |
jobs: | |
build-and-commit: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Setup Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: "16" | |
- name: Install Yarn | |
run: npm install -g yarn | |
- name: Get yarn cache directory path | |
id: yarn-cache-dir-path | |
run: echo "::set-output name=dir::$(yarn cache dir)" | |
- name: Cache dependencies | |
uses: actions/cache@v2 | |
with: | |
path: | | |
frontend/node_modules | |
${{ steps.yarn-cache-dir-path.outputs.dir }} | |
key: ${{ runner.os }}-yarn-${{ hashFiles('frontend/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- name: Install dependencies | |
run: | | |
cd frontend | |
yarn install --frozen-lockfile | |
- name: Build React project | |
run: | | |
cd frontend | |
yarn build | |
- name: Create build directory if it doesn't exist | |
run: mkdir -p public | |
- name: Move build files to /public | |
run: | | |
mv frontend/build/* public/ | |
- name: Commit and push build files | |
run: | | |
git config --local user.email "action@github.com" | |
git config --local user.name "GitHub Action" | |
git add public/ | |
git commit -m "Add build files" || echo "No changes to commit" | |
git push https://${{ secrets.REPO_PAT }}@github.com/${{ github.repository }}.git |