reg-suit icon indicating copy to clipboard operation
reg-suit copied to clipboard

About the example workflow to avoid detached head in github actions

Open mamaredo opened this issue 3 years ago • 2 comments

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 avatar Jul 22 '22 07:07 mamaredo

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 }}
...

t-Asai avatar Aug 06 '22 12:08 t-Asai

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

yshrsmz avatar Aug 18 '22 07:08 yshrsmz