Skip to content

mel-habi in&out

mel-habi in&out #839

Workflow file for this run

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 numpy typing_extensions
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 scripts/sanitize.py
id: check-sanitize
continue-on-error: true
run: echo $HOME/files.json | xargs python3 scripts/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 checks = {
json: '${{ steps.check-json.outcome }}' === 'success',
commands: '${{ steps.check-commands.outcome }}' === 'success',
files: '${{ steps.check-files.outcome }}' === 'success',
filesSize: '${{ steps.check-files-size.outcome }}' === 'success',
sanitize: '${{ steps.check-sanitize.outcome }}' === 'success',
sanitizeCommit: '${{ steps.check-sanitize-commit.outcome }}' === 'success',
};
const messages = {
commands: 'Check if you have the Hall-Voice on your intra shop',
json: '/custom/login.json file is present',
filesSize: 'Audio files are under 1 Mo',
files: '20 max audio files',
sanitize: 'Volume reduced and audio files trimmed by sanitize',
sanitizeCommit: 'Sanitized sound committed',
};
let message = `CI:\n`;
for (const [key, description] of Object.entries(messages)) {
message += ` - ${checks[key] ? '✅' : '❌'} ${description}\n`;
}
if (checks.commands && checks.json && checks.files && checks.filesSize) {
message += `\n - ⌛ Everything looks good, awaiting staff approval\n`;
} else {
message += `\n - ❌ Something went wrong, check your PR\n`;
}
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: message,
});
const failureMessages = {
json: '.json file is missing',
commands: 'HallVoice check on intra shop KO',
files: 'More than 20 songs',
filesSize: 'Mp3 file is over 1 Mo',
};
for (const [key, failureMessage] of Object.entries(failureMessages)) {
if (!checks[key]) {
core.setFailed(failureMessage);
}
}