Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using checkout twice, keeping the previous folder #33

Closed
thewavelength opened this issue Sep 7, 2019 · 11 comments
Closed

Using checkout twice, keeping the previous folder #33

thewavelength opened this issue Sep 7, 2019 · 11 comments
Assignees
Milestone

Comments

@thewavelength
Copy link

thewavelength commented Sep 7, 2019

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/ghpages@v0.2.1
      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.

@TingluoHuang
Copy link
Member

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.

@Trimud
Copy link

Trimud commented Oct 25, 2019

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

@fregante
Copy link

fregante commented Oct 31, 2019

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

@Trimud
Copy link

Trimud commented Oct 31, 2019

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

@fregante
Copy link

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

@ericsciple
Copy link
Contributor

@thewavelength i'm working on a PR to fix

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

@ericsciple ericsciple self-assigned this Nov 23, 2019
@ericsciple ericsciple added this to the v2 milestone Nov 23, 2019
@gabrieljoelc
Copy link

gabrieljoelc commented Mar 6, 2020

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

@yasirroni
Copy link

@gabrieljoelc how to add the run so that both repository run in parallel?

For example run benchmark on both repository, but ensure both run in the same machine.

@yasirroni
Copy link

This will run in error

    steps:
    # Parallel checkout repository
      # HEAD
      - uses: actions/checkout@v3
        with:
          # ref to HEAD automatically
          path: head
      - name: Print current commit
        run: |
          git rev-parse --short HEAD

      # Ref
      - uses: actions/checkout@v3
        with:
          ref: my_tag
          path: ref
      - name: Print current commit
        run: |
          git rev-parse --short HEAD

@Moncsika123
Copy link

Monika

@Moncsika123
Copy link

Gut!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants