diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000000..7bca2db28a --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.github/workflows/pr-lint.yml b/.github/workflows/pr-lint.yml index 31520079ca..fea5acfd2f 100644 --- a/.github/workflows/pr-lint.yml +++ b/.github/workflows/pr-lint.yml @@ -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 diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml new file mode 100644 index 0000000000..e509a3d82c --- /dev/null +++ b/.github/workflows/pre-release.yml @@ -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 ---" diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index 6df1765eda..b922b69253 100644 --- a/.github/workflows/test-and-deploy.yml +++ b/.github/workflows/test-and-deploy.yml @@ -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 }} + 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 @@ -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 diff --git a/pom.xml b/pom.xml index b9be5c8152..5b586a4d35 100644 --- a/pom.xml +++ b/pom.xml @@ -200,7 +200,7 @@ 2.18.6 - 3.3.1 + 3.12.0 0.12.6 1.18.34 5.14.2 @@ -424,7 +424,7 @@ org.apache.maven.plugins maven-assembly-plugin - 3.3.0 + 3.8.0 jar-with-dependencies @@ -443,7 +443,7 @@ org.apache.maven.plugins maven-checkstyle-plugin - 3.1.1 + 3.6.0 checkstyle.xml @@ -451,7 +451,7 @@ org.apache.maven.plugins maven-source-plugin - 3.2.1 + 3.4.0 attach-sources @@ -490,7 +490,7 @@ org.apache.maven.plugins maven-release-plugin - 2.5.3 + 3.3.1 @{project.version} -DskipTests=${skip.tests} @@ -534,7 +534,7 @@ org.apache.maven.plugins maven-enforcer-plugin - 3.0.0 + 3.4.1 enforce-versions