Checkout: Using checkout twice, keeping the previous folder

Created on 7 Sep 2019  路  7Comments  路  Source: actions/checkout

What do I wanto to achieve?
I want to deploy the master-branch and the beta-branch to gh-pages at the same time. master should go to gh-pages/ (root folder) and beta-branch to gh-pages/beta-folder.

My idea
Currently I'm using actions/checkout twice (in a single job) with those two different branches. First I do checkout, then npm install && npm run build. Works quite well, until the second actions/checkout is executed. This action seems to remove the previous folder including all build results, so I'm unable to move both builds to a deploy-folder to finally publish it to gh-pages. See parts of my script for details:

    steps:
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - name: Checking out master
      uses: actions/checkout@v1
      with:
        ref: master
        path: master
    - name: Build master
      run: |
        npm install
        npm run build --if-present
      env:
        CI: true
# at this point, everything from master has been built and is on the filesystem of the runner
    - name: Checking out beta
      uses: actions/checkout@v1
      with:
        ref: beta
        path: beta
# at this point, everything from master seems to be lost in the filesystem
    - name: Build beta
      run: |
        npm install
        npm run build --if-present
      env:
        CI: true
    - name: GitHub Pages Deploy
      uses: maxheld83/[email protected]
      env:
        BUILD_DIR: deploy/
        GH_PAT: ${{ secrets.GH_PAT }}

Questions

  1. Why is this behaviour? Am I understanding actions/checkout wrong?
  2. Is there a better strategy to use to publish multiple things to gh-pages?

Notes
This idea works when not using actions/checkout but raw git clone. I guess that actions/checkout runs in some sort of docker container, which will be burned after operation.

Most helpful comment

For anyone else that's looking for a clear answer, setting the path of the second checkout uses allowed me to clone the second repo into a sub-directory:

steps:
  build:
    runs-on: ubuntu-latest

    # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
    - uses: actions/checkout@v2
    - uses: actions/checkout@v2
      with:
        repository: gabrieljoelc/fresh-themes
        path: fresh-themes
    - run: ls

build output for the run:

README.md
default.yml
fresh-themes # <= 2nd repo here
manager.yml
node_modules
package-lock.json

All 7 comments

actions/checkout has some special logic when it tries to handle the workflow triggering repository, since the triggering repository will become the GITHUB_WORKSPACE, so you can't use checkout action to make 2 copy of the triggering repository, the workaround I can think of is to write a script to clone/checkout the second copy of your repo.

Shame, I was hoping this is possible...
As a workaround I did the following:
git clone https://<username>:${{ secrets.GH_TOKEN }}@github.com/<user>/<repo>

Edit: It's a private repo hence the token

Just use 2+ separate jobs, they'll run in parallel too. Then use "save/download artifacts" actions to share data between them, if necessary.

You mean in different yml files or in the same action yml file?

You can have multiple jobs in the same workflow (yml)

@thewavelength i'm working on a PR to fix

will be in actions/checkout@v2 and will hopefully merge early next week

For anyone else that's looking for a clear answer, setting the path of the second checkout uses allowed me to clone the second repo into a sub-directory:

steps:
  build:
    runs-on: ubuntu-latest

    # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
    - uses: actions/checkout@v2
    - uses: actions/checkout@v2
      with:
        repository: gabrieljoelc/fresh-themes
        path: fresh-themes
    - run: ls

build output for the run:

README.md
default.yml
fresh-themes # <= 2nd repo here
manager.yml
node_modules
package-lock.json
Was this page helpful?
0 / 5 - 0 ratings