Skip to content

Commit

Permalink
Actions workflow for ace-api (#14)
Browse files Browse the repository at this point in the history
* added workflow file for ace maven

* updated actions-maven-setting file

* updated workflow to deploy for master branch only
  • Loading branch information
kcs-bandihareesh authored Oct 11, 2024
1 parent 4229975 commit 2e909a1
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 0 deletions.
92 changes: 92 additions & 0 deletions .github/workflows/ace-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: ace-api

on:
push:
pull_request:
workflow_dispatch:

permissions:
contents: read
id-token: write

jobs:
test:
name: Test
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up JDK 8
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'

- name: Cache Maven dependencies
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven
- name: Setup Maven settings
run: |
mkdir -p ~/.m2
cp ./travis/actions-maven-settings.xml ~/.m2/settings.xml
sed -i "s/-SNAPSHOT/-github-build-${{ github.run_number }}/" pom.xml
- name: Run tests
run: mvn -e verify

- name: Display Surefire reports on failure
if: failure()
run: |
for F in target/surefire-reports/*.txt; do echo $F; cat $F; echo; done
deploy-snapshots:
name: Deploy Snapshots
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master' && github.event_name == 'push'

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up JDK 8
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'

- name: Cache Maven dependencies
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven
- name: Setup Maven settings
run: |
mkdir -p ~/.m2
cp ./travis/actions-maven-settings.xml ~/.m2/settings.xml
sed -i "s/-SNAPSHOT/-github-build-${{ github.run_number }}/" pom.xml
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
project_id: 'som-rit-infrastructure-prod'
workload_identity_provider: 'projects/294515190965/locations/global/workloadIdentityPools/github/providers/susom-github'
create_credentials_file: true
export_environment_variables: true
cleanup_credentials: true

- name: Set up OAuth2 access token for Maven
run: |
echo "ACCESS_TOKEN=$(gcloud auth print-access-token)" >> $GITHUB_ENV
- name: Deploy Snapshots
run: mvn --batch-mode -e -DskipTests=true deploy -s ~/.m2/settings.xml
69 changes: 69 additions & 0 deletions travis/actions-maven-settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">

<mirrors>
<mirror>
<mirrorOf>*,!artifact-registry</mirrorOf>
<url>https://repo.maven.apache.org/maven2/</url>
</mirror>
</mirrors>

<profiles>
<profile>
<id>ci-build</id>
<repositories>
<repository>
<id>artifact-registry</id>
<url>https://us-west1-maven.pkg.dev/som-rit-infrastructure-prod/ace-maven</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>

<activeProfiles>
<!-- Activate the profile for GitHub Actions -->
<activeProfile>github-actions</activeProfile>
</activeProfiles>

<servers>
<server>
<id>artifact-registry</id>
<username>oauth2accesstoken</username>
<password>${env.ACCESS_TOKEN}</password> <!-- Access token set as environment variable -->
</server>

<server>
<id>ossrh</id>
<username>${env.OSSRH_USERNAME}</username>
<password>${env.OSSRH_PASSWORD}</password>
</server>

<server>
<id>github.com</id>
<username>${env.GITHUB_USERNAME}</username>
<password>${env.GITHUB_TOKEN}</password>
</server>
</servers>
</settings>

0 comments on commit 2e909a1

Please sign in to comment.