ci: add line ending check workflow for current pr #84
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: π Integration | |
on: | |
pull_request: | |
jobs: | |
linelint: | |
runs-on: ubuntu-latest | |
steps: | |
- 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 }} | 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 | |
label-lang: | |
runs-on: ubuntu-latest | |
continue-on-error: true | |
permissions: | |
contents: read | |
pull-requests: write | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- run: echo '{}' > package.json | |
- run: npm install @octokit/rest node-fetch | |
- name: Detect languages and add labels | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
PR_NUM: ${{ github.event.number }} | |
run: | | |
node --input-type=module -e " | |
import { Octokit } from '@octokit/rest'; | |
import path from 'path'; | |
import fetch from 'node-fetch'; | |
const octokit = new Octokit({ | |
auth: process.env.GITHUB_TOKEN, | |
request: { fetch } | |
}); | |
const extensionsToLanguages = { | |
js: 'js', | |
ts: 'ts', | |
py: 'py', | |
java: 'java', | |
kt: 'kotlin', | |
cpp: 'c++', | |
go: 'go', | |
exs: 'elixir', | |
swift: 'swift' | |
// νμν λ€λ₯Έ νμ₯μμ μΈμ΄ 맀ν μΆκ° | |
}; | |
async function run() { | |
const { data: files } = await octokit.pulls.listFiles({ | |
owner: process.env.GITHUB_REPOSITORY.split('/')[0], | |
repo: process.env.GITHUB_REPOSITORY.split('/')[1], | |
pull_number: process.env.PR_NUM, | |
}); | |
const languages = new Set(); | |
files.forEach(file => { | |
const ext = path.extname(file.filename).slice(1); | |
if (extensionsToLanguages[ext]) { | |
languages.add(extensionsToLanguages[ext]); | |
} | |
}); | |
if (languages.size > 0) { | |
await octokit.issues.addLabels({ | |
owner: process.env.GITHUB_REPOSITORY.split('/')[0], | |
repo: process.env.GITHUB_REPOSITORY.split('/')[1], | |
issue_number: process.env.PR_NUM, | |
labels: Array.from(languages), | |
}); | |
} | |
} | |
run(); | |
" |