CI/CD for pacman-typescript

The pacman-typescript project employs a CI/CD pipeline for building, testing, and deploying the game. This pipeline is managed by GitHub Actions, leveraging a combination of workflows and jobs to streamline development processes.

CI/CD Pipeline Overview:

The pacman-typescript project utilizes a comprehensive CI/CD pipeline orchestrated through GitHub Actions. This pipeline streamlines the development process by automating tasks such as:

  • Building the game.
  • Running unit tests.
  • Deploying to static hosting services.

Workflows:

The CI/CD pipeline is defined by a single workflow, “ci.yml” located in the .github/workflows directory:

# .github/workflows/ci.yml
          name: CI
          on:
            push:
              branches:
                - main
            pull_request:
              branches:
                - main
          jobs:
            build:
              runs-on: ubuntu-latest
              steps:
                - name: Checkout code
                  uses: actions/checkout@v3
                - name: Install dependencies
                  run: npm install
                - name: Build game
                  run: npm run build
                - name: Run tests
                  run: npm run test
                - name: Deploy to GitHub Pages
                  if: ${{ github.ref == 'refs/heads/main' }}
                  uses: peaceiris/actions-gh-pages@v3
                  with:
                    github_token: ${{ secrets.GITHUB_TOKEN }}
                    publish_dir: ./dist
          

Workflows Options:

  • on: push: Triggers the workflow on every push to the “main” branch.
  • on: pull_request: Triggers the workflow on every pull request targeting the “main” branch.
  • jobs.build.runs-on: ubuntu-latest: Specifies that the build job should run on a “ubuntu-latest” virtual environment.
  • jobs.build.steps.name: Checkout code: Uses the “actions/checkout@v3” action to checkout the code from the repository.
  • jobs.build.steps.name: Install dependencies: Runs the command “npm install” to install project dependencies.
  • jobs.build.steps.name: Build game: Runs the command “npm run build” to build the game.
  • jobs.build.steps.name: Run tests: Runs the command “npm run test” to execute unit tests.
  • jobs.build.steps.name: Deploy to GitHub Pages: Only triggered on pushes to the “main” branch. Uses the “peaceiris/actions-gh-pages@v3” action to deploy the built game to GitHub Pages.
    • github_token: ${{ secrets.GITHUB_TOKEN }}: Uses the “GITHUB_TOKEN” secret to authenticate with GitHub.
    • publish_dir: ./dist: Specifies the directory containing the built game assets to be deployed.

CI/CD Pipeline Implementation

The CI/CD pipeline in pacman-typescript is designed to provide a seamless development experience by automating core processes. The workflow, “ci.yml”, is triggered whenever a new commit is pushed to the “main” branch or a pull request is opened against it.

Workflow Execution:

When a workflow is triggered, it executes a series of steps, each representing a distinct operation. The steps are:

  1. Checkout code: Fetches the latest code from the repository.
  2. Install dependencies: Installs all project dependencies.
  3. Build game: Compiles the game code into a playable build.
  4. Run tests: Executes the project’s unit tests to ensure code quality and functionality.
  5. Deploy to GitHub Pages: (If the push is to the “main” branch) deploys the built game to GitHub Pages, making it accessible online.

CI/CD Pipeline Benefits

The CI/CD pipeline in pacman-typescript brings several advantages to the development process:

  • Automated testing: Ensures code quality through automated unit tests.
  • Continuous deployment: Automatically deploys new builds to GitHub Pages, making them readily available for testing and feedback.
  • Increased developer productivity: Automating routine tasks allows developers to focus on core development activities.

Source:

  • https://github.com/stevedunn/pacman-typescript
  • .github/workflows/ci.yml