Skip to content

Commit

Permalink
cloudhub2 deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandramartinez committed May 1, 2024
1 parent e5484e8 commit 5627506
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 147 deletions.
122 changes: 31 additions & 91 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,98 +1,38 @@
name: Build and Deploy to Sandbox
name: Publish to Exchange & Deploy to CH2.0

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
branches: [ cloudhub2 ]

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout this repo
uses: actions/checkout@v3
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Set up JDK 1.8
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 8
- name: Test with Maven
env:
nexus_username: ${{ secrets.nexus_username }}
nexus_password: ${{ secrets.nexus_password }}
KEY: ${{ secrets.decryption_key }}
run: mvn test --settings .maven/settings.xml -Dsecure.key="$KEY"
- name: Upload MUnit reports
uses: actions/upload-artifact@v3
with:
name: munit-test-reports
path: target/site/munit/coverage/

jobs:
build:
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout this repo
uses: actions/checkout@v3
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Set up JDK 1.8
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 8
- name: Build with Maven
run: mvn -B package --file pom.xml -DskipMunitTests
- name: Stamp artifact file name with commit hash
run: |
artifactName1=$(ls target/*.jar | head -1)
commitHash=$(git rev-parse --short "$GITHUB_SHA")
artifactName2=$(ls target/*.jar | head -1 | sed "s/.jar/-$commitHash.jar/g")
mv $artifactName1 $artifactName2
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: artifacts
path: target/*.jar

deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout this repo
uses: actions/checkout@v3
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- uses: actions/download-artifact@v3
with:
name: artifacts
- name: Deploy to Sandbox
env:
USERNAME: ${{ secrets.anypoint_platform_username }}
PASSWORD: ${{ secrets.anypoint_platform_password }}
KEY: ${{ secrets.decryption_key }}
run: |
artifactName=$(ls *.jar | head -1)
mvn deploy -DskipMunitTests -DmuleDeploy \
-Dmule.artifact=$artifactName \
-Danypoint.username="$USERNAME" \
-Danypoint.password="$PASSWORD" \
-Ddecryption.key="$KEY"
- name: Checkout this repo
uses: actions/checkout@v4

- name: Cache dependencies
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-maven-

- name: Set up JDK 1.8
uses: actions/setup-java@v4
with:
distribution: "zulu"
java-version: 8

- name: Publish to Exchange
run: |
mvn deploy --settings .maven/settings.xml -DskipMunitTests \
-Dclient.id="${{ secrets.CONNECTED_APP_CLIENT_ID }}" \
-Dclient.secret="${{ secrets.CONNECTED_APP_CLIENT_SECRET }}"
- name: Deploy to CloudHub 2.0
run: |
mvn deploy --settings .maven/settings.xml -DskipMunitTests -DmuleDeploy \
-Dclient.id="${{ secrets.CONNECTED_APP_CLIENT_ID }}" \
-Dclient.secret="${{ secrets.CONNECTED_APP_CLIENT_SECRET }}"
-Ddecryption.key="${{ secrets.DECRYPTION_KEY }}"
29 changes: 4 additions & 25 deletions .maven/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,12 @@
</pluginGroups>

<servers>
<!-- connected app's required scopes: https://help.salesforce.com/s/articleView?id=001119708&type=1 -->
<server>
<id>MuleRepository</id>
<username>${nexus_username}</username>
<password>${nexus_password}</password>
<id>Repository</id> <!-- make sure this matches the serverId property in pom.xml -->
<username>~~~Client~~~</username>
<password>${client.id}~?~${client.secret}</password> <!-- these come from the build.yml and your github secrets -->
</server>
</servers>

<profiles>
<profile>
<id>Mule</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>MuleRepository</id>
<name>MuleRepository</name>
<url>https://repository.mulesoft.org/nexus-ee/content/repositories/releases-ee/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
</settings>
79 changes: 48 additions & 31 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mycompany</groupId>
<groupId>4500658a-7637-4fcf-bc7d-51d1feb28edb</groupId> <!-- make sure to add your business group ID here -->
<artifactId>github-actions</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.0.0</version> <!-- this has to change EVERY TIME you want to re-deploy -->
<packaging>mule-application</packaging>

<name>github-actions</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<app.runtime>4.4.0</app.runtime>
<mule.maven.plugin.version>3.8.0</mule.maven.plugin.version>
<app.name>amartinez17-github-actions</app.name>
<mule.maven.plugin.version>4.1.1</mule.maven.plugin.version> <!-- use at least v4.1.0 -->
<env>Sandbox</env>
<munit.version>2.3.13</munit.version>
<region>Cloudhub-US-East-1</region> <!-- make sure it's one of these Target Names: https://docs.mulesoft.com/cloudhub-2/ch2-architecture#regions-and-dns-records -->
<serverId>Repository</serverId> <!-- can be whatever you want, just make sure it matches the settings.xml -->
<munit.version>3.1.0</munit.version>
</properties>

<build>
Expand All @@ -28,31 +25,32 @@
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<cloudHubDeployment>
<uri>https://anypoint.mulesoft.com</uri>
<muleVersion>${app.runtime}</muleVersion>
<username>${anypoint.username}</username>
<password>${anypoint.password}</password>
<applicationName>${app.name}</applicationName>
<environment>${env}</environment>
<workerType>MICRO</workerType>
<region>us-east-2</region>
<workers>1</workers>
<objectStoreV2>true</objectStoreV2>
<!-- Start: SECURED PROPERTIES CI/CD -->
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<classifier>mule-application</classifier>
<cloudhub2Deployment>
<uri>https://anypoint.mulesoft.com</uri>
<provider>MC</provider>
<environment>${env}</environment>
<target>${region}</target>
<server>${serverId}</server> <!-- this is where our credentials will be stored -->
<applicationName>${project.artifactId}</applicationName>
<replicas>1</replicas>
<vCores>0.1</vCores>
<deploymentSettings>
<generateDefaultPublicUrl>true</generateDefaultPublicUrl>
</deploymentSettings>
<!-- Start: SECURED PROPERTIES CI/CD -->
<properties>
<secure.key>${decryption.key}</secure.key>
</properties>
<!-- End: SECURED PROPERTIES CI/CD -->
</cloudHubDeployment>
<classifier>mule-application</classifier>
</configuration>
</plugin>
</cloudhub2Deployment>
</configuration>
</plugin>
<plugin>
<groupId>com.mulesoft.munit.tools</groupId>
<artifactId>munit-maven-plugin</artifactId>
Expand Down Expand Up @@ -138,7 +136,7 @@

<repositories>
<repository>
<id>anypoint-exchange-v3</id>
<id>anypoint-exchange-v3</id> <!-- make sure to use v3 -->
<name>Anypoint Exchange</name>
<url>https://maven.anypoint.mulesoft.com/api/v3/maven</url>
<layout>default</layout>
Expand All @@ -149,6 +147,14 @@
<url>https://repository.mulesoft.org/releases/</url>
<layout>default</layout>
</repository>
<!-- START: needed for ch2 deployment -->
<repository>
<id>${serverId}</id>
<name>Private Exchange repository</name>
<url>https://maven.anypoint.mulesoft.com/api/v3/organizations/${project.groupId}/maven</url>
<layout>default</layout>
</repository>
<!-- END: needed for ch2 deployment -->
</repositories>

<pluginRepositories>
Expand All @@ -163,4 +169,15 @@
</pluginRepository>
</pluginRepositories>

<!-- START: needed for ch2 deployment -->
<distributionManagement>
<repository>
<id>${serverId}</id>
<name>Corporate Repository</name>
<url>https://maven.anypoint.mulesoft.com/api/v3/organizations/${project.groupId}/maven</url>
<layout>default</layout>
</repository>
</distributionManagement>
<!-- END: needed for ch2 deployment -->

</project>

0 comments on commit 5627506

Please sign in to comment.