Feat[TE-15256]: Image based Actions addon #42
Workflow file for this run
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 - Automation | |
on: | |
pull_request: | |
types: [closed] | |
jobs: | |
build: | |
if: github.event.pull_request.merged == true | |
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: Detect changed directories | |
id: changes | |
run: | | |
changed_files=$(git diff --name-only "${{ github.event.pull_request.base.sha }}" "${{ github.event.pull_request.head.sha }}") | |
echo "Changed files : $changed_files" | |
changed_dirs=$(dirname $changed_files | sort -u) | |
echo "Changed dirs : $changed_dirs" | |
root_dirs=() | |
for dir in $changed_dirs; do | |
if [[ $dir != *"."* ]]; then | |
relative_dir="$dir" | |
echo "Relative : $relative_dir" | |
while [[ ! -f "$relative_dir/pom.xml" ]]; do | |
relative_dir=$(dirname "$relative_dir") | |
echo "-- relative : $relative_dir" | |
done | |
if [[ -f "$relative_dir/pom.xml" ]]; then | |
root_dirs+=("$relative_dir") | |
fi | |
fi | |
done | |
echo "::set-output name=directories::${root_dirs[@]}" | |
- name: Display changed directories | |
run: | | |
echo "Changed directories: ${{ steps.changes.outputs.directories }}" | |
- name: Build and commit changes | |
run: | | |
for dir in ${{ steps.changes.outputs.directories }}; do | |
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 | |
echo "Updating the $dir addon in stacks" | |
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"' | |
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"' | |
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"' | |
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"' | |
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"' | |
done |