Build Addon - Manual #115
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 : Build Addon - Manual | |
on: | |
workflow_dispatch: | |
inputs: | |
environment: | |
description: 'Environment To Deploy Addons' | |
required: true | |
type: choice | |
options: | |
- none | |
- production | |
- staging | |
- prestaging | |
- devtesting | |
- blackpearl | |
- vikings | |
- demons | |
- development | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: "0" | |
- name: Set environment variables | |
run: | | |
echo "BLACKPEARL_ADDON_URL=https://blackpearl-kibbutz.testsigma.com" >> $GITHUB_ENV | |
echo "VIKING_ADDON_URL=https://vikings-kibbutz.testsigma.com" >> $GITHUB_ENV | |
echo "DEMONS_ADDON_URL=https://demons-kibbutz.testsigma.com" >> $GITHUB_ENV | |
echo "DEVELOPMENT_ADDON_URL=https://development-kibbutz.testsigma.com" >> $GITHUB_ENV | |
echo "DEVTESTING_ADDON_URL=https://devtesting-kibbutz.testsigma.com" >> $GITHUB_ENV | |
echo "PRESTAGING_ADDON_URL=https://prestaging-kibbutz.testsigma.com" >> $GITHUB_ENV | |
echo "STAGING_ADDON_URL=https://staging-kibbutz.testsigma.com" >> $GITHUB_ENV | |
echo "PROD_ADDON_URL=https://kibbutz.testsigma.com" >> $GITHUB_ENV | |
echo "GIT_BRANCH=dev" >> $GITHUB_ENV | |
- name: SSH repo access | |
uses: webfactory/ssh-agent@v0.5.4 | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY}} | |
- name: Setup Java version | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '11' | |
distribution: 'zulu' | |
- name: Install xmlstarlet | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y xmlstarlet | |
- name: Build and commit changes | |
run: | | |
echo "Environment value: ${{ github.event.inputs.environment }} " | |
directories=$(find . -mindepth 1 -maxdepth 1 -type d -exec basename {} \;) | |
echo $directories; | |
for dir in $directories; do | |
if [[ $dir != *"."* ]]; then | |
echo "Setting Variables $dir" | |
cd $dir | |
version=$(xmlstarlet sel -t -v "/*[local-name()='project']/*[local-name()='version']" -n pom.xml) | |
artifactId=$(xmlstarlet sel -t -v "/*[local-name()='project']/*[local-name()='artifactId']" -n pom.xml) | |
version_dir=build/$version | |
archival="$artifactId"_source.zip | |
echo "Building $dir With latest version : $version" | |
mvn clean install | |
echo "Archiving the build files to $archival" | |
zip -r $archival . -x "build/*" | |
echo "Creating an directory for version : $version_dir" | |
sudo mkdir -p $version_dir | |
echo "Copy build files to the location : $version_dir " | |
sudo mv $archival $version_dir/ | |
sudo cp target/$artifactId.jar target/original-$artifactId.jar $version_dir/ | |
echo "Committing the file changes" | |
ls $version_dir | |
echo "Github Actor : ${{ github.actor }}" | |
git config --global user.email "${{ github.actor }}@users.noreply.github.com" | |
git config --global user.name "${{ github.actor }}" | |
git branch -a | |
git checkout $GIT_BRANCH | |
git add . | |
git commit -m "build files added to the path $version_dir" | |
git push origin $GIT_BRANCH | |
cd $version_dir | |
ENVIRONMENT=${{ github.event.inputs.Environment }} | |
echo "Updating the $dir addon in stack $ENVIRONMENT" | |
if [[ "$ENVIRONMENT" == "production"* ]]; then | |
curl --location --request PUT '${{ env.PROD_ADDON_URL }}/api/v1/plugins' \ | |
--header 'Authorization: Bearer ${{ secrets.PROD_V1_TOKEN }}' \ | |
--form "sourceCode=@\"$archival\"" \ | |
--form 'buildTool="MAVEN"' \ | |
--form 'isDefault="true"' | |
elif [[ "$ENVIRONMENT" == "staging"* ]]; then | |
curl --location --request PUT '${{ env.STAGING_ADDON_URL }}/api/v1/plugins' \ | |
--header 'Authorization: Bearer ${{ secrets.STAGING_V1_TOKEN }}' \ | |
--form "sourceCode=@\"$archival\"" \ | |
--form 'buildTool="MAVEN"' \ | |
--form 'isDefault="true"' | |
elif [[ "$ENVIRONMENT" == "prestaging"* ]]; then | |
curl --location --request PUT '${{ env.PRESTAGING_ADDON_URL }}/api/v1/plugins' \ | |
--header 'Authorization: Bearer ${{ secrets.PRESTAGING_V1_TOKEN }}' \ | |
--form "sourceCode=@\"$archival\"" \ | |
--form 'buildTool="MAVEN"' \ | |
--form 'isDefault="true"' | |
elif [[ "$ENVIRONMENT" == "devtesting"* ]]; then | |
curl --location --request PUT '${{ env.DEVTESTING_ADDON_URL }}/api/v1/plugins' \ | |
--header 'Authorization: Bearer ${{ secrets.DEVTESTING_V1_TOKEN }}' \ | |
--form "sourceCode=@\"$archival\"" \ | |
--form 'buildTool="MAVEN"' \ | |
--form 'isDefault="true"' | |
elif [[ "$ENVIRONMENT" == "blackpearl"* ]]; then | |
curl --location --request PUT '${{ env.BLACKPEARL_ADDON_URL }}/api/v1/plugins' \ | |
--header 'Authorization: Bearer ${{ secrets.BLACKPEARL_V1_TOKEN }}' \ | |
--form "sourceCode=@\"$archival\"" \ | |
--form 'buildTool="MAVEN"' \ | |
--form 'isDefault="true"' | |
elif [[ "$ENVIRONMENT" == "vikings"* ]]; then | |
curl --location --request PUT '${{ env.VIKING_ADDON_URL }}/api/v1/plugins' \ | |
--header 'Authorization: Bearer ${{ secrets.VIKING_V1_TOKEN }}' \ | |
--form "sourceCode=@\"$archival\"" \ | |
--form 'buildTool="MAVEN"' \ | |
--form 'isDefault="true"' | |
elif [[ "$ENVIRONMENT" == "demons"* ]]; then | |
curl --location --request PUT '${{ env.DEMONS_ADDON_URL }}/api/v1/plugins' \ | |
--header 'Authorization: Bearer ${{ secrets.DEMONS_V1_TOKEN }}' \ | |
--form "sourceCode=@\"$archival\"" \ | |
--form 'buildTool="MAVEN"' \ | |
--form 'isDefault="true"' | |
elif [[ "$ENVIRONMENT" == "development"* ]]; then | |
curl --location --request PUT '${{ env.DEVELOPMENT_ADDON_URL }}/api/v1/plugins' \ | |
--header 'Authorization: Bearer ${{ secrets.DEVELOPMENT_V1_TOKEN }}' \ | |
--form "sourceCode=@\"$archival\"" \ | |
--form 'buildTool="MAVEN"' \ | |
--form 'isDefault="true"' | |
fi | |
cd ../../../ | |
fi | |
done | |