forked from cncf/glossary
-
Notifications
You must be signed in to change notification settings - Fork 0
153 lines (128 loc) · 6.03 KB
/
post-outdated-content-report.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# This workflow will post a report of outdated content
# by using data from previous workflows.
name: Post outdated content report
on:
workflow_run:
workflows: ["Check outdated content"]
types:
- completed
jobs:
post-outdated-report:
name: Post outdated content report
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
permissions:
issues: write
# pull-requests: write
steps:
- name: Show the github context
shell: bash
run: |
echo "(DEBUG) ParsedBranch: ${GITHUB_REF#refs/heads/}"
echo "(DEBUG) github: ${{ github }}"
echo "(DEBUG) toJSON(github):"
echo '${{ toJSON(github) }}'
echo "(DEBUG) github.action: ${{ github.action }}"
echo "(DEBUG) github.action_path: ${{ github.action_path }}"
echo "(DEBUG) github.actor: ${{ github.actor }}"
echo "(DEBUG) github.base_ref: ${{ github.base_ref }}"
echo "(DEBUG) github.event: ${{ github.event }}"
echo "(DEBUG) github.event_name: ${{ github.event_name }}"
echo "(DEBUG) github.event_path: ${{ github.event_path }}"
echo "(DEBUG) github.head_ref: ${{ github.head_ref }}"
echo "(DEBUG) github.job: ${{ github.job }}"
echo "(DEBUG) github.ref: ${{ github.ref }}"
echo "(DEBUG) github.repository: ${{ github.repository }}"
echo "(DEBUG) github.repository_owner: ${{ github.repository_owner }}"
echo "(DEBUG) github.run_id: ${{ github.run_id }}"
echo "(DEBUG) github.run_number: ${{ github.run_number }}"
echo "(DEBUG) github.sha: ${{ github.sha }}"
echo "(DEBUG) github.token: ${{ github.token }}"
echo "(DEBUG) github.workflow: ${{ github.workflow }}"
echo "(DEBUG) github.workspace: ${{ github.workspace }}"
# NOTE - "actions/download-artifact" is not working for sharing data between workflows.
# - name: Download output
# uses: actions/download-artifact@v3
- name: Download output
uses: dawidd6/action-download-artifact@v6
with:
github_token: ${{secrets.GITHUB_TOKEN}}
workflow: check-outdated-content.yaml
workflow_conclusion: success
- name: Set up environment variables from the output
shell: bash
run: |
echo "(DEBUG) Install 'jq' to read json"
sudo apt-get install -y jq
echo "(DEBUG) Display files and directories"
tree
# Set the last changed directory as the output directory
OUTPUT_DIR=$(ls -tp | head -1)
# Read L10N_DIR and L10N_CODE from L10N_INFO.json
L10N_DIR=$(jq -r '.L10N_DIR' < ${OUTPUT_DIR}/L10N_INFO.json)
L10N_CODE=$(jq -r '.L10N_CODE' < ${OUTPUT_DIR}/L10N_INFO.json)
# Count outdated content
OUTDATED_CONTENT_COUNT=$(ls $OUTPUT_DIR | wc -l)
echo "(DEBUG) OUTPUT_DIR: ${OUTPUT_DIR}"
echo "(DEBUG) L10N_DIR: ${L10N_DIR}"
echo "(DEBUG) L10N_CODE: ${L10N_CODE}"
echo "(DEBUG) OUTDATED_CONTENT_COUNT: ${OUTDATED_CONTENT_COUNT}"
# Set OUTPUT_DIR, L10N_DIR, L10N_CODE, and OUTDATED_CONTENT_COUNT as environment variables
# Ref: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
echo "OUTPUT_DIR=${OUTPUT_DIR}" >> $GITHUB_ENV
echo "L10N_DIR=${L10N_DIR}" >> $GITHUB_ENV
echo "L10N_CODE=${L10N_CODE}" >> $GITHUB_ENV
echo "OUTDATED_CONTENT_COUNT=${OUTDATED_CONTENT_COUNT}" >> $GITHUB_ENV
- name: Generate a report markdown
if: ${{ env.OUTDATED_CONTENT_COUNT > 0 }}
shell: bash
run: |
FILE_LIST=$(find ${OUTPUT_DIR} -name '*.md')
# Create report.md
touch report.md
# Generate markdown
echo "This is an issue to track and reflect updates of English content. Please, check the files below as they may have been improved." >> report.md
echo "" >> report.md
echo "NOTICE - The following outdated content should be resolved before the next L10n branch updates." >> report.md
echo "" >> report.md
echo "### Files to check" >> report.md
for FILE in ${FILE_LIST}; do
FILE_NAME="${FILE#${OUTPUT_DIR}}"
echo "- [ ] ${FILE_NAME}" >> report.md
done
echo "" >> report.md
echo "### Changes in each file" >> report.md
for FILE in ${FILE_LIST}; do
FILE_NAME="${FILE#${OUTPUT_DIR}}"
echo "#### ${FILE_NAME}" >> report.md
echo "- en: https://github.com/${{ github.repository }}/blob/main/content/en/${FILE_NAME}" >> report.md
echo "- ${{ env.L10N_CODE }}: https://github.com/${{ github.repository }}/blob/dev-${{ env.L10N_CODE }}/${{ env.L10N_DIR }}${FILE_NAME}" >> report.md
echo "" >> report.md
# The collapsible section is applied to improve the readability of the report.
# Apply collapsible section in case the number of lines is greater than 20.
LINES=$(wc -l < ${FILE})
if [[ "$LINES" -gt "20" ]]; then
echo "<details>" >> report.md
echo "<summary><b>Diff in detail</b></summary>" >> report.md
echo "" >> report.md
echo "\`\`\`diff" >> report.md
cat ${FILE} >> report.md
echo "\`\`\`" >> report.md
echo "</details>" >> report.md
echo "" >> report.md
else
echo "\`\`\`diff" >> report.md
cat ${FILE} >> report.md
echo "\`\`\`" >> report.md
echo "" >> report.md
fi
done
echo "The end of report" >> report.md
- name: Create an issue from the report
uses: peter-evans/create-issue-from-file@v5
with:
title: "[${{ env.L10N_CODE }}] A report to track and reflect updates of English content"
content-filepath: report.md
labels: |
outdated
lang/${{ env.L10N_CODE }}