Skip to content

Commit f24b144

Browse files
authored
Refactor deploy workflow for React app
Updated GitHub Actions workflow for deploying a React application to GitHub Pages, including build and upload artifact steps.
1 parent 2ec1192 commit f24b144

File tree

1 file changed

+40
-25
lines changed

1 file changed

+40
-25
lines changed

.github/workflows/deploy.yml

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,49 @@
1-
name: Deploy to GitHub Pages
1+
name: Deploy React to GitHub Pages
22

33
on:
44
push:
55
branches:
6-
- main # ou 'master', verifique o nome da sua branch principal
7-
8-
permissions:
9-
contents: write
6+
- main # Triggers the workflow on pushes to the main branch
107

118
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: '20' # Use a stable Node.js version
20+
21+
- name: Install dependencies
22+
run: npm ci
23+
24+
- name: Build React application
25+
run: npm run build # Builds your app into the 'build' or 'dist' folder
26+
27+
- name: Upload artifact
28+
uses: actions/upload-pages-artifact@v3
29+
with:
30+
path: './build' # Path to your built application's static files (e.g., 'dist' for Vite, 'build' for CRA)
31+
1232
deploy:
13-
name: Deploy to GitHub Pages
33+
needs: build # Ensures the build job completes first
1434
runs-on: ubuntu-latest
35+
permissions:
36+
pages: write # Grants the GITHUB_TOKEN write permission for Pages
37+
id-token: write # Required by the deploy-pages action
38+
39+
environment:
40+
name: github-pages
41+
url: ${{ steps.deployment.outputs.page_url }} # Sets the deployment environment and URL
42+
1543
steps:
16-
- uses: actions/checkout@v4
17-
- uses: actions/setup-node@v4
18-
with:
19-
node-version: 20
20-
cache: npm
21-
22-
- name: Install dependencies
23-
run: npm ci
24-
25-
- name: Build website
26-
run: npm run build
27-
28-
- name: Deploy to GitHub Pages
29-
uses: peaceiris/actions-gh-pages@v3
30-
with:
31-
github_token: ${{ secrets.GITHUB_TOKEN }}
32-
publish_dir: ./build
33-
user_name: 'github-actions[bot]'
34-
user_email: 'github-actions[bot]@users.noreply.github.com'
44+
- name: Setup Pages
45+
uses: actions/configure-pages@v5 # This action configures the GitHub Pages environment
46+
47+
- name: Deploy to GitHub Pages
48+
id: deployment
49+
uses: actions/deploy-pages@v4 # This action deploys the uploaded artifact

0 commit comments

Comments
 (0)