Skip to content

Update OWC 2025 (#13814) #4

Update OWC 2025 (#13814)

Update OWC 2025 (#13814) #4

name: Post-merge outdate processing
on:
push:
branches:
- master
paths:
- "**/en.md"
- "**/en.yaml"
jobs:
process-outdated-files:
name: Process outdated files after merge
runs-on: ubuntu-latest
if: github.repository == 'ppy/osu-wiki'
permissions:
contents: write
actions: read
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: 1475412
private-key: ${{ secrets.OUTDATER_APP_SECRET }}
# Because the action is triggered by pushes to `master` to cover both standalone and merge commits, and we need
# to fetch DO_NOT_OUTDATE rules from the PR's body, this is one way of doing it, because in case of push events,
# `github.event.pull_request` is `null` even if there was an associated PR.
# For data format, see: https://docs.github.com/en/rest/commits/commits#list-pull-requests-associated-with-a-commit
- name: Read pull request data
uses: actions/github-script@v6
id: read-pr-data
with:
script: |
return (
await github.rest.repos.listPullRequestsAssociatedWithCommit({
commit_sha: context.sha,
owner: context.repo.owner,
repo: context.repo.repo,
})
).data[0];
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
- name: Set up Python
uses: actions/setup-python@v5
with:
cache: pip
cache-dependency-path: requirements.txt
python-version: "3.11"
- name: Set up Python CI dependencies
run: pip install -r requirements.txt
# Read DO_NOT_OUTDATE rules, feed them to the tool, and commit and push the result.
# The following rules are supported, with the wiki/ prefix optionally omitted:
#
# # Individual translations
# DO_NOT_OUTDATE: wiki/Path/To/Article/es.md
#
# # All translations of a single article, NOT including nested articles
# DO_NOT_OUTDATE: wiki/Article
#
# # Fnmatch masks
# DO_NOT_OUTDATE: wiki/*/es.md
# DO_NOT_OUTDATE: *
#
# # Several paths, separated by "," (comma, no space)
# DO_NOT_OUTDATE: wiki/{Article,Other_article,Yet_another_article}/es.md
# DO_NOT_OUTDATE: wiki/{Article,Other_article}/{es,jp}.md
#
# # Several rules on a line, separated by "+" (plus sign, spaces are optional)
# DO_NOT_OUTDATE: wiki/Article + wiki/Other_article/es.md + wiki/*/ru.md
- name: Process outdated articles
id: process-articles
env:
PULL_REQUEST_BODY: ${{ steps.read-pr-data.outputs.result && fromJson(steps.read-pr-data.outputs.result).body }}
PULL_REQUEST_NUMBER: ${{ steps.read-pr-data.outputs.result && fromJson(steps.read-pr-data.outputs.result).number }}
run: |
exclude_args=()
exclude_list=""
if [ -n "$PULL_REQUEST_BODY" ]; then
while IFS= read -r line; do
if [[ "$line" =~ DO_NOT_OUTDATE:[[:space:]]*(.+) ]]; then
IFS='+' read -ra items <<< "${BASH_REMATCH[1]}"
for item in "${items[@]}"; do
item_clean=$( echo "$item" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' )
exclude_args+=( "--exclude=${item_clean}" )
exclude_list="${exclude_list}--exclude=${item_clean}"$'\n'
done
fi
done <<< "$PULL_REQUEST_BODY"
fi
if [ -n "$exclude_list" ]; then
echo 'exclude_list<<EOF' >> $GITHUB_OUTPUT
echo "$exclude_list" >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
else
echo "exclude_list=" >> $GITHUB_OUTPUT
fi
osu-wiki-tools check-outdated-articles \
--autofix \
--base-commit "${{ github.sha }}~1" \
--outdated-since ${{ github.sha }} \
"${exclude_args[@]}"
if [ -z "$( git status -s )" ]; then
exit 0
fi
if [ -n "$PULL_REQUEST_NUMBER" ]; then
action_trigger="pull request #${PULL_REQUEST_NUMBER}"
else
action_trigger="commit ${{ github.sha }}"
fi
action_url="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/attempts/${{ github.run_attempt }}"
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git commit -a -m "Mark translations as outdated after $action_trigger
Generated by: $action_url"
for attempt in {1..3}; do
if git pull --rebase --strategy-option=theirs origin master && git push origin master; then
break
fi
if [ $attempt -lt 3 ]; then
echo "Attempt $attempt failed, retrying..."
sleep 2
else
echo "All retries failed -- couldn't pull/push onto $( git log -1 origin/master )"
git diff origin/master
exit 1
fi
done
- name: Create summary
run: |
exclude_rules="${{ steps.process-articles.outputs.exclude_list }}"
if [ -n "$exclude_rules" ]; then
echo "**Exclude rules applied:**" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "$exclude_rules" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
else
echo "**Status:** No exclude rules found, processed all changed files" >> $GITHUB_STEP_SUMMARY
fi