[NHN] Implement ListIID() #227
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: Korean checker | |
# Controls/triggers when the action will run. | |
on: | |
pull_request: | |
branches: | |
- "master" | |
paths: | |
- "**.go" | |
# Environment variables | |
env: | |
OUTPUT_DIR: "./output" | |
OUTPUT_FILE: "korean-check-results.md" | |
jobs: | |
check-if-Korean-is-included: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Fetch all history for all branches and tags | |
- name: Setup to check Korean and upload the results | |
run: | | |
# Make an output directory | |
if [[ ! -e $OUTPUT_DIR ]]; then | |
mkdir -p $OUTPUT_DIR | |
elif [[ ! -d $OUTPUT_DIR ]]; then | |
echo "$OUTPUT_DIR already exists but is not a directory" 1>&2 | |
fi | |
echo ${{ github.event.number }} > ${OUTPUT_DIR}/pr-number.txt | |
- name: Check Korean in quotes | |
id: check-korean | |
run: | | |
set -x | |
##### DEBUG section, this will be removed later ########### | |
ls -al | |
git status | |
git branch | |
# Default environment variables | |
BASE_BRANCH="origin/${{github.base_ref}}" # origin/master | |
PR_BRANCH=${GITHUB_REF#refs/} # pull/xx/merge | |
echo "Base branch: ${BASE_BRANCH}" | |
echo "Extract branch: ${GITHUB_REF#refs/}" | |
# `github` context information | |
echo "(DEBUG) github.ref: ${{github.ref}}" | |
echo "(DEBUG) github.head_ref: ${{github.head_ref}}" | |
echo "(DEBUG) github.base_ref: ${{github.base_ref}}" | |
##################################################### | |
temp_output="temp.md" | |
OUTPUT="${OUTPUT_DIR}/${OUTPUT_FILE}" | |
# Get changed files in the PR | |
files=$(git diff --name-only ${BASE_BRANCH}...${PR_BRANCH} | grep '\.go$' || true) | |
# Create a temp file | |
echo "" > $temp_output | |
# Process each changed file | |
for file in $files; do | |
found_korean=false | |
# Extract changed lines | |
changed_lines=$(git diff ${BASE_BRANCH}...${PR_BRANCH} -- $file | grep "^+") | |
echo "(DEBUG) Changed lines in $file:" | |
echo "$changed_lines" | |
# Check Korean characters wrapped in quote (" ") | |
korean_lines=$(echo "$changed_lines" | grep -n -P "\"([^\"]*[\x{AC00}-\x{D7A3}]+[^\"]*)\"" || true) | |
# Check all Korean characters, such as Korean wrapped in quote, included in comments, and so on. | |
# korean_lines=$(echo "$changed_lines" | grep -n -P "[\x{AC00}-\x{D7A3}]" || true) | |
echo "(DEBUG) Korean lines in $file:" | |
echo "$korean_lines" | |
if [ -n "$korean_lines" ]; then | |
echo "**$file**" >> $temp_output | |
echo "\`\`\`diff" >> $temp_output | |
echo "$korean_lines" | sed -e 's/^[+]\s*//' >> $temp_output | |
echo "\`\`\`" >> $temp_output | |
echo "" >> $temp_output | |
fi | |
done | |
# Output the results to check if Korean exists | |
# Check if the temp_output exists and has content | |
if [ -s "$temp_output" ]; then | |
# Trim before checking if the file has content | |
trimmed_temp_outputs=$(<"$temp_output" tr -d '\n\r\t ') | |
echo "(DEBUG) Trimmed temp_output:" | |
echo "$trimmed_temp_outputs" | |
if [ -n "$trimmed_temp_outputs" ]; then | |
echo "(DEBUG) Korean content detected." | |
cat "$temp_output" > "$OUTPUT" | |
# echo "KOREAN_EXISTS=true" >> $GITHUB_OUTPUT | |
else | |
echo "(DEBUG) No Korean content detected." | |
# echo "KOREAN_EXISTS=false" >> $GITHUB_OUTPUT | |
fi | |
fi | |
# Clean up | |
rm -f "$temp_output" | |
- name: Upload Korean check results | |
# if: steps.check-korean.outputs.KOREAN_EXISTS == 'true' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: results-to-check-korean | |
path: ${{ env.OUTPUT_DIR }} | |
# - name: Fail on Korean Content | |
# if: steps.check-korean.outputs.KOREAN_EXISTS == 'true' | |
# run: | | |
# echo "Korean content detected. Failing the workflow on purpose." | |
# exit 1 | |
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ | |
# https://github.com/actions/upload-artifact | |
# https://github.com/actions/download-artifact |