Skip to content

Commit

Permalink
Enhance CI workflow by adding caching for out folder and verifying …
Browse files Browse the repository at this point in the history
…output before deployment
  • Loading branch information
Hyclo committed Jan 8, 2025
1 parent 7a3c099 commit 7787b0b
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions .github/workflows/pipe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
# Task 1: Cache and Build
build:
runs-on: ubuntu-latest # Use the latest Ubuntu environment for the build.
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand Down Expand Up @@ -46,24 +46,31 @@ jobs:
run: npm run build
# Build the application using the `npm run build` command.

- name: Cache `out` folder
uses: actions/cache@v3
with:
path: out
key: ${{ runner.os }}-out-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-out-
# Cache the `out` folder containing the static files for deployment.

- name: Verify export output
run: ls -la ./out
# Verify that the `out` folder was created successfully.

# Task 2: Linting
lint:
runs-on: ubuntu-latest # Use the latest Ubuntu environment for linting.
needs: build # This job depends on the completion of the "build" job.
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v2
# Check out the code from the repository.

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '21'
# Set up Node.js version 21 for linting.

- name: Cache Node.js modules
uses: actions/cache@v3
Expand All @@ -72,30 +79,25 @@ jobs:
key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-modules-
# Cache the Node.js modules (node_modules) for faster dependency installation.
- name: Install dependencies
run: npm ci
# Install dependencies for the linting process.

- name: Run linting
run: npm run lint
# Run the linting process to check for code style and errors.

# Task 3: Testing
test:
runs-on: ubuntu-latest # Use the latest Ubuntu environment for testing.
needs: build # This job depends on the completion of the "build" job.
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v2
# Check out the code from the repository.

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '21'
# Set up Node.js version 21 for testing.

- name: Cache Node.js modules
uses: actions/cache@v3
Expand All @@ -104,38 +106,38 @@ jobs:
key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-modules-
# Cache the Node.js modules (node_modules) for faster dependency installation.
- name: Install dependencies
run: npm ci
# Install dependencies required for the tests.

- name: Cache .next folder
uses: actions/cache@v3
with:
path: .next
key: ${{ runner.os }}-next-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-next-
# Cache the `.next` folder to reuse the build output during testing.

- name: Run tests
run: npm test
# Run the tests to verify application functionality.

# Task 4: Deploy to GitHub Pages
deploy:
runs-on: ubuntu-latest # Use the latest Ubuntu environment for deployment.
needs: [lint, test] # This job depends on the completion of both "lint" and "test" jobs.
runs-on: ubuntu-latest
needs: [lint, test]
steps:
- name: Checkout code
uses: actions/checkout@v2
# Check out the code from the repository.

- name: Restore `out` folder cache
uses: actions/cache@v3
with:
path: out
key: ${{ runner.os }}-out-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-out-
# Restore the cached `out` folder to deploy the prebuilt static files.

- name: Verify export output before deploy
run: ls -la ./out
# Verify that the `out` folder exists before deployment.

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./out
publish_dir: out
force_orphan: true
# Deploy the static files from the `out` directory to GitHub Pages.

0 comments on commit 7787b0b

Please sign in to comment.