[es] Merge main
into dev-es
#10
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
# This workflow will check if a localized content is outdated or not | |
# by comparing English content in the old branch and the latest branch. | |
name: Check outdated content | |
on: | |
pull_request: | |
branches: | |
- 'dev-ko' | |
- 'dev-es' | |
paths: | |
- 'content/en/**.md' | |
jobs: | |
check-outdated-content: | |
name: Check outdated content | |
if: contains(fromJSON('["dev-ko","dev-es"]'), github.base_ref) | |
# Ref: https://docs.github.com/en/actions/learn-github-actions/expressions | |
#if: github.base_ref == 'dev-ko' | |
# Condition to run this workflow on the upstream repository | |
#if: github.repository == 'cncf/glossary' | |
runs-on: ubuntu-latest | |
# permissions: | |
# issues: write | |
# NOTE - In this workflow, "github.base_ref" refers to the old upstream/dev-xx. | |
# NOTE - In this workflow, "github.head_ref" refers to the latest forked/dev-xx or the latest upstream/main. | |
steps: | |
- name: Set up environment variables for the target L10n team | |
shell: bash | |
run: | | |
# Set L10n branch | |
L10N_BRANCH="${{github.base_ref}}" | |
echo "(DEBUG) L10N Branch: ${L10N_BRANCH}" | |
# Set output direcory | |
OUTPUT_DIR="./outdated" | |
# Set L10n code | |
L10N_CODE="${L10N_BRANCH//dev-/}" | |
echo "(DEBUG) L10N Code: ${L10N_CODE}" | |
# Set L10n directory | |
case "${L10N_BRANCH}" in | |
dev-pt) | |
L10N_DIR="content/pt-br/" | |
;; | |
dev-zh) | |
L10N_DIR="content/zh-cn/" | |
;; | |
dev-tw) | |
L10N_DIR="content/zh-tw/" | |
;; | |
*) | |
L10N_DIR="content/${L10N_CODE}/" | |
;; | |
esac | |
echo "(DEBUG) L10N Directory: ${L10N_DIR}" | |
# Set L10N_DIR, L10N_CODE, and OUTPUT_DIR as environment variables | |
# Ref: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable | |
echo "L10N_DIR=${L10N_DIR}" >> $GITHUB_ENV | |
echo "L10N_CODE=${L10N_CODE}" >> $GITHUB_ENV | |
echo "OUTPUT_DIR=${OUTPUT_DIR}" >> $GITHUB_ENV | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # fetch all history for all tags and branches | |
- name: Check outdated | |
id: checker | |
shell: bash | |
run: | | |
##### DEBUG section, this will be removed later ########### | |
ls -al | |
git status | |
git branch | |
# Default environment variables | |
echo "GITHUB_REF: $GITHUB_REF" | |
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}}" | |
echo "(DEBUG) L10N_DIR: ${L10N_DIR}" | |
echo "(DEBUG) L10N_DIR: ${{ env.L10N_DIR }}" | |
##################################################### | |
# Get the lastest branch name from 'GITHUB_REF' | |
# The latest branch can be 'upstream/main' or 'forked/dev-ko' (rebased) | |
LATEST_BRANCH=${GITHUB_REF#refs/} | |
echo "(DEBUG) LATEST_BRANCH: ${LATEST_BRANCH}" | |
# Get the old branch from 'github.base_ref' | |
# The old branch can be 'upstream/dev-ko' | |
OLD_BRANCH="origin/${{github.base_ref}}" | |
echo "(DEBUG) OLD_BRANCH: ${OLD_BRANCH}" | |
L10N_INFO_JSON=$(cat <<EOF | |
{ | |
"L10N_DIR": "${L10N_DIR}", | |
"L10N_CODE": "${L10N_CODE}" | |
} | |
EOF | |
) | |
# Make an output directory | |
if [[ ! -e $OUTPUT_DIR ]]; then | |
mkdir $OUTPUT_DIR | |
echo "${L10N_INFO_JSON}" > ${OUTPUT_DIR}/L10N_INFO.json | |
elif [[ ! -d $OUTPUT_DIR ]]; then | |
echo "$OUTPUT_DIR already exists but is not a directory" 1>&2 | |
fi | |
# Check outdated only if a localized content exists | |
# Loop files in a localization directory, which is ${L10N_DIR} (e.g., content/ko/) | |
echo "(DEBUG) Check outdated" | |
for L10N_FILE_PATH in $(find ${L10N_DIR} -name '*.md'); do | |
echo "(DEBUG) L10N_FILE_PATH: ${L10N_FILE_PATH}" | |
# Note - extracting a pattern-based substring (https://stackoverflow.com/a/19482947) | |
FILE_PATH="${L10N_FILE_PATH#${L10N_DIR}}" | |
FILE_DIR=$(dirname ${FILE_PATH}) | |
FILE_NAME=$(basename ${FILE_PATH}) | |
echo "(DEBUG) FILE_PATH: ${FILE_PATH}" | |
echo "(DEBUG) FILE_DIR: ${FILE_DIR}" | |
echo "(DEBUG) FILE_NAME: ${FILE_NAME}" | |
echo "(DEBUG) Localized file path: $L10N_FILE_PATH" | |
echo "(DEBUG) Original file path: content/en/${FILE_PATH}" | |
# Create subdirectories | |
mkdir -p ${OUTPUT_DIR}/${FILE_DIR} | |
# Actually compare between the old and lastest English content and log diff in the file | |
if [[ -f "content/en/${FILE_PATH}" ]]; then | |
# File exists | |
# Check changes | |
git diff ${OLD_BRANCH}..${LATEST_BRANCH} -- content/en/${FILE_PATH} > temp.diff | |
if [[ -s "temp.diff" ]]; then | |
echo "(DEBUG) ${FILE_PATH} is outdated." | |
mv temp.diff ${OUTPUT_DIR}/${FILE_PATH} | |
fi | |
else | |
echo "(DEBUG) ${FILE_PATH} does not exist." | |
# File dose not exist (e.g, changed, renamed or removed) | |
echo "Could not find ${FILE_PATH} in content/en/" > ${OUTPUT_DIR}/${FILE_PATH} | |
echo "Need to check if it has been changed, renamed or removed" >> ${OUTPUT_DIR}/${FILE_PATH} | |
fi | |
done | |
echo "(DEBUG) The outdated files" | |
ls -al ${OUTPUT_DIR} | |
- name: Upload output | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ env.L10N_CODE }}-outdated-checking-result | |
path: ${{ env.OUTPUT_DIR }}/ | |
# - name: Create an issue from file | |
# uses: peter-evans/create-issue-from-file@v4 | |
# with: | |
# title: An example issue | |
# content-filepath: ${{ steps.checker.outputs.output_path }} | |
# labels: | | |
# outdated | |
# lang/ko |