Skip to content

Instantly share code, notes, and snippets.

@mickmister
Last active February 15, 2024 08:13
Show Gist options
  • Save mickmister/9ded832b3f26bb7bc69e0198d8b53ebe to your computer and use it in GitHub Desktop.
Save mickmister/9ded832b3f26bb7bc69e0198d8b53ebe to your computer and use it in GitHub Desktop.

Uploads a plugin CI artifact to a Mattermost server. You can modify the plugin-install-gh-artifact.sh how you see fit, to connect with your MM admin account.

First you'll need to install and configure the GitHub CLI tool https://cli.github.com

Usage:

./plugin-install-gh-artifact.sh (MM site URL) (actions workflow run URL)


./plugin-install-gh-artifact.sh https://app-rhs-view-builder.test.mattermost.cloud https://github.com/mattermost/mattermost-plugin-jira/actions/runs/6112604241

Go to a PR's CI checks, and copy the URL from the ci / plugin-ci / build (pull_request) job. Use this value as the actions workflow run URL parameter above.

image

alias mmctl=~/mattermost/mattermost-server/server/bin/mmctl
# or make sure mmctl is in your PATH
directory="plugin-download-directory"
rm -rf $directory
mkdir -p $directory
USERNAME=sysadmin
PASSWORD=Sys@dmin123
MM_SITE_URL=$1
GH_ACTIONS_RUN_URL=$2
repo=$(echo $GH_ACTIONS_RUN_URL | cut -d '/' -f 1-5)
runNumber=$(echo $GH_ACTIONS_RUN_URL | cut -d '/' -f 8)
echo $PASSWORD > password-file.txt
mmctl auth login $MM_SITE_URL --username $USERNAME --password-file password-file.txt --name $MM_SITE_URL || (echo "MM login failed" && exit 1)
rm password-file.txt
echo "Successfully logged into $MM_SITE_URL"
echo "Downloading artifacts for GH action run $runNumber."
gh run download $runNumber --dir $directory --repo $repo || (echo "artifact download failed" && exit 1)
filepath=$(find $directory -name "*.gz")
pluginid=$(echo $filepath | cut -d'/' -f 3 | rev | cut -d'-' -f2- | rev)
echo "Downloaded $pluginid plugin. Stored in directory '$directory'."
echo "Uploading $pluginid plugin to MM server"
mmctl plugin add $filepath --force || (echo "MM plugin upload failed" && exit 1)
mmctl plugin enable $pluginid || (echo "MM plugin enable failed" && exit 1)
rm -rf $directory
@avas27JTG
Copy link

@mickmister For using the alias mmctl in the script, we should write it as $mmctl otherwise, on Ubuntu, it gives the error mmctl: command not found.
Not sure about how it behaves on mac.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment