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

About the example workflow to avoid detached head in github actions #590

Open
mamaredo opened this issue Jul 22, 2022 · 2 comments
Open
Labels

Comments

@mamaredo
Copy link

mamaredo commented Jul 22, 2022

Thanks for the great tool : )

Describe the bug

Why

# .github/workflows/reg.yml

- uses: actions/checkout@v2
  with:
    fetch-depth: 0
...

- name: workaround for detached HEAD
  run: |
    git checkout ${GITHUB_REF#refs/heads/} || git checkout -b ${GITHUB_REF#refs/heads/} && git pull

If you specify 0 for fetch-depth in actions/checkout@v2, you can get all history.
Therefore, a git pull of the detached HEAD workaround is not necessary.

Reproduced step

Fix reg-suit/README.md

# .github/workflows/reg.yml

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Use Node.js v10
        uses: actions/setup-node@v1
        with:
          node-version: "10.x"
      - name: npm install, build, and test
        run: |
          npm i
      - name: workaround for detached HEAD
        run: |
          git checkout ${GITHUB_REF#refs/heads/}
      - name: run reg-suit
        run: |
          npx reg-suit run

@mamaredo mamaredo added the bug label Jul 22, 2022
@t-Asai
Copy link

t-Asai commented Aug 6, 2022

In my case, workaround for detached HEAD is also not necessary as doing below.

...
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
          ref: ${{ github.event.pull_request.head.ref }}
...

@yshrsmz
Copy link

yshrsmz commented Aug 18, 2022

I still need the workaround, but a slightly different

- name: workaround for detached HEAD
  if: ${{ github.event_name == 'pull_request' }}
  run: |
    git checkout ${GITHUB_HEAD_REF#refs/heads/} || git checkout -b ${GITHUB_HEAD_REF#refs/heads/} && git pull

with pull_request trigger, I need to use GITHUB_HEADE_REF instead of GITHUB_REF

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

No branches or pull requests

3 participants