Adapt Dictionaries #50
This file contains hidden or 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
| name: Adapt Dictionaries | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| branch: | |
| description: 'Branch to compact' | |
| required: false | |
| default: main | |
| check-spelling: | |
| description: 'Organization with check-spelling repository containing action.yml' | |
| required: false | |
| default: check-spelling | |
| manifest: | |
| description: 'Branch of check-spelling to use to retrieve action.yml' | |
| required: false | |
| default: main | |
| jobs: | |
| dictionaries: | |
| name: Select Dictionaries | |
| runs-on: ubuntu-latest | |
| outputs: | |
| dictionaries: ${{ steps.dictionaries.outputs.dictionaries }} | |
| steps: | |
| - name: checkout | |
| uses: actions/checkout@v4 | |
| - name: prepare archive | |
| shell: bash | |
| env: | |
| check_spelling: ${{ inputs.check-spelling }} | |
| manifest: ${{ inputs.manifest }} | |
| run: | | |
| : Prepare archive | |
| archive=$(mktemp -d)/archive.zip | |
| echo "archive=$archive" >> $GITHUB_ENV | |
| perl -pi -e 's<CHECK_SPELLING><$ENV{check_spelling}>;s<VERSION><$ENV{manifest}>' check-spelling-stub.yml | |
| zip "$archive" check-spelling-stub.yml | |
| - name: checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ inputs.branch }} | |
| - name: select dictionaries | |
| id: dictionaries | |
| shell: bash | |
| env: | |
| check_spelling: ${{ inputs.check-spelling }} | |
| manifest: ${{ inputs.manifest }} | |
| run: | | |
| : Select dictionaries | |
| action=$(mktemp) | |
| curl -sL "https://raw.githubusercontent.com/$check_spelling/check-spelling/refs/heads/$manifest/action.yml" > "$action" | |
| files=$(mktemp) | |
| ( | |
| cd dictionaries | |
| perl -ne 'next unless s/^\s*cspell://;my $file=$_; chomp $file; print if -e $file' "$action" | |
| ) > "$files" | |
| echo "dictionaries=[$(perl -ne 'next unless s/^(\S+)\n/"$1",/;print' "$files"|perl -pe 's/,$//')]" >> "$GITHUB_OUTPUT" | |
| (cd dictionaries; zip "$archive" $(cat $files)) | |
| echo "archive=$archive" >> "$GITHUB_OUTPUT" | |
| - name: upload | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: "dictionaries" | |
| retention-days: 1 | |
| path: ${{ steps.dictionaries.outputs.archive }} | |
| spelling: | |
| name: Check Spelling | |
| needs: dictionaries | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| dictionary: ${{fromJson(needs.dictionaries.outputs.dictionaries)}} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: retrieve files | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: dictionaries | |
| path: /tmp/archive | |
| - name: setup check | |
| env: | |
| dictionary: ${{ matrix.dictionary }} | |
| shell: bash | |
| run: | | |
| : Create sandbox | |
| mkdir -p .github/actions/spelling | |
| echo '\Q'"$dictionary"'\E$' > .github/actions/spelling/only.txt | |
| unzip /tmp/archive/*.zip "$dictionary" | |
| git init -b main | |
| git config user.name "check-spelling-bot" | |
| git config user.email "[email protected]" | |
| git add . | |
| git commit -m 'Prepare for check-spelling' | |
| : Create stub action | |
| mkdir -p ../actions/check-spelling | |
| unzip -p /tmp/archive/*.zip check-spelling-stub.yml > ../actions/check-spelling/action.yml | |
| - name: check-spelling | |
| id: spelling | |
| uses: ./../actions/check-spelling | |
| with: | |
| event_aliases: '{"workflow_dispatch":"push"}' | |
| suppress_push_for_open_pull_request: 1 | |
| checkout: false | |
| post_comment: 0 | |
| check_extra_dictionaries: '' | |
| largest_file: 1750000 | |
| quit_without_error: 1 | |
| disable_checks: noisy-file,word-collating | |
| - name: rename output | |
| id: rename | |
| shell: bash | |
| env: | |
| dictionary: ${{ matrix.dictionary }} | |
| run: | | |
| rm -rf .github | |
| if [ -s /tmp/*/unknown.words.txt ]; then | |
| mv /tmp/*/unknown.words.txt "$dictionary" | |
| else | |
| rm "$dictionary" | |
| fi | |
| rm -rf .git .github | |
| echo "name=$(echo "$dictionary" | tr '/' '-')" >> $GITHUB_ENV | |
| - name: collect output | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: reduced-dictionaries-${{ env.name }} | |
| path: . | |
| update: | |
| name: Update dictionaries | |
| needs: spelling | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: setup | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ inputs.branch }} | |
| - name: retrieve files | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: reduced-dictionaries-* | |
| merge-multiple: true | |
| path: /tmp/reduced/ | |
| - name: collate | |
| shell: bash | |
| run: | | |
| rsync -a /tmp/reduced/* dictionaries/ | |
| git config user.name "check-spelling-bot" | |
| git config user.email "[email protected]" | |
| git add -u | |
| git commit -m 'Reduce dictionaries' | |
| git push origin HEAD | |