rajout dossier/mp3 tauer #786
This file contains 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: Sanitize | |
on: | |
pull_request_target: | |
branches: [ master ] | |
paths: | |
- 'custom/*.json' | |
- 'mp3/**' | |
- '**.mp3' | |
workflow_dispatch: | |
jobs: | |
sanitize: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
repository: ${{ github.event.pull_request.head.repo.full_name }} | |
ref: ${{ github.head_ref }} | |
- name: Install sox, jq and pip packages | |
run: | | |
sudo apt-get -qq update | |
sudo apt-get -qq -y install libsox-fmt-mp3 sox jq | |
python3 -m pip install -r requirements.txt | |
- name: Get changed files | |
#uses: lots0logs/[email protected] | |
uses: Mineflash07/gh-action-get-changed-files@feature/support-pr-target-event # Remove as soon as PR is merged. See https://github.com/lots0logs/gh-action-get-changed-files/pull/22 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Run sanitize.py | |
id: check-sanitize | |
continue-on-error: true | |
run: echo $HOME/files.json | xargs python3 sanitize.py -v --db -10.0 -- | |
- name: Commit changes | |
id: check-sanitize-commit | |
continue-on-error: true | |
uses: stefanzweifel/git-auto-commit-action@v4 | |
with: | |
skip_checkout: true | |
# branch: ${{ github.event.pull_request.head.sha }} | |
file_pattern: ./mp3/ | |
commit_message: 'CI: Sanitize mp3' | |
commit_author: 'GitHub Actions <[email protected]>' | |
- name: Check if .json file is present | |
id: check-json | |
continue-on-error: true | |
run: jq -r '[.[] | select(startswith("custom") or startswith("mp3")) | split("/")[1] | split(".json")[0]] | unique[]' ${HOME}/files.json | xargs -I {} test -f "custom/{}.json" | |
- name: Check if there are less than 20 sounds | |
id: check-files | |
continue-on-error: true | |
run: jq -r '[.[] | select(startswith("custom") or startswith("mp3")) | split("/")[1] | split(".json")[0]] | unique[]' ${HOME}/files.json | xargs -I {} sh -c 'test $(find mp3/{} -type f | wc -l) -le 20' -- {} | |
- name: Check if student has bought Hall Voice Change on intra | |
id: check-commands | |
env: | |
API42_ID: ${{ secrets.API42_ID }} | |
API42_SECRET: ${{ secrets.API42_SECRET }} | |
continue-on-error: true | |
run: jq -r '[.[] | select(startswith("custom") or startswith("mp3")) | split("/")[1] | split(".json")[0]] | unique[]' ${HOME}/files.json | xargs python3 check-commands.py -v -- | |
- name: Check if files are under 1 Mo | |
id: check-files-size | |
continue-on-error: true | |
run: echo $HOME/files.json | xargs python3 check-files-size.py -v -- | |
- name: Post comment | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const checkJson = '${{ steps.check-json.outcome }}' == 'success' | |
const checkCommands = '${{ steps.check-commands.outcome }}' == 'success' | |
const checkFiles = '${{ steps.check-files.outcome }}' == 'success' | |
const checkFilesSize = '${{ steps.check-files-size.outcome }}' == 'success' | |
const checkSanitize = '${{ steps.check-sanitize.outcome }}' == 'success' | |
const checkSanitizeCommit = '${{ steps.check-sanitize-commit.outcome }}' == 'success' | |
var message = `CI: | |
- ${checkCommands ? '✅' : '❌'} Check if you have the Hall-Voice on your intra shop | |
- ${checkJson ? '✅' : '❌'} /custom/login.json file is present | |
- ${checkFilesSize ? '✅' : '❌'} Audio files are under 1 Mo | |
- ${checkFiles ? '✅' : '❌'} 20 max audio files | |
- ${checkSanitize ? '✅' : '❌'} Volume reduced and audio files trimed by sanitize | |
- ${checkSanitizeCommit ? '✅' : '❌'} Sanitized sound commited | |
` | |
if (checkCommands && checkJson && checkFilesSize && checkFiles) { | |
message += ` | |
- ⌛ Everything looks good, awaiting staff approval` | |
} else { | |
message += ` | |
- ❌ Something went wrong, check your PR` | |
} | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: message | |
}) | |
if (!checkJson) { | |
core.setFailed('.json file is missing') | |
} | |
if (!checkCommands) { | |
core.setFailed('HallVoice check on intra shop KO') | |
} | |
if (!checkFiles) { | |
core.setFailed('More than 20 songs') | |
} | |
if (!checkFilesSize) { | |
core.setFailed('Mp3 file is over 1 Mo') | |
} | |