Generate medias from Musescore files #31
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: Generate medias from Musescore files | |
# Configures this workflow to run every time a change is pushed to the branch called `release`. | |
on: | |
workflow_dispatch: | |
jobs: | |
generate-medias: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
packages: read | |
container: | |
image: ghcr.io/soprodecarnaval/musicoteca:main | |
options: --user root --workdir /app | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
# - name: Create generator file | |
# shell: sh | |
# run: | | |
# find public/collection/ -type f -name "*.mscz" | jq -R -s 'split("\n") | map(select(.!="") | sub(".mscz";"") | {"in":"\(.).mscz", "out": [[ "\(.)_",".svg"],[ "\(.)_",".midi"],"\(.).midi","\(.).metajson"]})' > media-generation.json | |
# head media-generation.json | |
# - name: Create media files | |
# shell: sh | |
# run: | | |
# xvfb-run /squashfs-root/AppRun -j media-generation.json | |
# find public/collection/ -type f -name "*.svg" -a -name "*.midi" | head | |
# - name: Commit and push files | |
# shell: sh | |
# run: | | |
# git config --global --add safe.directory /__w/musicoteca/musicoteca | |
# git config --global user.email "musicoteca@github.com" | |
# git config --global user.name "GitHub Actions" | |
# git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} | |
# git add media-generation.json | |
# git add public/collection | |
# (git commit -m "[AUTO] Generating media files" && git push) || exit 0 | |
# env: | |
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
index-files: | |
runs-on: ubuntu-latest | |
needs: [generate-medias] | |
permissions: | |
contents: write | |
packages: read | |
container: | |
image: node:18.18.2-alpine3.18 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Index collection | |
run: | | |
mv public/collection /collection | |
npm install | |
npm run index-collection -- -i /collection -o public/collection | |
- name: Commit and push files | |
uses: actions/github-script@v5 | |
with: | |
script: | | |
github.rest.git | |
.createCommit({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
message: "[AUTO] Generating index file", | |
tree: await github.rest.git | |
.createTree({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
tree: [ | |
{ | |
path: "public/collection", | |
mode: "040000", | |
type: "tree", | |
sha: await github.rest.git | |
.getCommit({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
commit_sha: context.sha, | |
}) | |
.then( | |
(commit) => | |
commit.data.tree.find( | |
(tree) => tree.path === "public/collection" | |
).sha | |
), | |
}, | |
], | |
}) | |
.then((tree) => tree.data.sha), | |
parents: [context.sha], | |
}) | |
.then((commit) => | |
github.rest.git.updateRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: "heads/release", | |
sha: commit.data.sha, | |
}) | |
); | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |