Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use GitHub Actions with multiple repositories and deploy to GitHub Pages?

Is there a way to setup Github Actions to run multiple npm run builds? I wanted to use multiple repos and set them as different webpages on the main site.

Imagine I had 3 repos: Main, Angular App, and React App.

The Main repo would have my landing site. Angular App and React App would be two different sites.

From foobar.github.io (main repo), I would go to foobar.github.io/angular to navigate to my Angular App. foobar.github.io/react would be a react app.

Each application would be in 3 different repositories. Is there a way for me to push to my Angular App and GitHub Actions would automatically do an ng build --prod --base-href='angular', and update that page or even run a build for all repositories and deploy it?

To do this locally, I would have to do a build command on each repository, and then drag each prod folder into my repo, then push it up, which, in my opinion, can get very inefficient.

like image 761
Jay Patel Avatar asked Feb 18 '20 03:02

Jay Patel


People also ask

How do I deploy a project to GitHub Pages?

GitHub Pages Deploy Action This GitHub Action will automatically deploy your project to GitHub Pages. It can be configured to push your production-ready code into any branch you'd like, including gh-pages and docs. It can also handle cross repository deployments and works with GitHub Enterprise too.

What can you do with GitHub actions?

GitHub Actions. Automate, customize, and execute your software development workflows right in your repository with GitHub Actions. You can discover, create, and share actions to perform any job you'd like, including CI/CD, and combine actions in a completely customized workflow. Quickstart Reference.

How do I deploy any any secrets to a GitHub repository?

Any secrets must be referenced using the bracket syntax and stored in the GitHub repository's Settings/Secrets menu. You can learn more about setting environment variables with GitHub actions here. The following options must be configured in order to make a deployment. The folder in your repository that you want to deploy.

Can I have multiple GitHub Pages sites in one account?

No you are not limited, it is possible to have multiple GitHub Pages sites within one account. Create another GitHub repository and push your site files to the gh-pages branch. Now, push another file "CNAME" to the same repository and branch and fill it with movies.tshepang.net.


1 Answers

The easiest way to do this would be to add a workflow to each repository that updates the corresponding area in Pages. I.e. in the "Main" repo, it would look something like:

on: push

jobs:
  main:
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Build
        run: TODO

      - name: Publish
        run: TODO 

And in the other repositories, you'd have something similar. For example in the Angular repository:

on: push

jobs:      
  angular:
    steps:
      - name: Checkout App
        uses: actions/checkout@v2

      - name: Build Angular
        run: |
          npm ci
          npm run build
          ng build --prod --base-href='angular'

      - name: Publish
        run: TODO

If you wanted to only publish when you update Main, you could have a workflow in your Main repository that builds and publishes all three, e.g.:

on: push

jobs:
  main:
    steps:
      - name: Checkout repo
        uses: actions/checkout@v2
        with:
          repository: my-org/main
          path: main

      - name: Build
        run: TODO
        working-directory: ./main

      - name: Publish
        run: TODO
        working-directory: ./main

  react:
    steps:
      - name: Checkout repo
        uses: actions/checkout@v2
        with:
          repository: my-org/react
          path: react

      - name: Build React
        run: TODO
        working-directory: ./react

      - name: Publish
        run: TODO
        working-directory: ./react

  angular:
    steps:
      - name: Checkout App
        uses: actions/checkout@v2
        with:
          repository: my-org/angular
          path: angular

      - name: Build Angular
        run: |
          npm ci
          npm run build
          ng build --prod --base-href='angular', 
        working-directory: ./angular

      - name: Publish
        run: TODO
        working-directory: ./angular
like image 152
Patrick Quirk Avatar answered Sep 23 '22 14:09

Patrick Quirk