Files
archived-osu-wiki/.github/workflows/continuous-integration.yml
2022-03-27 18:26:29 +02:00

169 lines
7.1 KiB
YAML

name: osu-wiki continuous integration
on:
push:
branches:
- master
pull_request:
branches:
- master
types:
- opened
- reopened
- synchronize
- edited
jobs:
ci:
name: changed files
runs-on: ubuntu-latest
steps:
- name: sparse checkout
shell: bash
run: |
# repository url, utilising provided github credentials
REPOSITORY="https://${{ github.actor }}:${{ github.token }}@github.com/${{ github.repository }}.git"
# merge commit ref name (with refs/heads/ stripped out)
BRANCH="${GITHUB_REF/#refs\/heads\//}"
git version
# clone without blobs; don't checkout to avoid fetching them anyway
git clone --filter=blob:none --no-checkout ${REPOSITORY} .
git config --local gc.auto 0
# set up sparse checkout
git sparse-checkout init
git sparse-checkout set '**/*.md' '**/.remark*' '**/*.json' '**/*.yaml' '.github/scripts' 'wiki/**/*'
# fetch the merge commit ref
git -c protocol.version=2 fetch --no-tags --prune --progress --depth=2 origin +${GITHUB_SHA}:refs/remotes/origin/${BRANCH}
git checkout --progress --force -B $BRANCH refs/remotes/origin/$BRANCH
- name: inspect binary file sizes
shell: bash
run: |
WARN_ON_SIZE=500000
ERROR_ON_SIZE=1000000
EXIT=0
while read file
do
echo "Checking ${file}..."
# git ls-tree will output:
# (file mode) (file type) (blob hash)<TAB>(file name)
# we're interested in the hash to pull the file's size using cat-file
hash=`git ls-tree ${{ github.sha }} "${file}" | awk -F ' ' '{ print $3 }'`
filesize=`git cat-file -s ${hash} 2>/dev/null`
if [[ ${filesize} -ge ${ERROR_ON_SIZE} ]]; then
echo "::error file=${file}::The size of the file exceeds 1MB. Compress it to optimise performance."
EXIT=1
elif [[ ${filesize} -ge ${WARN_ON_SIZE} ]]; then
echo "::warning file=${file}::The size of the file exceeds 500kB. Consider compressing it to optimise performance."
else
echo "::debug::File ${file} is ok."
fi
done < <(git diff --numstat --no-renames --diff-filter=d ${{ github.sha }}^ ${{ github.sha }} | grep -Poe '-\t-\t\K.+')
# git diff --numstat will output -<TAB>-<TAB>$filename for blobs
exit ${EXIT}
- name: setup node
uses: actions/setup-node@v1
- name: install remark
run: npm install
- name: run remark on changed files
# xargs is ran with -d '\n' to properly handle single and double quotes
# stdout is discarded (remark prints files being checked there)
run: git diff --diff-filter=d --name-only ${{ github.sha }}^ ${{ github.sha }} '*.md' | xargs -d '\n' npx remark -qf --no-stdout --silently-ignore --report=vfile-reporter-position --color
- name: setup Python
uses: actions/setup-python@v2
with:
python-version: "3.x"
- name: setup and run yamllint on .yaml and .md files
run: |
pip install yamllint
python .github/scripts/ci/run_yamllint.py --config .yamllint.yaml
- name: find broken wikilinks
shell: bash
env:
PULL_REQUEST_TAG: 'SKIP_WIKILINK_CHECK'
run: |
if ${{ contains(github.event.pull_request.body, env.PULL_REQUEST_TAG) }}; then
echo "::notice::Broken wikilink check suppressed ($PULL_REQUEST_TAG tag found in the pull request)"
exit 0
fi
ARTICLES=$( git diff --diff-filter=d --name-only ${{ github.sha }}^ ${{ github.sha }} "wiki/**/*.md" "news/*.md" )
python .github/scripts/ci/find_broken_wikilinks.py --target $ARTICLES
- name: check if translations are marked as outdated
shell: bash
env:
MASK: '---\n(.*\n)*?((outdated: |outdated_since: ).+\n)(.*\n)*?---'
PULL_REQUEST_TAG: 'SKIP_OUTDATED_CHECK'
run: |
# https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit
function echo_red () { echo -e "\e[0;31m$1\e[m"; }
function echo_green () { echo -e "\e[0;32m$1\e[m"; }
function print_error () {
echo "::error::You have edited some original articles (en.md), but did not outdate their translations:"
while read FILENAME; do
echo_red "* $FILENAME"
done <<< "$1"
echo -e "\nIf your changes DON'T NEED to be added to the translations, add $( echo_red $PULL_REQUEST_TAG ) anywhere in the description of your pull request."
echo -e "Otherwise, add the following to each article's front matter (https://osu.ppy.sh/wiki/en/Article_styling_criteria/Formatting#front-matter):\n"
echo_green "---"
echo_green "outdated: true"
if [[ -n "$2" ]]; then
echo_green "outdated_since: $2"
fi
echo_green "---"
}
function diff_files () { git diff --diff-filter=d --name-only ${{ github.sha }}^ ${{ github.sha }} "$@"; }
TRANSLATIONS=$( diff_files 'wiki/**/*.md' ':(exclude)*/en.md' )
ORIGINAL_ARTICLES=$( diff_files 'wiki/**/en.md' )
if [[ -z "$ORIGINAL_ARTICLES" ]]; then
echo "::notice::No original articles are edited, exiting"
exit 0
fi
if ${{ contains(github.event.pull_request.body, env.PULL_REQUEST_TAG) }}; then
echo "::notice::Outdated articles check suppressed ($PULL_REQUEST_TAG tag found in the pull request)"
exit 0
fi
# obtain directories of the modified en.md files, then list translations in them which:
# - are not modified in the PR (assuming that the author took care of them)
# - don't have the outdated/outdated_since markers
MISSED_TRANSLATIONS=$( echo "$ORIGINAL_ARTICLES" | tr \\n \\0 | xargs -0 dirname | sort -u | {
while read DIRECTORY; do
for ARTICLE_NAME in "$DIRECTORY"/*.md; do
if ! [[ "$ARTICLE_NAME" =~ \/(..|..-..)\.md ]] || [[ "$ARTICLE_NAME" =~ \/en\.md ]]; then
continue
fi
if ! [[ "$TRANSLATIONS" =~ "$ARTICLE_NAME" ]]; then
grep -LzP -e "$MASK" "$ARTICLE_NAME" || true # print only names of non-matching files, with multiline match (considering \n)
fi
done
done
})
if [[ -n "$MISSED_TRANSLATIONS" ]]; then
# get the first commit of the branch associated with the PR; GitHub's ubuntu-latest has curl/jq: https://github.com/actions/virtual-environments
FIRST_COMMIT_HASH=$( curl -sS ${{ github.event.pull_request.commits_url }}?per_page=1 | jq -r '.[0].sha' || true )
print_error "$MISSED_TRANSLATIONS" "$FIRST_COMMIT_HASH"
exit 1
else
echo -e "::notice::Either you have edited no original articles, or all translations are properly outdated"
fi