Building a docsite outside the project folder and committing to branch

name: Update Docsite

on:
  create:
    tags:
      - v*

jobs:
  build:
    name: Build Docsite

    strategy:
      matrix:
        os: [ubuntu-latest]

    runs-on: ${{ matrix.os }}

    steps:
    - uses: actions/checkout@v2
    - name: Cache Dependencies
      uses: actions/cache@v1.1.2
      env:
        cache-name: cache-node-modules
      with:
        path: ~/.npm
        key: ${{ matrix.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
        restore-keys: |
          ${{ runner.os }}-build-${{ env.cache-name }}-
          ${{ runner.os }}-build-
          ${{ runner.os }}-
    - name: Install Dependencies
      run: npm i
    - name: Define package data
      id: define_pkg
      run: |
        content=`cat **/package.json`
        echo "::set-output name=package::$content"
    - name: Initiate Git
      run: |
        git config --global user.name "Doc updater"
        cd ../cyclone-engine-pages
        git init
        git remote add origin https://github.com/exoRift/cyclone-engine.git
        git fetch origin gh-pages
    - name: Build Resources
      run: npm run build
    - name: Commit Docsite
      run: |
        cd ../cyclone-engine-pages
        git commit -m "Update docsite for version '${{ fromJson(steps.define_pkg.outputs.package).version }}'"

So, I have this workflow that’s a work in progress. npm run build generates a docsite in the directory ../cyclone-engine-pages which I initialized and fetched before as a branch of my repo.

So I have 3 questions with this code
1: Can I manipulate the filesystem outside the project folder directory?
2: Do I have to reset my CD to the project folder for step “Build Resources”?

3: Does this workflow work?

Hi @exorift ,

Thank you for being here! To answer your queries:

  1. yes, you can manipulate the filesystem outside the project folder directory. For github hosted runner, you need to manually create the folder before you cd into.

    • name: Initiate Git
      run: |
      mkdir …/cyclone-engine-pages cd …/cyclone-engine-pages
  2. The default working directory is ‘GITHUB_WORKSPACE’, on ubuntu hosted runner, which typically stands for ‘/home/runner/work/repo/repo’, you can check with command ‘pwd’.

For the step ‘Build Resources’, the ‘npm run build’ command is executed under the GITHUB_WORKSPACE directory NOT ‘cyclone-engine-pages’.

  1. For ‘Commit Docsite’ step, there is no change to commit since npm built in the GITHUB_WORKSPACE directory.

Besides, github hosted runner will be released after workflow completed, if you only commit but not push back the change, no change will be saved after workflow.  

You can use action ‘ad-m/github-push-action’ to push the change, please check the usage of the action.

Hence, your workflow should be not working.

Besides, using the working-directory keyword, you can specify the working directory of where to run the command. Please check the doc for more details.

Thanks.

1 Like

Thank you for the very clear answers! I forgot about mkdir.

Just 2 things to note,

1: npm run build exports its contents to ../cyclone-engine-pages, so I’m good.
2: Yeah, I haven’t implemented the push code yet, but I will. Thank you for your help!