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

ci: add line ending check workflow for current pr #336

Merged
merged 4 commits into from
Aug 26, 2024

Conversation

bky373
Copy link
Contributor

@bky373 bky373 commented Aug 17, 2024

작업 내용

  • 추가된 워크플로우는 PR 에서 변경된 파일의 끝에 개행(newline) 문자가 있는지 확인합니다.
  • 모든 파일에 개행 처리가 되어 있다면, GitHub Job Summary 에 모든 파일이 올바르게 개행 처리되어 있습니다. 라는 메시지를 출력합니다.
  • 개행 처리가 안 된 파일이 있다면, 해당 파일 목록을 추출하여 Job Summary 에 출력합니다.

테스트

  • 모두 개행 처리된 경우 Job Summary -> 불필요하다고 판단하여 제거
  • 개행 처리되지 않은 파일이 있는 경우 Job Summary
    image
  • 워크플로 실패시 PR 페이지 하단에 아래와 같이 실패 표시가 나타남
    image

.github/workflows/pr-line-lint.yaml Outdated Show resolved Hide resolved
.github/workflows/pr-line-lint.yaml Outdated Show resolved Hide resolved
.github/workflows/pr-line-lint.yaml Outdated Show resolved Hide resolved
.github/workflows/pr-line-lint.yaml Outdated Show resolved Hide resolved
.github/workflows/pr-line-lint.yaml Outdated Show resolved Hide resolved
@bky373
Copy link
Contributor Author

bky373 commented Aug 22, 2024

@DaleSeo
달레님~, integration 워크플로에 신규 job 포함시키는 작업 진행하였습니다~ (이전에는 성공일 경우에도 Job Summary 남겼는데 불필요하다고 생각되어 제거하였습니다. 코드도 줄일겸..)

  • 테스트
    image

그리고 main과 싱크한 후에 워크플로에서 불필요한 permission 을 축소하고 일부 step name 을 제거하는 작업도 진행하였습니다!

@DaleSeo
Copy link
Contributor

DaleSeo commented Aug 22, 2024

(이전에는 성공일 경우에도 Job Summary 남겼는데 불필요하다고 생각되어 제거하였습니다. 코드도 줄일겸..)

저도 그 부분이 약간 걸렸었는데, 제거해주시니 좋네요!

@DaleSeo
Copy link
Contributor

DaleSeo commented Aug 22, 2024

그리고 main과 싱크한 후에 워크플로에서 불필요한 permission 을 축소하고 일부 step name 을 제거하는 작업도 진행하였습니다!

이 job은 추가 persmission 설정 필요없나요? 혹시 워크플로우를 합치는 과정에서 빼먹으셨을까봐 여쭤봅니다.

@bky373
Copy link
Contributor Author

bky373 commented Aug 22, 2024

그리고 main과 싱크한 후에 워크플로에서 불필요한 permission 을 축소하고 일부 step name 을 제거하는 작업도 진행하였습니다!

이 job은 추가 persmission 설정 필요없나요? 혹시 워크플로우를 합치는 과정에서 빼먹으셨을까봐 여쭤봅니다.

아네 개인 레포에서 했을 때 없어도 되었는데요~
현재 PR 에 대한 워크플로도 잘 작동하는 거 보면 없어도 괜찮을 것 같습니다!
https://github.com/DaleStudy/leetcode-study/actions/runs/10511235077/job/29121714569

Copy link
Contributor

@DaleSeo DaleSeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

피드백 적극적으로 반영해주셔서 너무 감사합니다! 덕분에 앞으로 우리 저장소에서 🚫 표시 볼 일을 없겠네요. 🥰


label-lang:
runs-on: ubuntu-latest
continue-on-error: true

permissions:
contents: write
contents: read
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

done < <(echo '${{ steps.changed-files.outputs.files }}' | jq -r '.[]')

if [ ${#files_without_newline[@]} -gt 0 ]; then
json_files=$(printf '%s\n' "${files_without_newline[@]}" | jq -R -s -c 'split("\n")[:-1]')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 거 생각보다 복잡하네요. 예전 방식이 더 간단해서 좋은 것 같기도 하고 ㅎㅎ
예전 방식으로 돌려 달라고 말씀드리면 화나실려나요? 😂

Copy link
Contributor Author

@bky373 bky373 Aug 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아뇨 괜찮습니다 ㅋㅋㅋ 그런데 예전 방식이 이거 말씀하시는 걸까요?

for file in "${changed_files[@]}"; do
    if [ -f "$file" ] && [ "$(tail -c 1 "$file" | wc -l)" -eq 0 ]; then
      files_without_newline+="- ${file}\n" 
    fi
done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DaleSeo 달레님, 요거 답변 주실 수 있으실까요?

Copy link
Contributor

@DaleSeo DaleSeo Aug 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

한 줄의 JSON으로 변환하지 않고 여러 줄의 문자열을 그대로 환경 변수에 설정하는 방식이요! (참고: #336 (comment))

Copy link
Contributor Author

@bky373 bky373 Aug 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DaleSeo 달레님, 스크립트를 많이 개선해서 보다 직관적으로 만들어봤습니다! f6fe0e8

아래는 테스트 결과입니다! 이 친구는 fork repository 와는 무관하지만 그래도 혹시 몰라서 실제 PR 올리는 플로우로 테스트해보았습니다

Copy link
Contributor Author

@bky373 bky373 Aug 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

integration 워크플로면 아무래도 나중에 다른 job 도 추가될 듯한데, 새로운 워크플로는 기존 워크플로에 비해 시간이 많이 감소했습니다.

  • 기존 예시 (fernandrone/linelint)
    image
  • 현재
    image

Comment on lines +16 to +28
files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }})
success=true
for file in $files; do
if [ "$(tail -c 1 $file | wc -l)" -eq 0 ]; then
echo "- $file" >> $GITHUB_STEP_SUMMARY
success=false
fi
done

if [ "$success" = false ]; then
echo -e "\n:warning: 위 파일들의 끝에 누락된 줄 바꿈을 추가해 주세요." >> $GITHUB_STEP_SUMMARY
exit 1
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

와, 맨 처음 스크립트에 비해서 진짜 간단해졌네요 ㅎㅎ 🕺

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네네 다행히 간단히 줄일 수 있었습니다! 요거는 전에 승인 주셨으니 병합 진행할게요!

@bky373 bky373 merged commit 2f78a50 into DaleStudy:main Aug 26, 2024
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants