From 344fd2d08d9222d796e651ff346bca8366b32f9d Mon Sep 17 00:00:00 2001 From: bky373 Date: Sat, 17 Aug 2024 22:24:59 +0900 Subject: [PATCH 1/4] ci: add line ending check workflow for current pr --- .github/workflows/pr-line-lint.yaml | 57 +++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 .github/workflows/pr-line-lint.yaml diff --git a/.github/workflows/pr-line-lint.yaml b/.github/workflows/pr-line-lint.yaml new file mode 100644 index 000000000..1e1204cb6 --- /dev/null +++ b/.github/workflows/pr-line-lint.yaml @@ -0,0 +1,57 @@ +name: PR Line Lint + +on: + pull_request: + types: [opened, ready_for_review, synchronize] + +permissions: + contents: write + pull-requests: write + +jobs: + line-ending-check: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Get list of changed files + id: changed-files + run: | + changed_files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }}) + echo "Changed files:" + echo "$changed_files" + echo "files<> $GITHUB_OUTPUT + echo "$changed_files" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + - name: Check for missing newlines + id: newline-check + run: | + readarray -t changed_files <<< "${{ steps.changed-files.outputs.files }}" + files_without_newline="" + 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 + if [ -n "$files_without_newline" ]; then + echo "Files without newline at end:" + echo -e "$files_without_newline" + echo "files<> $GITHUB_OUTPUT + echo -e "$files_without_newline" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + exit 1 + fi + + - name: Set Job Summary + if: always() + run: | + if [ -n "${{ steps.newline-check.outputs.files }}" ]; then + echo "아래 파일들에 공백 줄을 추가해주세요." >> $GITHUB_STEP_SUMMARY + echo -e "${{ steps.newline-check.outputs.files }}" >> $GITHUB_STEP_SUMMARY + else + echo "모든 파일이 올바르게 개행 처리되어 있습니다." >> $GITHUB_STEP_SUMMARY + fi From ae4676ebff96d2c0eff53ccab030dd41f351dcfe Mon Sep 17 00:00:00 2001 From: bky373 Date: Fri, 23 Aug 2024 00:28:10 +0900 Subject: [PATCH 2/4] ci: replace `fernandrone/linelint` to custom job in integration workflow --- .github/workflows/integration.yaml | 40 +++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index cd481d9a9..efa068d07 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -8,4 +8,42 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: fernandrone/linelint@0.0.6 + with: + fetch-depth: 0 + + - name: Get list of changed files + id: changed-files + run: | + changed_files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | jq -R -s -c 'split("\n")[:-1]') + echo "changed_files: $changed_files" + echo "files=$changed_files" >> $GITHUB_OUTPUT + + - name: Check for missing newlines + id: newline-check + run: | + files_without_newline=() + while IFS= read -r file; do + if [ -f "$file" ]; then + last_char=$(tail -c 1 "$file") + if [ -n "$last_char" ]; then + files_without_newline+=("$file") + fi + fi + 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]') + echo "files_without_newline: $json_files" + echo "files=$json_files" >> $GITHUB_OUTPUT + exit 1 + fi + + - name: Set Job Summary + if: failure() + run: | + if [ -n '${{ steps.newline-check.outputs.files }}' ]; then + echo "🛠️ 아래 파일들에 공백 줄을 추가해주세요:" >> $GITHUB_STEP_SUMMARY + echo '${{ steps.newline-check.outputs.files }}' | + jq -r '.[]' | + sed 's/^/- /' >> $GITHUB_STEP_SUMMARY + fi From 3eda5164b5935a3012ae92f2d467e426a4f96c3a Mon Sep 17 00:00:00 2001 From: bky373 Date: Fri, 23 Aug 2024 00:37:29 +0900 Subject: [PATCH 3/4] ci: remove file --- .github/workflows/pr-line-lint.yaml | 57 ----------------------------- 1 file changed, 57 deletions(-) delete mode 100644 .github/workflows/pr-line-lint.yaml diff --git a/.github/workflows/pr-line-lint.yaml b/.github/workflows/pr-line-lint.yaml deleted file mode 100644 index 1e1204cb6..000000000 --- a/.github/workflows/pr-line-lint.yaml +++ /dev/null @@ -1,57 +0,0 @@ -name: PR Line Lint - -on: - pull_request: - types: [opened, ready_for_review, synchronize] - -permissions: - contents: write - pull-requests: write - -jobs: - line-ending-check: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Get list of changed files - id: changed-files - run: | - changed_files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }}) - echo "Changed files:" - echo "$changed_files" - echo "files<> $GITHUB_OUTPUT - echo "$changed_files" >> $GITHUB_OUTPUT - echo "EOF" >> $GITHUB_OUTPUT - - - name: Check for missing newlines - id: newline-check - run: | - readarray -t changed_files <<< "${{ steps.changed-files.outputs.files }}" - files_without_newline="" - 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 - if [ -n "$files_without_newline" ]; then - echo "Files without newline at end:" - echo -e "$files_without_newline" - echo "files<> $GITHUB_OUTPUT - echo -e "$files_without_newline" >> $GITHUB_OUTPUT - echo "EOF" >> $GITHUB_OUTPUT - exit 1 - fi - - - name: Set Job Summary - if: always() - run: | - if [ -n "${{ steps.newline-check.outputs.files }}" ]; then - echo "아래 파일들에 공백 줄을 추가해주세요." >> $GITHUB_STEP_SUMMARY - echo -e "${{ steps.newline-check.outputs.files }}" >> $GITHUB_STEP_SUMMARY - else - echo "모든 파일이 올바르게 개행 처리되어 있습니다." >> $GITHUB_STEP_SUMMARY - fi From f6fe0e840e858127a97d0d21d75a73285ffb9c5e Mon Sep 17 00:00:00 2001 From: bky373 Date: Mon, 26 Aug 2024 01:50:34 +0900 Subject: [PATCH 4/4] ci: polish `linelint` job --- .github/workflows/integration.yaml | 41 ++++++++---------------------- 1 file changed, 10 insertions(+), 31 deletions(-) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index efa068d07..deb24d546 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -11,39 +11,18 @@ jobs: with: fetch-depth: 0 - - name: Get list of changed files - id: changed-files + - name: Find files missing end line break run: | - changed_files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | jq -R -s -c 'split("\n")[:-1]') - echo "changed_files: $changed_files" - echo "files=$changed_files" >> $GITHUB_OUTPUT - - - name: Check for missing newlines - id: newline-check - run: | - files_without_newline=() - while IFS= read -r file; do - if [ -f "$file" ]; then - last_char=$(tail -c 1 "$file") - if [ -n "$last_char" ]; then - files_without_newline+=("$file") - fi + 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 < <(echo '${{ steps.changed-files.outputs.files }}' | jq -r '.[]') + done - if [ ${#files_without_newline[@]} -gt 0 ]; then - json_files=$(printf '%s\n' "${files_without_newline[@]}" | jq -R -s -c 'split("\n")[:-1]') - echo "files_without_newline: $json_files" - echo "files=$json_files" >> $GITHUB_OUTPUT + if [ "$success" = false ]; then + echo -e "\n:warning: 위 파일들의 끝에 누락된 줄 바꿈을 추가해 주세요." >> $GITHUB_STEP_SUMMARY exit 1 fi - - - name: Set Job Summary - if: failure() - run: | - if [ -n '${{ steps.newline-check.outputs.files }}' ]; then - echo "🛠️ 아래 파일들에 공백 줄을 추가해주세요:" >> $GITHUB_STEP_SUMMARY - echo '${{ steps.newline-check.outputs.files }}' | - jq -r '.[]' | - sed 's/^/- /' >> $GITHUB_STEP_SUMMARY - fi