Skip to content

Commit

Permalink
Full extraction with ms3 v2.4.1, including chords facet; added pre-co…
Browse files Browse the repository at this point in the history
…mmit hook (workflow v4.3) (#20)
  • Loading branch information
johentsch authored Dec 5, 2023
2 parents d8f900f + efa0c28 commit 63de987
Show file tree
Hide file tree
Showing 76 changed files with 10,491 additions and 1,646 deletions.
82 changes: 82 additions & 0 deletions .github/workflows/helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import argparse
import re
import os
def create_new_tag(tag, update_major):
if not (re.match(r'^v\d+\.\d+$', tag)):
raise Exception(f'tag: {tag} is not giving in the correct format e.i v0.0')

# Notice that this could make a tag version of three digits become two digits
# e.i 3.2.1 -> 3.3
digits_tags = (re.match(r'^v\d+\.\d+', tag)).group()[1::].split('.')
if len(digits_tags) != 2:
raise Exception(f'tag: {tag} must contain two version digits')

major_num = int(digits_tags[0])
minor_num = int(digits_tags[1])
if update_major:
print(f"Label detected to update major version")
major_num += 1
minor_num = 0
else:
minor_num += 1
return f"v{major_num}.{minor_num}"

def store_tag(tag):
with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:
print(f'new_tag={tag}', file=fh)

def update_file_with_tag(f_name, old_tag, new_tag):
if os.path.isfile(f_name):
try:
with open(f_name, "r",encoding="utf-8") as f:
data = f.read()
data = data.replace(old_tag, new_tag)
with open(f_name, "w",encoding="utf-8") as f:
f.write(data)
except Exception as e:
print(e)
else:
print(f"Warning: {f_name} doest exist at the current path {os.getcwd()}")

def main(args):
tag = args.tag
new_tag = "v2.0"
if not tag:
print(f"Warning: a latest release with a tag does not exist in current repository, starting from {new_tag}")
else:
new_tag = create_new_tag(tag,args.update_major_ver)
print(f"Repository with tag: {tag}, creating a new tag with: {new_tag}")
update_file_with_tag(".zenodo.json", tag, new_tag)
update_file_with_tag("CITATION.cff", tag, new_tag)
update_file_with_tag("README.md", tag, new_tag)
store_tag(new_tag)

def run():
args = parser.parse_args()
main(args)


def str_to_bool(value):
if value.lower() == "true":
return True
elif value.lower() == "false":
return False
else:
raise Exception(
f"Error: value {value} as argument is not accepted\n"
f"retry with true or false"
)

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--tag", type=str,
help="Require: latest tag",
required=True
)
parser.add_argument(
"--update_major_ver", type=str_to_bool,
help="Require: boolean to update the major tag number",
required=True
)
run()
72 changes: 72 additions & 0 deletions .github/workflows/version_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
on:
pull_request:
types:
- closed

jobs:
if_merged:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:

- name: Checkout corpus repository
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.MS3_BOT_TOKEN }}
ref: "${{ github.event.pull_request.base.ref }}"
submodules: recursive

- name: "Get latest tag version"
id: tag
continue-on-error: true
run: |
res=$(git tag -l --sort=-v:refname | grep --invert-match '\^' | head -n 1)
echo "tag_version=${res}" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.MS3_BOT_TOKEN }}

- name: "Generate a new tag version"
id: generate_tag
run: |
major_in_PR="${{ contains(github.event.pull_request.labels.*.name, 'major_version')}}"
python .github/workflows/helper.py --tag "${{ steps.tag.outputs.tag_version }}" --update_major_ver "$major_in_PR"
- name: Setup Github credentials & push zenodo, citation and README changes
continue-on-error: true
run: |
git config --global user.name "ms3-bot"
git config --global user.email [email protected]
if [[ -f .zenodo.json ]]; then
git add .zenodo.json
fi
if [[ -f CITATION.cff ]]; then
git add CITATION.cff
fi
if [[ -f README.md ]]; then
git add README.md
fi
git commit -m 'chore: files updated with tag: ${{ steps.generate_tag.outputs.new_tag }}'
git push
- name: "Create tag"
run: |
git tag -a "${{ steps.generate_tag.outputs.new_tag }}" -m "chore: files updated with tag: ${{ steps.generate_tag.outputs.new_tag }}"
git push origin "${{ steps.generate_tag.outputs.new_tag }}"
- name: "Get ms3 package & apply transform"
continue-on-error: true
run: |
pip install --upgrade pip
pip install ms3
ms3 transform -M -N -X -F -C -D
- uses: ncipollo/release-action@v1
with:
artifacts: "${{ github.event.repository.name }}.zip,\
${{ github.event.repository.name }}.datapackage.json,\
${{ github.event.repository.name }}.datapackage.errors"
body: "${{ github.event.pull_request.body }}"
name: "${{ github.event.pull_request.title }}"
tag: "${{ steps.generate_tag.outputs.new_tag }}"
makeLatest: "latest"
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
repos:
- repo: https://github.com/johentsch/ms3
rev: v2.4.0
hooks:
- id: review
args: [-M, -N, -C, -X, -F, -D, -c LATEST_VERSION, --fail]
190 changes: 190 additions & 0 deletions chords/op08n01.chords.resource.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
{
"name": "op08n01.chords",
"type": "table",
"path": "op08n01.chords.tsv",
"scheme": "file",
"format": "tsv",
"mediatype": "text/tsv",
"encoding": "utf-8",
"dialect": {
"csv": {
"delimiter": "\t"
}
},
"schema": {
"fields": [
{
"name": "mc",
"title": "Measure Count",
"description": "Running count of encoded <Measure> tags which do not necessarily express a full measure (e.g. in case of an anacrusis).",
"type": "integer",
"constraints": {
"required": true
}
},
{
"name": "mn",
"title": "Measure Number",
"description": "Measure number as printed in the score, computed from mc, dont_count and numbering_offset.",
"type": "string"
},
{
"name": "quarterbeats",
"title": "Offset from Beginning",
"description": "Distance of an event from the piece's beginning. By default, only second endings are taken into account to reflect the proportions of a simply playthrough without repeats.",
"type": "string",
"constraints": {
"pattern": "\\d+(?:\\/\\d+)?"
}
},
{
"name": "quarterbeats_all_endings",
"title": "Offset from Beginning (Including Endings)",
"description": "Distance from the piece's beginning, taking all endings into account for addressability purposes.",
"type": "string",
"constraints": {
"pattern": "\\d+(?:\\/\\d+)?"
}
},
{
"name": "duration_qb",
"title": "Duration in \u2669",
"description": "A float corresponding to duration * 4",
"type": "number"
},
{
"name": "mc_onset",
"title": "Offset within Encoded Measure",
"description": "Distance of an event from the beginning of the <Measure> tag.",
"type": "string",
"constraints": {
"pattern": "\\d+(?:\\/\\d+)?"
}
},
{
"name": "mn_onset",
"title": "Offset within Logical Measure",
"description": "Distance from the beginning of the logical measure. Relevant, for example, to compute the metric position of an event.",
"type": "string",
"constraints": {
"pattern": "\\d+(?:\\/\\d+)?"
}
},
{
"name": "event",
"type": "string"
},
{
"name": "timesig",
"title": "Time Signature",
"description": "Given as string, e.g. \"4/4\".",
"type": "string"
},
{
"name": "staff",
"title": "Staff",
"description": "Number of the staff where an event occurs, 1 designating the top staff.",
"type": "integer"
},
{
"name": "voice",
"title": "Notational Layer",
"description": "A number between 1-4 where 1 is MuseScore's default layer (blue), 2 the second layer in green with downward stems, etc.",
"type": "integer"
},
{
"name": "duration",
"title": "Duration",
"description": "As fraction of a whole note.",
"type": "string",
"constraints": {
"pattern": "\\d+(?:\\/\\d+)?"
}
},
{
"name": "gracenote",
"title": "Grace Note",
"description": "Name given to a type of grace note in the MuseScore encoding, e.g. \"grace16\"",
"type": "string"
},
{
"name": "nominal_duration",
"title": "Nominal Duration",
"description": "The duration corresponding to a note/rest value without applying any dots or n-tuplets, as fraction of a whole note. Multiplied with \"scalar\" to yield the actual duration of the note/rest.",
"type": "string",
"constraints": {
"pattern": "\\d+(?:\\/\\d+)?"
}
},
{
"name": "scalar",
"title": "Scalar",
"description": "Decimal value reflecting all dots and n-tuplets modifying the duration of a note/rest. Yields the actual duration when multiplied with \"nominal_duration\".",
"type": "string",
"constraints": {
"pattern": "\\d+(?:\\/\\d+)?"
}
},
{
"name": "chord_id",
"title": "Chord ID",
"description": "Row in the chords table.",
"type": "integer"
},
{
"name": "dynamics",
"type": "string"
},
{
"name": "articulation",
"type": "string"
},
{
"name": "staff_text",
"type": "string"
},
{
"name": "slur",
"title": "Slur",
"description": "IDs of active slurs that a chord falls under, as a tuple of integers.",
"type": "string"
},
{
"name": "crescendo_hairpin",
"type": "string"
},
{
"name": "decrescendo_hairpin",
"type": "string"
},
{
"name": "pedal",
"title": "Pedal Point",
"description": "Specified as Roman numeral.",
"type": "string"
},
{
"name": "Pedal_<sym>keyboardPedalPed</sym>",
"type": "string"
}
],
"facet": "chords",
"identifier": "XejHo1tti6VsNw",
"filepath": "chords/XejHo1tti6VsNw.schema.yaml",
"used_in": "op08n01"
},
"creator": {
"@context": "https://schema.org/",
"@type": "SoftwareApplication",
"@id": "https://pypi.org/project/ms3/",
"name": "ms3",
"description": "A parser for MuseScore 3 files and data factory for annotated music corpora.",
"author": {
"name": "Johannes Hentschel",
"@id": "https://orcid.org/0000-0002-1986-9545"
},
"softwareVersion": "2.4.1"
},
"git_revision": "d8f900f0ae0345c70b3766dcd141365001eb59dd",
"git_tag": "v2.0"
}
Loading

0 comments on commit 63de987

Please sign in to comment.