name: Deploy on: release: types: [published] permissions: contents: read concurrency: group: npm-publish cancel-in-progress: false jobs: lint: uses: ./.github/workflows/lint.yaml test: uses: ./.github/workflows/test.yaml package: needs: [lint, test] runs-on: ubuntu-latest timeout-minutes: 20 steps: - name: Check out source uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - name: Set up pnpm via corepack run: | mkdir -p "$RUNNER_TEMP/corepack" corepack enable --install-directory "$RUNNER_TEMP/corepack" pnpm echo "$RUNNER_TEMP/corepack" >> "$GITHUB_PATH" corepack prepare --activate - name: Set up Node.js uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 with: node-version: 24 # No cache: pnpm here, deliberately. This job builds and publishes release tarballs, so # restoring a pnpm store from a prior run's cache would let a poisoned cache entry slip # dependencies into a published package. Every run resolves and installs cleanly. - name: Validate production release version # The five npm packages and the Flutter package must carry one version, and it must be # the release tag's. env: RELEASE_TAG: ${{ github.event.release.tag_name }} run: node scripts/release-version.mjs --tag "$RELEASE_TAG" - name: Install dependencies run: pnpm install --frozen-lockfile --ignore-scripts - name: Build packages run: pnpm build - name: Pack release tarballs run: | mkdir release pnpm --filter @appduct/shared pack --pack-destination release pnpm --filter appduct pack --pack-destination release pnpm --filter @appduct/react-native pack --pack-destination release pnpm --filter @appduct/web pack --pack-destination release pnpm --filter @appduct/e2e pack --pack-destination release - name: Upload release tarballs uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: npm-packages path: release/*.tgz retention-days: 1 compression-level: 0 publish-shared: needs: package runs-on: ubuntu-latest timeout-minutes: 10 environment: npm permissions: id-token: write steps: - name: Set up Node.js uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 with: node-version: 24 - name: Verify npm version run: >- node -e 'const [major, minor, patch] = process.argv[1].split(".").map(Number); if (major < 11 || (major === 11 && (minor < 5 || (minor === 5 && patch < 1)))) process.exit(1);' "$(npm --version)" - name: Download release tarballs uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: name: npm-packages path: release - name: Publish shared package run: npm publish ./release/appduct-shared-*.tgz --access public --provenance --tag latest publish-cli: needs: publish-shared runs-on: ubuntu-latest timeout-minutes: 10 environment: npm permissions: id-token: write steps: - name: Set up Node.js uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 with: node-version: 24 - name: Verify npm version run: >- node -e 'const [major, minor, patch] = process.argv[1].split(".").map(Number); if (major < 11 || (major === 11 && (minor < 5 || (minor === 5 && patch < 1)))) process.exit(1);' "$(npm --version)" - name: Download release tarballs uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: name: npm-packages path: release - name: Publish CLI package run: npm publish ./release/appduct-[0-9]*.tgz --access public --provenance --tag latest publish-react-native: needs: publish-shared runs-on: ubuntu-latest timeout-minutes: 10 environment: npm permissions: id-token: write steps: - name: Set up Node.js uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 with: node-version: 24 - name: Verify npm version run: >- node -e 'const [major, minor, patch] = process.argv[1].split(".").map(Number); if (major < 11 || (major === 11 && (minor < 5 || (minor === 5 && patch < 1)))) process.exit(1);' "$(npm --version)" - name: Download release tarballs uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: name: npm-packages path: release - name: Publish React Native package run: npm publish ./release/appduct-react-native-*.tgz --access public --provenance --tag latest publish-web: needs: publish-shared runs-on: ubuntu-latest timeout-minutes: 10 environment: npm permissions: id-token: write steps: - name: Set up Node.js uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 with: node-version: 24 - name: Verify npm version run: >- node -e 'const [major, minor, patch] = process.argv[1].split(".").map(Number); if (major < 11 || (major === 11 && (minor < 5 || (minor === 5 && patch < 1)))) process.exit(1);' "$(npm --version)" - name: Download release tarballs uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: name: npm-packages path: release - name: Publish web package run: npm publish ./release/appduct-web-*.tgz --access public --provenance --tag latest publish-e2e: # Depends on the `appduct` package, so it goes out after the CLI. needs: publish-cli runs-on: ubuntu-latest timeout-minutes: 10 environment: npm permissions: id-token: write steps: - name: Set up Node.js uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 with: node-version: 24 - name: Verify npm version run: >- node -e 'const [major, minor, patch] = process.argv[1].split(".").map(Number); if (major < 11 || (major === 11 && (minor < 5 || (minor === 5 && patch < 1)))) process.exit(1);' "$(npm --version)" - name: Download release tarballs uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: name: npm-packages path: release - name: Publish e2e package run: npm publish ./release/appduct-e2e-*.tgz --access public --provenance --tag latest publish-cocoapods: # Deliberately last, after every npm publish has succeeded. A CocoaPods trunk version is # permanent -- `pod trunk` has no unpublish, and a version can never be replaced or reused -- # whereas npm allows `npm unpublish` within 72 hours. So the irreversible half of the release # only runs once the reversible half is known good; a trunk push that lands next to a failed # npm publish would pin the repo to a version number it can never ship again. needs: [publish-cli, publish-react-native, publish-web, publish-e2e] runs-on: macos-latest timeout-minutes: 45 # Holds COCOAPODS_TRUNK_TOKEN (from `pod trunk register`). CocoaPods has no OIDC/trusted- # publishing equivalent to npm's, so this is a long-lived secret rather than an id-token # exchange -- hence its own protected environment, and no `id-token: write` here. environment: cocoapods env: # CocoaPods drives Ruby's default_external encoding off the locale; on the runner's default # POSIX locale a non-ASCII byte anywhere in a podspec or a cloned source path raises # `Encoding::CompatibilityError`. Same workaround the iOS test job applies to `pod install`. LANG: en_US.UTF-8 LC_ALL: en_US.UTF-8 steps: - name: Check out source uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: # The release's tag, not the default branch: AppductCore.podspec reads its version out # of packages/react-native/package.json at push time, so the checkout has to be the # commit that release actually names. ref: ${{ github.event.release.tag_name }} persist-credentials: false - name: Verify the release tag is fetchable from GitHub # `pod trunk push` does not upload the working tree -- it clones `s.source`'s git URL at # `tag: v#{s.version}` and validates that. A tag that is missing from the remote (a local- # only tag, or a release cut from a branch) fails deep inside CocoaPods' downloader with an # opaque git error, so check the precondition here where the message can say what is wrong. env: RELEASE_TAG: ${{ github.event.release.tag_name }} run: | source_url=$(grep -o 'https://github.com/[^'"'"']*\.git' AppductCore.podspec) if [ -z "$(git ls-remote --tags "$source_url" "refs/tags/$RELEASE_TAG")" ]; then echo "::error::$RELEASE_TAG is not present at $source_url, which is what 'pod trunk push' clones." exit 1 fi - name: Resolve the podspec version # Single-sourced from packages/react-native/package.json by the podspec itself; the # `package` job has already asserted that this equals the release tag. run: | version=$(node -p "require('./packages/react-native/package.json').version") echo "PODSPEC_VERSION=$version" >> "$GITHUB_ENV" - name: Check whether this version is already on trunk # Makes a re-run of a partially-failed deploy safe. A duplicate `pod trunk push` is a hard # error, so without this any re-run after a successful push fails the whole workflow and # obscures whatever actually needed re-running. run: | # 404 is the expected answer until the very first release, and it returns an empty body -- # so branch on the status code rather than piping nothing into a JSON parser. http=$(curl -sS -o trunk.json -w '%{http_code}' \ "https://trunk.cocoapods.org/api/v1/pods/AppductCore" || echo 000) if [ "$http" = "200" ] && node -e ' const pod = JSON.parse(require("fs").readFileSync("trunk.json", "utf8")); const published = (pod.versions || []).some((v) => v.name === process.argv[1]); process.exit(published ? 0 : 1); ' "$PODSPEC_VERSION"; then echo "ALREADY_PUBLISHED=true" >> "$GITHUB_ENV" echo "AppductCore $PODSPEC_VERSION is already on trunk; skipping the push." else echo "ALREADY_PUBLISHED=false" >> "$GITHUB_ENV" fi - name: Publish AppductCore to CocoaPods trunk if: env.ALREADY_PUBLISHED == 'false' env: COCOAPODS_TRUNK_TOKEN: ${{ secrets.COCOAPODS_TRUNK_TOKEN }} # `pod trunk push` validates locally (clone, lint, build for every platform the podspec # declares) and only uploads once that passes, so a validation failure publishes nothing. # Deliberately no --allow-warnings (#57 cleared the warnings that used to need it): a new # warning in these sources should block a release. test.yaml's iOS build catches it first, # on the PR that introduces it, so reaching this job with warnings should not happen. run: pod trunk push AppductCore.podspec publish-maven: # Alongside publish-cocoapods rather than after it: the two are independent registries, and # neither can be rolled back, so ordering them buys nothing. Both wait on the npm publishes for # the same reason publish-cocoapods does -- Maven Central is immutable, a version can never be # replaced or deleted, so the irreversible half of a release only runs once npm (which allows # `npm unpublish` for 72 hours) is known good. # # Re-run safe, like publish-cocoapods: an already-published version is skipped, and a deployment # uploaded by an earlier attempt of this run is picked back up instead of being uploaded twice. needs: [publish-cli, publish-react-native, publish-web, publish-e2e] runs-on: ubuntu-latest timeout-minutes: 30 # Holds CENTRAL_TOKEN_USERNAME/PASSWORD (Central Portal user token) and the GPG key pair. # Central has no OIDC trusted-publishing equivalent either, so these are long-lived secrets in # a protected environment. environment: maven-central steps: - name: Check out source uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: # The release's tag: the Gradle build reads its version from # packages/react-native/package.json, so the checkout must be the commit the release names. ref: ${{ github.event.release.tag_name }} persist-credentials: false - name: Set up Java 17 uses: actions/setup-java@de7274f081f381c8f8158605e0321c36c376e2e6 # v6.0.1 with: distribution: temurin java-version: 17 - name: Set up Android SDK uses: android-actions/setup-android@be39fa834029ff78f1a44aa3bb0819b8fc2bd8fd # v4.0.4 with: # See test.yaml: the legacy standalone "tools" package no longer exists upstream. packages: platform-tools - name: Check whether this version is already on Maven Central # Two independent sources, OR-ed. Each can only say "published" when that is genuinely true, # so neither can cause a false skip -- the dangerous direction, since it would end a release # green without anything ever reaching Central. # # repo1.maven.org is public and unambiguous, but trails a real publish by up to ~30 minutes. # The Portal's `published` endpoint has no such lag, but its response body is not in # Sonatype's published docs, so it only counts on an explicit `"published": true` and any # other answer falls through. Checking `core` alone is enough: both artifacts go up in one # bundle, so they are published together or not at all. env: CENTRAL_TOKEN_USERNAME: ${{ secrets.CENTRAL_TOKEN_USERNAME }} CENTRAL_TOKEN_PASSWORD: ${{ secrets.CENTRAL_TOKEN_PASSWORD }} run: | version=$(node -p "require('./packages/react-native/package.json').version") echo "APPDUCT_VERSION=$version" >> "$GITHUB_ENV" published=false repo1=$(curl -s -o /dev/null -I -w '%{http_code}' \ "https://repo1.maven.org/maven2/com/callstack/appduct/core/$version/core-$version.pom") || repo1=000 if [ "$repo1" = "200" ]; then published=true else auth=$(printf '%s:%s' "$CENTRAL_TOKEN_USERNAME" "$CENTRAL_TOKEN_PASSWORD" | base64 | tr -d '\n') if curl -sS -H "Authorization: Bearer $auth" \ "https://central.sonatype.com/api/v1/publisher/published?namespace=com.callstack.appduct&name=core&version=$version" \ | node -e 'let s="";process.stdin.on("data",c=>s+=c).on("end",()=>{ try { process.exit(JSON.parse(s).published === true ? 0 : 1); } catch { process.exit(1); } })'; then published=true fi fi echo "ALREADY_PUBLISHED=$published" >> "$GITHUB_ENV" if [ "$published" = true ]; then echo "::notice::com.callstack.appduct $version is already on Maven Central; skipping the upload." fi - name: Restore the deployment id from an earlier attempt if: env.ALREADY_PUBLISHED == 'false' # Covers what the check above cannot: an upload that succeeded, followed by a failure later # in this job (most likely the status poll timing out), followed by "Re-run failed jobs". # That deployment is VALIDATED but unpublished, so it is invisible to both published checks, # and the Portal API has no endpoint to list deployments -- its id is the only handle on it. # The upload step saves the id as an artifact of this run, which a re-run attempt can read. # Absent on a first attempt, hence continue-on-error. continue-on-error: true uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: name: central-deployment-id path: ${{ runner.temp }}/central-deployment - name: Reuse the earlier deployment if it is still live if: env.ALREADY_PUBLISHED == 'false' # Only states that mean "this deployment will, or already did, carry the release" are reused. # FAILED, a deployment dropped in the Portal UI, or any answer that cannot be parsed all # fall through to a fresh upload -- reusing wrongly would leave the release with nothing to # publish, while uploading again at worst leaves a duplicate for a human to drop. env: CENTRAL_TOKEN_USERNAME: ${{ secrets.CENTRAL_TOKEN_USERNAME }} CENTRAL_TOKEN_PASSWORD: ${{ secrets.CENTRAL_TOKEN_PASSWORD }} run: | reuse=false id_file="$RUNNER_TEMP/central-deployment/deployment-id" if [ -f "$id_file" ]; then id=$(tr -d '[:space:]' < "$id_file") auth=$(printf '%s:%s' "$CENTRAL_TOKEN_USERNAME" "$CENTRAL_TOKEN_PASSWORD" | base64 | tr -d '\n') state=$(curl -sS -X POST -H "Authorization: Bearer $auth" \ "https://central.sonatype.com/api/v1/publisher/status?id=$id" \ | node -e 'let s="";process.stdin.on("data",c=>s+=c).on("end",()=>{ try { process.stdout.write(JSON.parse(s).deploymentState || "UNKNOWN"); } catch { process.stdout.write("UNKNOWN"); } })') || state=UNKNOWN echo "Deployment $id from an earlier attempt is $state." case "$state" in PENDING|VALIDATING|VALIDATED|PUBLISHING|PUBLISHED) reuse=true echo "DEPLOYMENT_ID=$id" >> "$GITHUB_ENV" echo "::notice::Reusing deployment $id ($state) instead of uploading $APPDUCT_VERSION again." ;; esac fi echo "REUSE_DEPLOYMENT=$reuse" >> "$GITHUB_ENV" - name: Stage the signed bundle if: env.ALREADY_PUBLISHED == 'false' && env.REUSE_DEPLOYMENT != 'true' # Publishes both modules into one on-disk Maven repository layout, which is exactly the # shape the Portal's bundle zip must have. Gradle writes the .md5/.sha1 checksums Central # requires for every file, and the `signing` plugin writes a .asc beside each one -- the # key is only ever in the environment, never on the runner's disk. working-directory: packages/native/android env: APPDUCT_SIGNING_KEY: ${{ secrets.APPDUCT_SIGNING_KEY }} APPDUCT_SIGNING_PASSWORD: ${{ secrets.APPDUCT_SIGNING_PASSWORD }} run: | ./gradlew --no-daemon \ :core:publishAllPublicationsToCentralBundleRepository \ :core-noop:publishAllPublicationsToCentralBundleRepository - name: Verify every artifact is signed if: env.ALREADY_PUBLISHED == 'false' && env.REUSE_DEPLOYMENT != 'true' # A missing APPDUCT_SIGNING_KEY makes `signing` a silent no-op by design, so that # `publishToMavenLocal` keeps working on an unkeyed machine (see publishing.gradle). That # same leniency would otherwise let this job upload an unsigned bundle and fail deep inside # Central's validator, so assert it here where the cause is obvious. working-directory: packages/native/android run: | bundle=build/central-bundle unsigned=$(find "$bundle" -type f \ ! -name '*.asc' ! -name '*.md5' ! -name '*.sha1' ! -name '*.sha256' ! -name '*.sha512' \ ! -name 'maven-metadata.xml' \ -exec sh -c '[ -f "$1.asc" ] || echo "$1"' _ {} \;) if [ -n "$unsigned" ]; then echo "::error::Unsigned artifacts staged -- is APPDUCT_SIGNING_KEY set?" echo "$unsigned" exit 1 fi echo "All staged artifacts carry a .asc signature." - name: Build the deployment bundle if: env.ALREADY_PUBLISHED == 'false' && env.REUSE_DEPLOYMENT != 'true' # maven-metadata.xml is excluded deliberately: Central generates its own repository # metadata, and Gradle's copy describes only this one deployment, so shipping it is at best # redundant and at worst a validation failure. working-directory: packages/native/android/build/central-bundle run: zip -r "$RUNNER_TEMP/central-bundle.zip" . -x '*maven-metadata.xml*' - name: Upload to the Central Portal if: env.ALREADY_PUBLISHED == 'false' && env.REUSE_DEPLOYMENT != 'true' env: CENTRAL_TOKEN_USERNAME: ${{ secrets.CENTRAL_TOKEN_USERNAME }} CENTRAL_TOKEN_PASSWORD: ${{ secrets.CENTRAL_TOKEN_PASSWORD }} # publishingType=USER_MANAGED, not AUTOMATIC. Central validates the bundle and then waits # for a human to press Publish in the Portal UI. Given the deployment can never be undone # once it goes out, the last step stays manual until this path has proven itself over a few # releases; switching to AUTOMATIC later is a one-word change. run: | auth=$(printf '%s:%s' "$CENTRAL_TOKEN_USERNAME" "$CENTRAL_TOKEN_PASSWORD" | base64 | tr -d '\n') response=$(curl --fail-with-body -sS -X POST \ -H "Authorization: Bearer $auth" \ -F "bundle=@$RUNNER_TEMP/central-bundle.zip" \ "https://central.sonatype.com/api/v1/publisher/upload?name=appduct-v$APPDUCT_VERSION&publishingType=USER_MANAGED") id=$(printf '%s' "$response" | tr -d '[:space:]') # The body is the bare deployment id. Refuse anything else rather than saving junk that a # re-run would then try to resume. if ! printf '%s' "$id" | grep -Eq '^[0-9a-fA-F-]{36}$'; then echo "::error::Unexpected upload response (expected a deployment id): $response" exit 1 fi echo "Deployment id: $id" echo "DEPLOYMENT_ID=$id" >> "$GITHUB_ENV" mkdir -p "$RUNNER_TEMP/central-deployment" printf '%s\n' "$id" > "$RUNNER_TEMP/central-deployment/deployment-id" - name: Save the deployment id for a re-run if: env.ALREADY_PUBLISHED == 'false' && env.REUSE_DEPLOYMENT != 'true' # Deliberately before the status poll, so the id survives whatever fails after the upload. uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: central-deployment-id path: ${{ runner.temp }}/central-deployment/deployment-id # A later attempt that finds the saved deployment FAILED or dropped uploads a fresh one, # and must replace this id rather than collide with it. overwrite: true # GitHub allows re-running a workflow run for up to 30 days. retention-days: 30 - name: Report validation status if: env.ALREADY_PUBLISHED == 'false' env: CENTRAL_TOKEN_USERNAME: ${{ secrets.CENTRAL_TOKEN_USERNAME }} CENTRAL_TOKEN_PASSWORD: ${{ secrets.CENTRAL_TOKEN_PASSWORD }} # Validation is asynchronous, so poll until it leaves the pending states. FAILED fails the # job; VALIDATED is the success case and means the release is staged and waiting for the # manual Publish. Never publishes anything itself. run: | auth=$(printf '%s:%s' "$CENTRAL_TOKEN_USERNAME" "$CENTRAL_TOKEN_PASSWORD" | base64 | tr -d '\n') for _ in $(seq 1 40); do state=$(curl --fail-with-body -sS -X POST \ -H "Authorization: Bearer $auth" \ "https://central.sonatype.com/api/v1/publisher/status?id=$DEPLOYMENT_ID" \ | node -e 'let s="";process.stdin.on("data",c=>s+=c).on("end",()=>{ process.stdout.write(JSON.parse(s).deploymentState || "UNKNOWN"); })') echo "deploymentState=$state" case "$state" in VALIDATED|PUBLISHING|PUBLISHED) echo "::notice::Deployment $DEPLOYMENT_ID is $state. Press Publish at https://central.sonatype.com/publishing/deployments to release it." exit 0 ;; FAILED) echo "::error::Central rejected deployment $DEPLOYMENT_ID. See https://central.sonatype.com/publishing/deployments" exit 1 ;; esac sleep 15 done echo "::error::Timed out waiting for deployment $DEPLOYMENT_ID to validate. Re-running this job resumes watching it rather than uploading again." exit 1 start-pub-publish: # pub.dev refuses OIDC tokens from `release` events -- it accepts only `push` and # `workflow_dispatch` -- so the publish lives in publish-pub.yaml and this job starts it at the # release tag. A workflow_dispatch may be started with GITHUB_TOKEN (given `actions: write`), # unlike a tag push made by it, which GitHub would not turn into a workflow run. # # Last, with the other irreversible publishes: pub.dev has no unpublish, so it waits for the # npm publishes. Nothing needs this job, so a pub.dev problem never fails the npm release; the # publish run shows its own result under Actions > Publish to pub.dev and can be started again # by hand on the tag. needs: [publish-cli, publish-react-native, publish-web, publish-e2e] runs-on: ubuntu-latest timeout-minutes: 5 permissions: actions: write env: GH_TOKEN: ${{ github.token }} RELEASE_TAG: ${{ github.event.release.tag_name }} steps: - name: Start the pub.dev publish at the release tag run: gh workflow run publish-pub.yaml --repo "$GITHUB_REPOSITORY" --ref "$RELEASE_TAG"