3
3
name : Check outdated terms
4
4
on :
5
5
pull_request :
6
- paths :
7
- - ' content/en/**.md'
8
6
branches :
9
7
- ' dev-ko' # add other branches or use wildcard 'dev-**'
8
+ paths :
9
+ - ' content/en/**.md'
10
10
11
11
jobs :
12
12
check-outdated-terms :
13
13
name : Check outdated terms
14
+
15
+ # if: contains(fromJSON('["dev-ko", "dev-xx"]'), github.base_ref)
16
+ # Ref: https://docs.github.com/en/actions/learn-github-actions/expressions
17
+
18
+ if : github.base_ref == 'dev-ko'
14
19
15
20
# Condition to run this workflow on the upstream repository
16
21
# if: github.repository == 'cncf/glossary'
30
35
L10N_BRANCH="${{github.base_ref}}"
31
36
echo "(DEBUG) L10N Branch: ${L10N_BRANCH}"
32
37
38
+ # Set output direcory
39
+ OUTPUT_DIR="./outdated"
40
+
33
41
# Set L10n directory and code
34
42
case "${L10N_BRANCH}" in
35
43
dev-ko)
@@ -46,10 +54,11 @@ jobs:
46
54
echo "(DEBUG) L10N Directory: ${L10N_DIR}"
47
55
echo "(DEBUG) L10N Code: ${L10N_CODE}"
48
56
49
- # Set L10N_DIR and L10N_CODE as environment variables
57
+ # Set L10N_DIR, L10N_CODE, and OUTPUT_DIR as environment variables
50
58
# Ref: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
51
59
echo "L10N_DIR=${L10N_DIR}" >> $GITHUB_ENV
52
- echo "L10N_CODE=${L10N_CODE}" >> $GITHUB_ENV
60
+ echo "L10N_CODE=${L10N_CODE}" >> $GITHUB_ENV
61
+ echo "OUTPUT_DIR=${OUTPUT_DIR}" >> $GITHUB_ENV
53
62
54
63
- name : Checkout
55
64
uses : actions/checkout@v3
@@ -88,38 +97,59 @@ jobs:
88
97
echo "(DUBUG) OLD_BRANCH: ${OLD_BRANCH}"
89
98
90
99
# Make an output directory
91
- mkdir outdated
100
+ if [[ ! -e $OUTPUT_DIR ]]; then
101
+ mkdir $OUTPUT_DIR
102
+ elif [[ ! -d $OUTPUT_DIR ]]; then
103
+ echo "$OUTPUT_DIR already exists but is not a directory" 1>&2
104
+ fi
92
105
93
106
# Check outdated only if there is a localized term
94
107
# Loop files in a localization directory, which is ${L10N_DIR} (e.g., ./content/ko/)
95
108
echo "(DEBUG) Check outdated"
96
- for FILE_PATH in $(find ${L10N_DIR} -name '*.md'); do
97
- # ${MYVAR#pattern}: delete shortest match of pattern from the beginning
98
- FILE_NAME="${FILE_PATH#${L10N_DIR}}"
109
+ for L10N_FILE_PATH in $(find ${L10N_DIR} -name '*.md'); do
110
+ echo "(DEBUG) L10N_FILE_PATH: ${L10N_FILE_PATH}"
111
+
112
+ # Note - extracting a pattern-based substring (https://stackoverflow.com/a/19482947)
113
+ FILE_PATH="${L10N_FILE_PATH#${L10N_DIR}}"
114
+ FILE_DIR=$(dirname ${FILE_PATH})
115
+ FILE_NAME=$(basename ${FILE_PATH})
116
+
117
+ echo "(DEBUG) FILE_PATH: ${FILE_PATH}"
118
+ echo "(DEBUG) FILE_DIR: ${FILE_DIR}"
99
119
echo "(DEBUG) FILE_NAME: ${FILE_NAME}"
100
- echo "(DEBUG) Localized file path: $FILE_PATH"
101
- echo "(DEBUG) Original file path: ./content/en/${FILE_NAME}"
120
+ echo "(DEBUG) Localized file path: $L10N_FILE_PATH"
121
+ echo "(DEBUG) Original file path: ./content/en/${FILE_PATH}"
122
+
123
+ # Create subdirectories
124
+ mkdir -p ${OUTPUT_DIR}/${FILE_DIR}
102
125
103
126
# Actually compare between the old and lastest English terms and log diff in the file
104
- if [[ -f "./content/en/${FILE_NAME }" ]]; then
127
+ if [[ -f "./content/en/${FILE_PATH }" ]]; then
105
128
# File exists
106
- git diff ${OLD_BRANCH}..${LATEST_BRANCH} -- ./content/en/${FILE_NAME} > ./outdated/${FILE_NAME}
129
+ # Check changes
130
+ git diff ${OLD_BRANCH}..${LATEST_BRANCH} -- ./content/en/${FILE_PATH} > temp.diff
131
+
132
+ if [[ -s "temp.diff" ]]; then
133
+ echo "(DEBUG) ${FILE_PATH} is outdated."
134
+ mv temp.diff ${OUTPUT_DIR}/${FILE_PATH}
135
+ fi
136
+
107
137
else
138
+ echo "(DEBUG) ${FILE_PATH} dose not exist."
108
139
# File dose not exist (e.g, changed, renamed or removed)
109
- echo "Could not find ${FILE_NAME } in content/en/" > ./outdated/${FILE_NAME }
110
- echo "Need to check if it has been changed, renamed or removed" >> ./outdated/${FILE_NAME }
140
+ echo "Could not find ${FILE_PATH } in content/en/" > ${OUTPUT_DIR}/${FILE_PATH }
141
+ echo "Need to check if it has been changed, renamed or removed" >> ${OUTPUT_DIR}/${FILE_PATH }
111
142
fi
112
-
113
143
done
114
144
115
145
echo "(DEBUG) The outdated files"
116
- ls -al ./outdated
146
+ ls -al ${OUTPUT_DIR}
117
147
118
148
- name : Upload output
119
149
uses : actions/upload-artifact@v3
120
150
with :
121
151
name : ${{ env.L10N_CODE }}-outdated-checking-result
122
- path : ./outdated /
152
+ path : ${{ env.OUTPUT_DIR }} /
123
153
124
154
# - name: Create an issue from file
125
155
# uses: peter-evans/create-issue-from-file@v4
@@ -128,4 +158,4 @@ jobs:
128
158
# content-filepath: ${{ steps.checker.outputs.output_path }}
129
159
# labels: |
130
160
# outdated
131
- # lang/ko
161
+ # lang/ko
0 commit comments