Skip to content

Commit 0c3b663

Browse files
coadofacebook-github-bot
authored andcommitted
Setup Hermes publishing to Maven for commitlies and releases on Android and iOS (#1752)
Summary: Pull Request resolved: #1752 This setups publishing Android and iOS artifacts on commits and releases to be used by React Native. ## Motivation Reduce CI time by decreasing the number of Hermes builds currently running on the React Native repo by moving them to the Hermes repo with less traffic. Reviewed By: cortinico Differential Revision: D79163000 fbshipit-source-id: e80978a4f32e48c5c2c0ce5574e1956319693697
1 parent 5dd462a commit 0c3b663

File tree

16 files changed

+745
-8
lines changed

16 files changed

+745
-8
lines changed

.github/workflows/build-android.yml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
name: build-android
22

33
on:
4-
workflow_call
4+
workflow_call:
5+
inputs:
6+
release-type:
7+
required: true
8+
description: The type of release we are building. It could be commitly, release or dry-run
9+
type: string
510

611
jobs:
712
build-android:
@@ -26,12 +31,26 @@ jobs:
2631
# Build the Hermes compiler so that the cross compiler build can
2732
# access it to build the VM
2833
cmake --build ./build --target hermesc -j 4
34+
- name: Setup node.js
35+
uses: ./.github/actions/setup-node
36+
- name: Install node dependencies
37+
uses: ./.github/actions/yarn-install
38+
- name: Set React Native Version
39+
shell: bash
40+
run: node ./utils/scripts/hermes/set-artifacts-version.js --build-type ${{ inputs.release-type }}
2941
- name: Build android
3042
shell: bash
3143
run: |
3244
cd android
33-
TASKS="publishAllToMavenTempLocal :build"
34-
./gradlew $TASKS
45+
46+
if [[ "${{ inputs.release-type }}" == "commitly" ]]; then
47+
export ORG_GRADLE_PROJECT_isSnapshot="true"
48+
TASKS="publishAllToMavenTempLocal publishToSonatype :build"
49+
else
50+
TASKS="publishAllToMavenTempLocal :build"
51+
fi
52+
53+
./gradlew $TASKS -PenableWarningsAsErrors=true
3554
- name: Upload Maven Artifacts
3655
uses: actions/[email protected]
3756
with:

.github/workflows/publish.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: publish
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
release-type:
7+
required: true
8+
description: The type of release we are building. It could be commitly, release or dry-run
9+
type: string
10+
11+
jobs:
12+
publish:
13+
runs-on: 8-core-ubuntu
14+
container:
15+
image: reactnativecommunity/react-native-android:latest
16+
env:
17+
TERM: "dumb"
18+
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
19+
env:
20+
HERMES_WS_DIR: /tmp/hermes
21+
ORG_GRADLE_PROJECT_SIGNING_PWD: ${{ secrets.ORG_GRADLE_PROJECT_SIGNING_PWD }}
22+
ORG_GRADLE_PROJECT_SIGNING_KEY: ${{ secrets.ORG_GRADLE_PROJECT_SIGNING_KEY }}
23+
ORG_GRADLE_PROJECT_SONATYPE_USERNAME: ${{ secrets.ORG_GRADLE_PROJECT_SONATYPE_USERNAME }}
24+
ORG_GRADLE_PROJECT_SONATYPE_PASSWORD: ${{ secrets.ORG_GRADLE_PROJECT_SONATYPE_PASSWORD }}
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
- name: Setup git safe folders
29+
shell: bash
30+
run: git config --global --add safe.directory '*'
31+
- name: Create /tmp/hermes/osx-bin directory
32+
shell: bash
33+
run: mkdir -p /tmp/hermes/osx-bin
34+
- name: Download osx-bin release artifacts
35+
uses: actions/download-artifact@v4
36+
with:
37+
name: hermes-osx-bin-Release
38+
path: /tmp/hermes/osx-bin/Release
39+
- name: Download osx-bin debug artifacts
40+
uses: actions/download-artifact@v4
41+
with:
42+
name: hermes-osx-bin-Debug
43+
path: /tmp/hermes/osx-bin/Debug
44+
- name: Download darwin-bin release artifacts
45+
uses: actions/download-artifact@v4
46+
with:
47+
name: hermes-darwin-bin-Release
48+
path: /tmp/hermes/hermes-runtime-darwin
49+
- name: Download darwin-bin debug artifacts
50+
uses: actions/download-artifact@v4
51+
with:
52+
name: hermes-darwin-bin-Debug
53+
path: /tmp/hermes/hermes-runtime-darwin
54+
- name: Download hermes dSYM debug artifacts
55+
uses: actions/download-artifact@v4
56+
with:
57+
name: hermes-dSYM-Debug
58+
path: /tmp/hermes/dSYM/Debug
59+
- name: Download hermes dSYM release vartifacts
60+
uses: actions/download-artifact@v4
61+
with:
62+
name: hermes-dSYM-Release
63+
path: /tmp/hermes/dSYM/Release
64+
- name: Download windows-bin artifacts
65+
uses: actions/download-artifact@v4
66+
with:
67+
name: hermes-win64-bin
68+
path: /tmp/hermes/win64-bin
69+
- name: Download linux-bin artifacts
70+
uses: actions/download-artifact@v4
71+
with:
72+
name: hermes-linux-bin
73+
path: /tmp/hermes/linux64-bin
74+
- name: Show /tmp/hermes directory
75+
shell: bash
76+
run: ls -lR /tmp/hermes
77+
- name: Copy Hermes binaries
78+
shell: bash
79+
run: |
80+
mkdir -p ./android/ios-artifacts/artifacts/
81+
cp $HERMES_WS_DIR/hermes-runtime-darwin/hermes-ios-Debug.tar.gz ./android/ios-artifacts/artifacts/hermes-ios-debug.tar.gz
82+
cp $HERMES_WS_DIR/hermes-runtime-darwin/hermes-ios-Release.tar.gz ./android/ios-artifacts/artifacts/hermes-ios-release.tar.gz
83+
cp $HERMES_WS_DIR/dSYM/Debug/hermes.framework.dSYM ./android/ios-artifacts/artifacts/hermes-framework-dSYM-debug.tar.gz
84+
cp $HERMES_WS_DIR/dSYM/Release/hermes.framework.dSYM ./android/ios-artifacts/artifacts/hermes-framework-dSYM-release.tar.gz
85+
- name: Print Artifacts Directory
86+
shell: bash
87+
run: ls -lR ./android/ios-artifacts/artifacts/
88+
- name: Setup node.js
89+
uses: ./.github/actions/setup-node
90+
- name: Install dependencies
91+
uses: ./.github/actions/yarn-install
92+
- name: Publish artifacts
93+
shell: bash
94+
run: |
95+
node ./utils/scripts/hermes/publish-artifacts.js -t ${{ inputs.release-type }}

.github/workflows/rn-build-hermes.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,44 @@
11
name: RN Build Hermes
22

33
on:
4+
workflow_dispatch:
5+
inputs:
6+
release-type:
7+
description: 'Release type (release, commitly, dry-run)'
8+
required: false
9+
default: 'dry-run'
410
pull_request:
511
push:
612
branches:
713
- main
14+
tags:
15+
- "v0.*.*" # This should match v0.X.Y
816

917
jobs:
18+
set_release_type:
19+
runs-on: ubuntu-latest
20+
if: github.repository == 'facebook/hermes'
21+
outputs:
22+
RELEASE_TYPE: ${{ steps.set_release_type.outputs.RELEASE_TYPE }}
23+
env:
24+
EVENT_NAME: ${{ github.event_name }}
25+
REF: ${{ github.ref }}
26+
steps:
27+
- id: set_release_type
28+
run: |
29+
if [[ $EVENT_NAME == "push" && $REF == refs/tags/v* ]]; then
30+
echo "Setting release type to release"
31+
echo "RELEASE_TYPE=release" >> $GITHUB_OUTPUT
32+
elif [[ $EVENT_NAME == "push" && $REF == refs/heads/main ]]; then
33+
echo "Setting release type to commitly"
34+
echo "RELEASE_TYPE=commitly" >> $GITHUB_OUTPUT
35+
elif [[ $EVENT_NAME == "workflow_dispatch" ]]; then
36+
echo "Setting release type to ${{ github.event.inputs.release-type }}"
37+
echo "RELEASE_TYPE=${{ github.event.inputs.release-type }}" >> $GITHUB_OUTPUT
38+
else
39+
echo "Setting release type to dry-run"
40+
echo "RELEASE_TYPE=dry-run" >> $GITHUB_OUTPUT
41+
fi
1042
build_hermesc_apple:
1143
uses: ./.github/workflows/build-hermesc-apple.yml
1244
build_apple_slices_hermes:
@@ -21,11 +53,26 @@ jobs:
2153
uses: ./.github/workflows/build-hermesc-windows.yml
2254
build_android:
2355
uses: ./.github/workflows/build-android.yml
56+
needs: set_release_type
2457
secrets: inherit
58+
with:
59+
release-type: ${{ needs.set_release_type.outputs.RELEASE_TYPE }}
2560
build_emscripten:
2661
uses: ./.github/workflows/build-emscripten.yml
2762
test-apple-runtime:
2863
needs: build_hermes_macos
2964
uses: ./.github/workflows/test-apple-runtime.yml
3065
run-tests:
3166
uses: ./.github/workflows/run-tests.yml
67+
publish:
68+
uses: ./.github/workflows/publish.yml
69+
needs:
70+
[
71+
set_release_type,
72+
build_hermes_macos,
73+
build_hermesc_linux,
74+
build_hermesc_windows,
75+
build_android,
76+
]
77+
with:
78+
release-type: ${{ needs.set_release_type.outputs.RELEASE_TYPE }}

android/build-logic/src/main/kotlin/publish.gradle.kts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ plugins {
1010
id("signing")
1111
}
1212

13+
val isSnapshot: Boolean = findProperty("isSnapshot")?.toString()?.toBoolean() ?: false
1314
val signingKey: String? = findProperty("SIGNING_KEY")?.toString()
1415
val signingPwd: String? = findProperty("SIGNING_PWD")?.toString()
1516

@@ -20,9 +21,16 @@ publishing {
2021
create<MavenPublication>("release") {
2122
afterEvaluate {
2223
from(components["default"])
23-
version = project.version.toString()
24-
groupId = project.group.toString()
24+
25+
version =
26+
if (isSnapshot) {
27+
"${project.version}-SNAPSHOT"
28+
} else {
29+
project.version.toString()
30+
}
31+
2532
artifactId = "hermes-android"
33+
groupId = project.group.toString()
2634
}
2735

2836
pom {

android/build.gradle.kts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import org.apache.tools.ant.taskdefs.condition.Os
1111
plugins {
1212
id("maven-publish")
1313
id("signing")
14+
alias(libs.plugins.nexus.publish)
1415
alias(libs.plugins.android.library)
1516
alias(libs.plugins.download)
1617
id("publish")
@@ -23,6 +24,19 @@ version = project.findProperty("VERSION_NAME")?.toString()!!
2324
val cmakeVersion = System.getenv("CMAKE_VERSION") ?: libs.versions.cmake.get()
2425
val cmakePath = "${getSDKPath()}/cmake/$cmakeVersion"
2526
val cmakeBinaryPath = "${cmakePath}/bin/cmake"
27+
val sonatypeUsername = findProperty("SONATYPE_USERNAME")?.toString()
28+
val sonatypePassword = findProperty("SONATYPE_PASSWORD")?.toString()
29+
30+
nexusPublishing {
31+
repositories {
32+
sonatype {
33+
username.set(sonatypeUsername)
34+
password.set(sonatypePassword)
35+
nexusUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/service/local/"))
36+
snapshotRepositoryUrl.set(uri("https://central.sonatype.com/repository/maven-snapshots/"))
37+
}
38+
}
39+
}
2640

2741
fun getSDKPath(): String {
2842
val androidSdkRoot = System.getenv("ANDROID_SDK_ROOT")

android/cppruntime/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ android {
3434

3535
externalNativeBuild {
3636
cmake {
37-
version hermesUtils.cmakeVersion
37+
version = hermesUtils.cmakeVersion
3838
path "src/main/cpp/CMakeLists.txt"
3939
buildStagingDirectory = "${hermesUtils.hermesWs}/staging/cppruntime"
4040
buildStagingDirectory.mkdirs()

android/gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ download = "5.4.0"
1414
fbjni = "0.7.0"
1515
kotlin = "2.1.20"
1616
ktfmt = "0.22.0"
17+
nexus-publish = "2.0.0"
1718
yoga-proguard-annotations = "1.19.0"
1819

1920
[libraries]
@@ -25,4 +26,5 @@ yoga-proguard-annotations = { module = "com.facebook.yoga:proguard-annotations",
2526
android-library = { id = "com.android.library", version.ref = "agp" }
2627
download = { id = "de.undercouch.download", version.ref = "download" }
2728
ktfmt = { id = "com.ncorti.ktfmt.gradle", version.ref = "ktfmt" }
29+
nexus-publish = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "nexus-publish" }
2830
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }

android/intltest/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ task prepareTests() {
5757

5858
// TODO: Figure out how to deduplicate this file and intl/build.gradle
5959
android {
60-
namespace "com.facebook.hermes.intltest"
60+
namespace = "com.facebook.hermes.intltest"
6161
compileSdk = hermesUtils.compileSdk
6262
ndkVersion = hermesUtils.ndkVersion
6363

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
plugins {
9+
id("maven-publish")
10+
id("publish")
11+
}
12+
13+
group = "com.facebook.hermes"
14+
15+
version = project.findProperty("VERSION_NAME")?.toString()!!
16+
17+
configurations.maybeCreate("iosArtifacts")
18+
19+
// Those artifacts should be placed inside the `artifacts/hermes-ios-*.tar.gz` location.
20+
val hermesiOSDebugArtifactFile: RegularFile =
21+
layout.projectDirectory.file("artifacts/hermes-ios-debug.tar.gz")
22+
val hermesiOSDebugArtifact: PublishArtifact =
23+
artifacts.add("iosArtifacts", hermesiOSDebugArtifactFile) {
24+
type = "tgz"
25+
extension = "tar.gz"
26+
classifier = "hermes-ios-debug"
27+
}
28+
val hermesiOSReleaseArtifactFile: RegularFile =
29+
layout.projectDirectory.file("artifacts/hermes-ios-release.tar.gz")
30+
val hermesiOSReleaseArtifact: PublishArtifact =
31+
artifacts.add("iosArtifacts", hermesiOSReleaseArtifactFile) {
32+
type = "tgz"
33+
extension = "tar.gz"
34+
classifier = "hermes-ios-release"
35+
}
36+
37+
// Those artifacts should be placed inside the `artifacts/hermes-*.framework.dSYM` location
38+
val hermesDSYMDebugArtifactFile: RegularFile =
39+
layout.projectDirectory.file("artifacts/hermes-framework-dSYM-debug.tar.gz")
40+
val hermesDSYMDebugArtifact: PublishArtifact =
41+
artifacts.add("iosArtifacts", hermesDSYMDebugArtifactFile) {
42+
type = "tgz"
43+
extension = "tar.gz"
44+
classifier = "hermes-framework-dSYM-debug"
45+
}
46+
val hermesDSYMReleaseArtifactFile: RegularFile =
47+
layout.projectDirectory.file("artifacts/hermes-framework-dSYM-release.tar.gz")
48+
val hermesDSYMReleaseArtifact: PublishArtifact =
49+
artifacts.add("iosArtifacts", hermesDSYMReleaseArtifactFile) {
50+
type = "tgz"
51+
extension = "tar.gz"
52+
classifier = "hermes-framework-dSYM-release"
53+
}
54+
55+
publishing {
56+
publications {
57+
getByName("release", MavenPublication::class) {
58+
artifactId = "hermes-ios"
59+
artifact(hermesiOSDebugArtifact)
60+
artifact(hermesiOSReleaseArtifact)
61+
artifact(hermesDSYMDebugArtifact)
62+
artifact(hermesDSYMReleaseArtifact)
63+
}
64+
}
65+
}

utils/scripts/hermes/consts.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict
8+
* @format
9+
*/
10+
11+
const path = require('path');
12+
13+
/**
14+
* The absolute path to the repo root.
15+
*/
16+
const REPO_ROOT /*: string */ = path.resolve(__dirname, '../../..');
17+
18+
/**
19+
* The absolute path to the android directory.
20+
*/
21+
const ANDROID_DIR /*: string */ = path.join(REPO_ROOT, 'android');
22+
23+
module.exports = {
24+
REPO_ROOT,
25+
ANDROID_DIR,
26+
};

0 commit comments

Comments
 (0)