|
| 1 | +name: 'org.nativescript:gradle-api' |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + pull_request: |
| 6 | + paths: |
| 7 | + - 'gradle-api/**' |
| 8 | + - 'vendor/gradle-plugin/**' |
| 9 | + - 'lib/services/android-plugin-build-service.ts' |
| 10 | + - 'lib/services/android-project-service.ts' |
| 11 | + - 'lib/services/android/**' |
| 12 | + - '.github/workflows/gradle_api.yml' |
| 13 | + push: |
| 14 | + branches: [ 'main' ] |
| 15 | + # Path filters do not apply to tag pushes. |
| 16 | + tags: [ 'gradle-api-v*' ] |
| 17 | + paths: |
| 18 | + - 'gradle-api/**' |
| 19 | + - 'vendor/gradle-plugin/**' |
| 20 | + - 'lib/services/android-plugin-build-service.ts' |
| 21 | + - 'lib/services/android-project-service.ts' |
| 22 | + - 'lib/services/android/**' |
| 23 | + - '.github/workflows/gradle_api.yml' |
| 24 | + |
| 25 | +permissions: |
| 26 | + contents: read |
| 27 | + |
| 28 | +concurrency: |
| 29 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 30 | + cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/') }} |
| 31 | + |
| 32 | +jobs: |
| 33 | + test: |
| 34 | + name: Test |
| 35 | + runs-on: ubuntu-latest |
| 36 | + timeout-minutes: 45 |
| 37 | + |
| 38 | + steps: |
| 39 | + - name: Harden the runner (Audit all outbound calls) |
| 40 | + uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1 |
| 41 | + with: |
| 42 | + egress-policy: audit |
| 43 | + |
| 44 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 45 | + with: |
| 46 | + persist-credentials: false |
| 47 | + |
| 48 | + - uses: gradle/actions/wrapper-validation@3f5f9adaf7d9fecd50b5935e54106014257a94e6 # v6.4.0 |
| 49 | + with: |
| 50 | + # vendor/gradle-plugin/gradle/wrapper/gradle-wrapper.jar, which the CLI copies into |
| 51 | + # plugin builds, matches no published Gradle wrapper checksum. |
| 52 | + allow-checksums: 414142e6bc3b156908436f13b29e198bb3d59824f9c245ef145c809ddd5fe0a3 |
| 53 | + |
| 54 | + - uses: actions/setup-java@de7274f081f381c8f8158605e0321c36c376e2e6 # v6.0.1 |
| 55 | + with: |
| 56 | + distribution: temurin |
| 57 | + java-version: '17' |
| 58 | + |
| 59 | + - uses: gradle/actions/setup-gradle@3f5f9adaf7d9fecd50b5935e54106014257a94e6 # v6.4.0 |
| 60 | + with: |
| 61 | + cache-provider: basic |
| 62 | + # Done by the wrapper-validation step, which can allow the vendored jar. |
| 63 | + validate-wrappers: false |
| 64 | + |
| 65 | + # The Android SDK preinstalled on the runner (ANDROID_HOME) enables the plugin build tests. |
| 66 | + - name: Check |
| 67 | + working-directory: gradle-api |
| 68 | + run: ./gradlew check --console=plain |
| 69 | + |
| 70 | + test-windows: |
| 71 | + name: Unit tests (Windows) |
| 72 | + runs-on: windows-latest |
| 73 | + timeout-minutes: 30 |
| 74 | + |
| 75 | + steps: |
| 76 | + - name: Harden the runner (Audit all outbound calls) |
| 77 | + uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1 |
| 78 | + with: |
| 79 | + egress-policy: audit |
| 80 | + |
| 81 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 82 | + with: |
| 83 | + persist-credentials: false |
| 84 | + |
| 85 | + - uses: actions/setup-java@de7274f081f381c8f8158605e0321c36c376e2e6 # v6.0.1 |
| 86 | + with: |
| 87 | + distribution: temurin |
| 88 | + java-version: '17' |
| 89 | + |
| 90 | + # The Test job validates the wrappers. |
| 91 | + - uses: gradle/actions/setup-gradle@3f5f9adaf7d9fecd50b5935e54106014257a94e6 # v6.4.0 |
| 92 | + with: |
| 93 | + cache-provider: basic |
| 94 | + validate-wrappers: false |
| 95 | + |
| 96 | + - name: Test |
| 97 | + working-directory: gradle-api |
| 98 | + run: .\gradlew.bat test --console=plain |
| 99 | + |
| 100 | + publish: |
| 101 | + name: Publish to Maven Central |
| 102 | + if: startsWith(github.ref, 'refs/tags/gradle-api-v') |
| 103 | + needs: [ test, test-windows ] |
| 104 | + runs-on: ubuntu-latest |
| 105 | + timeout-minutes: 30 |
| 106 | + environment: maven-central |
| 107 | + |
| 108 | + steps: |
| 109 | + - name: Harden the runner (Audit all outbound calls) |
| 110 | + uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1 |
| 111 | + with: |
| 112 | + egress-policy: audit |
| 113 | + |
| 114 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 115 | + with: |
| 116 | + persist-credentials: false |
| 117 | + # Full history of every branch, for the main ancestry check. |
| 118 | + fetch-depth: 0 |
| 119 | + |
| 120 | + # A tag can point at any commit, and publishing releases it immediately. |
| 121 | + - name: Check the tagged commit is on main |
| 122 | + run: | |
| 123 | + commit="$(git rev-parse "$GITHUB_SHA^{commit}")" |
| 124 | + if ! git merge-base --is-ancestor "$commit" origin/main; then |
| 125 | + echo "::error::$GITHUB_REF_NAME points at $commit, which is not on main" |
| 126 | + exit 1 |
| 127 | + fi |
| 128 | +
|
| 129 | + - uses: gradle/actions/wrapper-validation@3f5f9adaf7d9fecd50b5935e54106014257a94e6 # v6.4.0 |
| 130 | + with: |
| 131 | + allow-checksums: 414142e6bc3b156908436f13b29e198bb3d59824f9c245ef145c809ddd5fe0a3 |
| 132 | + |
| 133 | + - uses: actions/setup-java@de7274f081f381c8f8158605e0321c36c376e2e6 # v6.0.1 |
| 134 | + with: |
| 135 | + distribution: temurin |
| 136 | + java-version: '17' |
| 137 | + |
| 138 | + - uses: gradle/actions/setup-gradle@3f5f9adaf7d9fecd50b5935e54106014257a94e6 # v6.4.0 |
| 139 | + with: |
| 140 | + cache-provider: basic |
| 141 | + cache-read-only: true |
| 142 | + validate-wrappers: false |
| 143 | + |
| 144 | + - name: Check the tag matches the version |
| 145 | + working-directory: gradle-api |
| 146 | + env: |
| 147 | + TAG: ${{ github.ref_name }} |
| 148 | + run: | |
| 149 | + version="$(sed -n 's/^VERSION_NAME=//p' gradle.properties)" |
| 150 | + if [ "$TAG" != "gradle-api-v$version" ]; then |
| 151 | + echo "::error::Tag $TAG does not match VERSION_NAME=$version in gradle-api/gradle.properties" |
| 152 | + exit 1 |
| 153 | + fi |
| 154 | + case "$version" in |
| 155 | + *-SNAPSHOT) |
| 156 | + echo "::error::$version is a snapshot version" |
| 157 | + exit 1 |
| 158 | + ;; |
| 159 | + esac |
| 160 | +
|
| 161 | + - name: Publish |
| 162 | + working-directory: gradle-api |
| 163 | + env: |
| 164 | + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }} |
| 165 | + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} |
| 166 | + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.MAVEN_CENTRAL_SIGNING_KEY }} |
| 167 | + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.MAVEN_CENTRAL_SIGNING_KEY_PASSWORD }} |
| 168 | + run: | |
| 169 | + # The build skips signing without a key, which Maven Central would only reject later. |
| 170 | + for name in ORG_GRADLE_PROJECT_mavenCentralUsername ORG_GRADLE_PROJECT_mavenCentralPassword ORG_GRADLE_PROJECT_signingInMemoryKey; do |
| 171 | + if [ -z "${!name}" ]; then |
| 172 | + echo "::error::$name is empty; check the maven-central environment's secrets" |
| 173 | + exit 1 |
| 174 | + fi |
| 175 | + done |
| 176 | + ./gradlew publishAndReleaseToMavenCentral --no-configuration-cache --console=plain |
0 commit comments