Skip to content

Commit

Permalink
Merge pull request #25850 from Eism/ci_deploy_to_musescore_com
Browse files Browse the repository at this point in the history
Ci. Deploy to musescore.com
  • Loading branch information
Eism authored Dec 16, 2024
2 parents 470f0af + a460200 commit 3f0b13c
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 5 deletions.
21 changes: 16 additions & 5 deletions .github/workflows/build_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,15 @@ jobs:
bash ./buildscripts/ci/tools/make_version_env.sh $BUILD_NUMBER
VERSION=$(cat ./build.artifacts/env/build_version.env)
GITHUB_ARTIFACT_NAME="MuseScore-${VERSION}"
VERSION_MAJOR_MINOR=$(echo "$VERSION" | cut -d '.' -f 1,2)
echo "github.repository: ${{ github.repository }}"
echo "BUILD_MODE=$BUILD_MODE" | tee -a $GITHUB_ENV
echo "BUILD_NUMBER=$BUILD_NUMBER" | tee -a $GITHUB_ENV
echo "DO_PUBLISH=$DO_PUBLISH" | tee -a $GITHUB_ENV
echo "VERSION=$VERSION" | tee -a $GITHUB_ENV
echo "VERSION_MAJOR_MINOR=$VERSION_MAJOR_MINOR" | tee -a $GITHUB_ENV
echo "GITHUB_ARTIFACT_NAME=$GITHUB_ARTIFACT_NAME" | tee -a $GITHUB_ENV
- name: Setup environment
Expand All @@ -82,11 +86,6 @@ jobs:
run: |
bash ./buildscripts/ci/backend/package.sh
- name: Publish to S3
if: env.DO_PUBLISH == 'true'
run: |
bash ./buildscripts/ci/backend/publish_to_s3.sh --s3_key ${{ secrets.S3_KEY_CONVERTER }} --s3_secret ${{ secrets.S3_SECRET_CONVERTER }}
- name: Build Docker
if: env.DO_PUBLISH == 'true'
run: |
Expand All @@ -97,6 +96,18 @@ jobs:
run: |
bash ./buildscripts/ci/backend/publish_to_registry.sh --token ${{ secrets.PACKAGES_PAT }}
- name: Deploy to musescore.com
if: env.DO_PUBLISH == 'true'
run: |
bash ./buildscripts/ci/backend/publish_to_s3.sh \
--s3_key ${{ secrets.S3_KEY_CONVERTER }} \
--s3_secret ${{ secrets.S3_SECRET_CONVERTER }} \
--stage ${{ inputs.build_mode }} \
--mu_version ${{ env.VERSION }} \
--mu_version_major_minor ${{ env.VERSION_MAJOR_MINOR }}
python3 ./buildscripts/ci/backend/deploy.py --mu_version ${{ env.VERSION }} --api_token ${{ secrets.JENKINS_API_TOKEN }}
- name: Upload artifacts on GitHub
if: ${{ always() }}
uses: actions/upload-artifact@v4
Expand Down
73 changes: 73 additions & 0 deletions buildscripts/ci/backend/deploy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-only
# MuseScore-Studio-CLA-applies
#
# MuseScore Studio
# Music Composition & Notation
#
# Copyright (C) 2021 MuseScore Limited
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import argparse
import sys

from jenkinsapi.jenkins import Jenkins

jenkins_url = "https://jenkins.mu.se/"
user = "e.ismailzada" # todo

build_job_name = "build_goosar"
deploy_job_name = "deploy_goosar"

def wait_for_job_to_finish(job, params):
qi = job.invoke(build_params=params)

# Block this script until build is finished
if qi.is_queued() or qi.is_running():
qi.block_until_complete()

build = qi.get_build()
print(build)

return build.is_good()

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Deploy to musescore.com")

parser.add_argument("--mu_version", type=str, help="MuseScore version", required=True)
parser.add_argument("--api_token", type=str, help="API Token", required=True)
args = parser.parse_args()

build_params = {"MS_VERSION": args.mu_version}
api_token = args.api_token

jenkins = Jenkins(jenkins_url, user, api_token)

# Trigger the build
jenkins.build_job(build_job_name, build_params)
build_job = jenkins[build_job_name]
if wait_for_job_to_finish(build_job, build_params):
print("Build finished")
else:
print("Build failed")
sys.exit(1)

# Trigger the deploy
jenkins.build_job(deploy_job_name, build_params)
deploy_job = jenkins[deploy_job_name]
if wait_for_job_to_finish(deploy_job, build_params):
print("Deploy finished")
else:
print("Deploy failed")
sys.exit(1)
43 changes: 43 additions & 0 deletions buildscripts/ci/backend/publish_to_s3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ S3_SECRET=""
S3_URL="s3://convertor.musescore.org"
ARTIFACTS_DIR=build.artifacts
ARTIFACT_PATH=""
STAGE="devel"
MU_VERSION=""
MU_VERSION_MAJOR_MINOR=""

while [[ "$#" -gt 0 ]]; do
case $1 in
--s3_key) S3_KEY="$2"; shift ;;
--s3_secret) S3_SECRET="$2"; shift ;;
--artifact) ARTIFACT_PATH="$2"; shift ;;
--stage) STAGE="$2"; shift ;;
--mu_version) MU_VERSION="$2"; shift ;;
--mu_version_major_minor) MU_VERSION_MAJOR_MINOR="$2"; shift ;;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
Expand All @@ -47,3 +53,40 @@ ARTIFACT_NAME=$(basename $ARTIFACT_PATH)
echo "=== Publish to S3 ==="

s3cmd put --acl-public --guess-mime-type "$ARTIFACT_PATH" "$S3_URL/$ARTIFACT_NAME"

echo "=== Edit configure file ==="

CONFIGURE_FILE="configure.json"
CONFIGURE_FILE_PATH="$ARTIFACTS_DIR/${CONFIGURE_FILE}"

s3cmd get "$S3_URL/$CONFIGURE_FILE" "$CONFIGURE_FILE_PATH"

ARTIFACT_NAME_NO_EXT="${ARTIFACT_NAME%.*}"

NEW_DISTR=$ARTIFACT_NAME
NEW_IMAGE_URL="ghcr.io/musescore/converter_4:${MU_VERSION}"
NEW_STAGE=$STAGE

if jq -e "has(\"$MU_VERSION_MAJOR_MINOR\")" "$CONFIGURE_FILE_PATH" > /dev/null; then
jq --arg version "$MU_VERSION_MAJOR_MINOR" \
--arg distr "$NEW_DISTR" \
--arg image_url "$NEW_IMAGE_URL" \
--arg stage "$NEW_STAGE" \
'(.[$version] // {}) |= {
distr: $distr,
image_url: $image_url,
stage: $stage
}' "$CONFIGURE_FILE_PATH" > "$CONFIGURE_FILE_PATH.tmp" && mv "$CONFIGURE_FILE_PATH.tmp" "$CONFIGURE_FILE_PATH"
else
jq --arg version "$MU_VERSION_MAJOR_MINOR" \
--arg distr "$NEW_DISTR" \
--arg image_url "$NEW_IMAGE_URL" \
--arg stage "$NEW_STAGE" \
'. + {($version): {
distr: $distr,
image_url: $image_url,
stage: $stage
}}' "$CONFIGURE_FILE_PATH" > "$CONFIGURE_FILE_PATH.tmp" && mv "$CONFIGURE_FILE_PATH.tmp" "$CONFIGURE_FILE_PATH"
fi

s3cmd put --acl-public --guess-mime-type "$CONFIGURE_FILE_PATH" "$S3_URL/$CONFIGURE_FILE"

0 comments on commit 3f0b13c

Please sign in to comment.