Giter VIP home page Giter VIP logo

build-deploy-and-preview-action's Introduction

Build, Deploy to GitHub Pages and Deploy PR Preview Action

code style: prettier Release version badge license PRs GitHub Marketplace badge

GitHub Action that automatically builds your project, deploys it to GitHub Pages and creates a PR preview.

Table of Contents

About

This action will automatically build your project, deploy it to GitHub Pages and also create a PR preview.

Usage

Usage is very simple and can be done with just a few steps.

Vite

If you are using Vite, it is very easy to use this action. This action will automatically configure the base URL for you.

First, you need to create a workflow file in your repository. For example, you can create a file called build-deploy-and-preview.yml in the .github/workflows directory of your repository with the following contents:

name: Build, Deploy to GitHub Pages and Deploy PR Preview

on:
  push:
    branches: [main, master]
  pull_request:
    types:
      - opened
      - reopened
      - synchronize
      - closed

permissions:
  contents: write
  pull-requests: write

concurrency: ci-${{ github.ref }}

jobs:
  build-deploy-and-preview:
    name: Build, Deploy to GitHub Pages and Deploy PR Preview
    runs-on: ubuntu-latest
    steps:
      - name: Build, Deploy to GitHub Pages and Deploy PR Preview
        uses: chvmvd/[email protected]
        with:
          type: vite

Second, you need to ensure that your GitHub repository is configured to use GitHub Pages. You can do this by going to the Settings tab of your repository and selecting the Pages section. You can then select the branch that you want to use for GitHub Pages(The gh-pages is used by convention and is used by this action by default).

capture of the `Pages` section

Docusaurus

First, since GitHub Pages deploys your project to https://<owner>.github.io/<repo>, you have to configure the base URL for your project.

You can do this by editing the docusaurus.config.js file in the root directory of your project.

Inside docusaurus.config.js, add the following line to the baseUrl property of the config object(This action provides the BASE_URL environment variable that contains the base URL of your project):

baseUrl: process.env.GITHUB_ACTIONS ? `${process.env.BASE_URL}/` : "/",

Second, you need to create a workflow file in your repository. For example, you can create a file called build-deploy-and-preview.yml in the .github/workflows directory of your repository with the following contents:

name: Build, Deploy to GitHub Pages and Deploy PR Preview

on:
  push:
    branches: [main, master]
  pull_request:
    types:
      - opened
      - reopened
      - synchronize
      - closed

permissions:
  contents: write
  pull-requests: write

concurrency: ci-${{ github.ref }}

jobs:
  build-deploy-and-preview:
    name: Build, Deploy to GitHub Pages and Deploy PR Preview
    runs-on: ubuntu-latest
    steps:
      - name: Build, Deploy to GitHub Pages and Deploy PR Preview
        uses: chvmvd/[email protected]
        with:
          type: docusaurus

Third, you need to ensure that your GitHub repository is configured to use GitHub Pages. Please refer to the Vite section for more information.

Configuration

The following configuration options are available:

Name Description Required Default
type The type of your project. (Other settings will be automatically set for the type of the project. Currently only vite and docusaurus are supported.) true
package-manager The package manager that will be used to install dependencies. (npm, yarn or pnpm) false npm
rootDir The root directory of your project. (Default is the current directory.) false .
folder The folder that contains the built files. (If set to auto, it will use the default folder for the type of the project.) false auto
pr-preview Whether to create a PR preview or not. false true
production-branch The branch that contains the production code. (Default is main or master) false main or master
development-branch The branch that contains the development code. It will be deployed to https://<owner>.github.io/<repo>/<branch>. (This can be multiple branches. If you want to specify multiple branches, separate them with a newline.) false
deployment-branch The branch that the project will be deployed to. false gh-pages
umbrella-dir The directory that will contain all PR previews. false pr-preview
custom-url The custom URL to deploy. false

Roadmap

Currently, only Vite and Docusaurus are supported. I will add support for other frameworks in the future.

License

This project is licensed under the terms of the MIT license.

Contributing

Issues and pull requests are always welcome.

build-deploy-and-preview-action's People

Contributors

chvmvd avatar

Stargazers

Jonathan Ferreira avatar  avatar

Watchers

Kostas Georgiou avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.