Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: CI

on:
push:
branches: ['*']
pull_request:
branches: [main]
workflow_dispatch:
inputs:
java-version:
description: "Java version (or 'all' for full matrix)"
required: false
default: "11"

jobs:
test:
name: Test - Java ${{ matrix.java }}
runs-on: ${{ github.event.pull_request.head.repo.fork && 'ubuntu-latest' || 'ubuntu-x64' }}
if: github.repository_owner == 'twilio'
timeout-minutes: 20
permissions:
contents: read
id-token: write
strategy:
fail-fast: false
matrix:
java: ${{ github.event.inputs.java-version == 'all' && fromJson('[8, 11, 17, 21]') || fromJson(format('[{0}]', github.event.inputs.java-version || '11')) }}
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
fetch-depth: 0

- name: Artifactory OIDC
if: ${{ !github.event.pull_request.head.repo.fork }}
uses: twilio/sdk-actions/artifactory-oidc@4ffc0c647c8d692a8fff24d4f767b207c3d1222e # java_maven
with:
ecosystem: maven

- name: Set up Java
uses: actions/setup-java@e9fbacdec3bb3b6036605a3e6f7995d66773a8c6 # v3.14.2
with:
distribution: temurin
java-version: ${{ matrix.java }}
cache: maven

- run: mvn install -DskipTests=true -Dgpg.skip -Dmaven.javadoc.skip=true -B -V

- name: Run unit tests
run: mvn test -B

# - name: SonarCloud scan
# if: ${{ matrix.java == 11 && !github.event.pull_request.head.repo.fork && (github.event_name == 'pull_request' || github.ref_type == 'branch') }}
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# run: mvn org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=twilio_twilio-java
6 changes: 3 additions & 3 deletions .github/workflows/pr-lint.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# todo: whitelist or replace the action & enable it
name: Lint PR
on:
pull_request_target:
types: [ opened, edited, synchronize, reopened ]
workflow_dispatch:

jobs:
validate:
name: Validate title
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
- uses: amannn/action-semantic-pull-request@9ebc021bcf7ac66f840f985c84d0ef77afd5e8d9 # v5.5.1
with:
types: |
chore
Expand Down
86 changes: 86 additions & 0 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Cluster Tests and Release Readiness

on:
push:
branches: [gated-release]
schedule:
- cron: '0 15 * * 1' # 8AM PST every Monday
workflow_dispatch:

jobs:
cluster-test:
name: Cluster Tests
runs-on: ubuntu-x64
if: github.repository_owner == 'twilio'
timeout-minutes: 20
environment: production
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0

- name: Artifactory OIDC
uses: twilio/sdk-actions/artifactory-oidc@4ffc0c647c8d692a8fff24d4f767b207c3d1222e # java_maven
with:
ecosystem: maven

- name: Set up Java
uses: actions/setup-java@e9fbacdec3bb3b6036605a3e6f7995d66773a8c6 # v3.14.2
with:
distribution: temurin
java-version: '11'
cache: maven

- run: mvn install -DskipTests=true -Dgpg.skip -Dmaven.javadoc.skip=true -B -V

- name: Run cluster tests
env:
TWILIO_ACCOUNT_SID: ${{ secrets.TWILIO_ACCOUNT_SID }}
TWILIO_API_KEY: ${{ secrets.TWILIO_CLUSTER_TEST_API_KEY }}
TWILIO_API_SECRET: ${{ secrets.TWILIO_CLUSTER_TEST_API_KEY_SECRET }}
TWILIO_FROM_NUMBER: ${{ secrets.TWILIO_FROM_NUMBER }}
TWILIO_TO_NUMBER: ${{ secrets.TWILIO_TO_NUMBER }}
TWILIO_ORGS_CLIENT_ID: ${{ secrets.TWILIO_ORGS_CLIENT_ID }}
TWILIO_ORGS_CLIENT_SECRET: ${{ secrets.TWILIO_ORGS_CLIENT_SECRET }}
TWILIO_ORG_SID: ${{ secrets.TWILIO_ORG_SID }}
TWILIO_CLIENT_ID: ${{ secrets.TWILIO_CLIENT_ID }}
TWILIO_CLIENT_SECRET: ${{ secrets.TWILIO_CLIENT_SECRET }}
TWILIO_MESSAGE_SID: ${{ secrets.TWILIO_MESSAGE_SID }}
run: mvn test -Dtest=ClusterTest -B

deploy-dry-run:
name: Release Readiness Check
needs: [cluster-test]
runs-on: ubuntu-x64
if: github.repository_owner == 'twilio'
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0

- name: Artifactory OIDC
uses: twilio/sdk-actions/artifactory-oidc@4ffc0c647c8d692a8fff24d4f767b207c3d1222e # java_maven
with:
ecosystem: maven

- name: Set up Java
uses: actions/setup-java@e9fbacdec3bb3b6036605a3e6f7995d66773a8c6 # v3.14.2
with:
distribution: temurin
java-version: '11'
cache: maven

- run: mvn install -DskipTests=true -Dgpg.skip -Dmaven.javadoc.skip=true -B -V

- name: Build artifacts (dry run)
run: mvn clean package -DskipTests -B -Prelease -Dgpg.skip

- name: Dry run summary
run: |
PKG_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
echo "Built artifacts:"
ls -lh target/*.jar 2>/dev/null || echo "No artifacts found"
echo "Package version: $PKG_VERSION"
echo "--- DRY RUN COMPLETE ---"
142 changes: 51 additions & 91 deletions .github/workflows/test-and-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,110 +1,86 @@
name: Test and Deploy
name: Twilio Public release-maven

on:
push:
branches: [ '*' ]
tags: [ '*' ]
pull_request:
branches: [ main ]
schedule:
# Run automatically at 8AM PST Monday-Friday
- cron: '0 15 * * 1-5'
tags:
- '*'
workflow_dispatch:

jobs:
test:
name: Test
runs-on: ubuntu-latest
runs-on: ubuntu-x64
if: github.repository_owner == 'twilio'
timeout-minutes: 20
permissions:
contents: read
id-token: write
strategy:
matrix:
java: [ 8, 11, 17, 21 ]
java: [8, 11, 17, 21]
steps:
- name: Checkout twilio-java
uses: actions/checkout@v3
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0

- name: Artifactory OIDC
uses: twilio/sdk-actions/artifactory-oidc@4ffc0c647c8d692a8fff24d4f767b207c3d1222e # java_maven
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
ecosystem: maven

- name: Set up Java
uses: actions/setup-java@v3
uses: actions/setup-java@e9fbacdec3bb3b6036605a3e6f7995d66773a8c6 # v3.14.2
with:
distribution: 'temurin'
distribution: temurin
java-version: ${{ matrix.java }}
cache: 'maven'

- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
cache: maven

- run: mvn install -DskipTests=true -Dgpg.skip -Dmaven.javadoc.skip=true -B -V
- name: Run Unit Tests
- name: Run unit tests
run: mvn test -B

- name: Run Cluster Test
if: (!github.event.pull_request.head.repo.fork)
env:
TWILIO_ACCOUNT_SID: ${{ secrets.TWILIO_ACCOUNT_SID }}
TWILIO_API_KEY: ${{ secrets.TWILIO_CLUSTER_TEST_API_KEY}}
TWILIO_API_SECRET: ${{ secrets.TWILIO_CLUSTER_TEST_API_KEY_SECRET }}
TWILIO_FROM_NUMBER: ${{ secrets.TWILIO_FROM_NUMBER }}
TWILIO_TO_NUMBER: ${{ secrets.TWILIO_TO_NUMBER }}
TWILIO_ORGS_CLIENT_ID: ${{ secrets.TWILIO_ORGS_CLIENT_ID }}
TWILIO_ORGS_CLIENT_SECRET: ${{ secrets.TWILIO_ORGS_CLIENT_SECRET }}
TWILIO_ORG_SID: ${{ secrets.TWILIO_ORG_SID }}
TWILIO_CLIENT_ID: ${{ secrets.TWILIO_CLIENT_ID }}
TWILIO_CLIENT_SECRET: ${{ secrets.TWILIO_CLIENT_SECRET }}
TWILIO_MESSAGE_SID: ${{ secrets.TWILIO_MESSAGE_SID }}
run: mvn test -DTest="ClusterTest" -B

- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'

- name: SonarCloud Scan
if: ${{ (github.event_name == 'pull_request' || github.ref_type == 'branch') && matrix.java == 11 && !github.event.pull_request.head.repo.fork }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=twilio_twilio-java

deploy:
name: Deploy
if: success() && github.ref_type == 'tag'
needs: [ test ]
runs-on: ubuntu-latest
name: Publish to Maven Central
needs: [test]
runs-on: ubuntu-x64
if: success() && github.ref_type == 'tag' && github.repository_owner == 'twilio'
environment:
name: production
url: https://central.sonatype.com/artifact/com.twilio.sdk/twilio/${{ github.ref_name }}
Comment on lines +45 to +47

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block isn't setting an environment variable called name and url. It's telling GitHub to use the environment "production" https://github.com/twilio/twilio-java/settings/environments/19230766429/edit

If you want to add variables to that, you could add them to the environment itself: https://github.com/twilio/twilio-java/settings/environments/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes right. added vars to environment.

permissions:
contents: write
id-token: write
steps:
- name: Checkout twilio-java
uses: actions/checkout@v3
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
fetch-depth: 0

- name: Login to Docker Hub
uses: docker/login-action@v2
- name: Artifactory OIDC
uses: twilio/sdk-actions/artifactory-oidc@4ffc0c647c8d692a8fff24d4f767b207c3d1222e # java_maven
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_AUTH_TOKEN }}
ecosystem: maven

# - name: Login to Docker Hub
# uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 # v2
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_AUTH_TOKEN }}

# The expression strips off the shortest match from the front of the string to yield just the tag name as the output
- name: Get tagged version
run: echo "GITHUB_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

- name: Create GitHub Release
uses: sendgrid/dx-automator/actions/release@main
uses: sendgrid/dx-automator/actions/release@08b601b726671445abc798ed59881766ec8fefc6
with:
footer: '**[Maven](https://central.sonatype.com/artifact/com.twilio.sdk/twilio/${version})**'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Push image
run: make docker-build && make docker-push
# - name: Build and push Docker image
# run: make docker-build && make docker-push

- name: Set up Sonatype Maven
uses: actions/setup-java@v3
- name: Set up Java for Maven Central publish
uses: actions/setup-java@e9fbacdec3bb3b6036605a3e6f7995d66773a8c6 # v3.14.2
with:
java-version: 11
java-version: '11'
distribution: temurin
server-id: central
server-username: MAVEN_USERNAME
Expand All @@ -113,32 +89,16 @@ jobs:
gpg-passphrase: GPG_PASSPHRASE

- run: mvn install -DskipTests=true -Dgpg.skip -Dmaven.javadoc.skip=true -B -V
- name: Publish to Maven

- name: Publish to Maven Central
env:
MAVEN_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
run: mvn clean deploy -DskipTests=true -B -U -Prelease

- name: Submit metric to Datadog
uses: sendgrid/dx-automator/actions/datadog-release-metric@main
env:
DD_API_KEY: ${{ secrets.DATADOG_API_KEY }}
# - name: Submit metric to Datadog
# uses: sendgrid/dx-automator/actions/datadog-release-metric@08b601b726671445abc798ed59881766ec8fefc6
# env:
# DD_API_KEY: ${{ secrets.DATADOG_API_KEY }}

notify-on-failure:
name: Slack notify on failure
if: failure() && github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || github.ref_type == 'tag')
needs: [ test, deploy ]
runs-on: ubuntu-latest
steps:
- uses: rtCamp/action-slack-notify@v2
env:
SLACK_COLOR: failure
SLACK_ICON_EMOJI: ':github:'
SLACK_MESSAGE: ${{ format('Test *{0}*, Deploy *{1}*, {2}/{3}/actions/runs/{4}', needs.test.result, needs.deploy.result, github.server_url, github.repository, github.run_id) }}
SLACK_TITLE: Action Failure - ${{ github.repository }}
SLACK_USERNAME: GitHub Actions
SLACK_MSG_AUTHOR: twilio-dx
SLACK_FOOTER: Posted automatically using GitHub Actions
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
MSG_MINIMAL: true
Loading
Loading