Skip to content

Commit f101962

Browse files
fix: make actions work for the initial release (#1)
* fix: make actions work for the initial release * fix docs * fix: actions location * fix: typo * fix: pass missing github-token * fix description * switch branch to v1 tag --------- Co-authored-by: Michał Pierzchała <[email protected]>
1 parent 3b22659 commit f101962

File tree

12 files changed

+150
-56
lines changed

12 files changed

+150
-56
lines changed

.github/actions/find-artifact/action.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,26 @@ inputs:
2020
outputs:
2121
artifact-id:
2222
description: 'The ID of the artifact'
23+
value: ${{ steps.find-artifact.outputs.artifact-id }}
2324
artifact-url:
2425
description: 'The URL of the artifact'
26+
value: ${{ steps.find-artifact.outputs.artifact-url }}
2527
artifact-ids:
2628
description: 'All IDs of the artifacts matching the name'
29+
value: ${{ steps.find-artifact.outputs.artifact-ids }}
2730
runs:
28-
using: 'node20'
29-
main: 'index.js'
31+
using: 'composite'
32+
steps:
33+
- name: Install dependencies
34+
run: npm install
35+
shell: bash
36+
working-directory: ${{ github.action_path }}
37+
- name: Find artifact
38+
id: find-artifact
39+
env:
40+
INPUT_NAME: ${{ inputs.name }}
41+
INPUT_RE_SIGN: ${{ inputs.re-sign }}
42+
INPUT_GITHUB_TOKEN: ${{ inputs.github-token }}
43+
INPUT_REPOSITORY: ${{ inputs.repository }}
44+
run: node ${{ github.action_path }}/index.mjs
45+
shell: bash
Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const core = require('@actions/core');
2-
const github = require('@actions/github');
1+
import * as core from "@actions/core";
2+
import * as github from "@actions/github";
33

44
const perPage = 100; // Maximum allowed by GitHub API
55

@@ -9,8 +9,8 @@ async function fetchArtifacts(octokit, repository, name) {
99

1010
while (true) {
1111
const response = await octokit.rest.actions.listArtifactsForRepo({
12-
owner: repository.split('/')[0],
13-
repo: repository.split('/')[1],
12+
owner: repository.split("/")[0],
13+
repo: repository.split("/")[1],
1414
name,
1515
per_page: perPage,
1616
page,
@@ -31,18 +31,31 @@ async function fetchArtifacts(octokit, repository, name) {
3131
}
3232

3333
function getPrNumber() {
34-
if (github.context.eventName === 'pull_request') {
34+
if (github.context.eventName === "pull_request") {
3535
return github.context.payload.pull_request.number;
3636
}
3737
return undefined;
3838
}
3939

4040
async function run() {
4141
try {
42-
const token = core.getInput('github-token');
43-
const repository = core.getInput('repository');
44-
const name = core.getInput('name');
45-
const reSign = core.getInput('re-sign');
42+
const token = core.getInput("github_token") || process.env.GITHUB_TOKEN;
43+
44+
if (!token) {
45+
throw new Error("GitHub token is required");
46+
}
47+
48+
const repository = core.getInput("repository");
49+
if (!repository) {
50+
throw new Error("Repository is required");
51+
}
52+
53+
const name = core.getInput("name");
54+
if (!name) {
55+
throw new Error("Artifact name is required");
56+
}
57+
58+
const reSign = core.getInput("re_sign");
4659
const prNumber = getPrNumber();
4760

4861
const octokit = github.getOctokit(token);
@@ -61,20 +74,20 @@ async function run() {
6174
for (const artifact of artifacts) {
6275
console.log(
6376
`- ID: ${artifact.id}, Name: ${artifact.name}, Size: ${formatSize(
64-
artifact.size_in_bytes,
65-
)}, Expires at: ${artifact.expires_at}`,
77+
artifact.size_in_bytes
78+
)}, Expires at: ${artifact.expires_at}`
6679
);
6780
}
6881

69-
const firstArtifact = artifacts.find(artifact => !artifact.expired);
82+
const firstArtifact = artifacts.find((artifact) => !artifact.expired);
7083
console.log(`First artifact: ${JSON.stringify(firstArtifact, null, 2)}`);
7184

7285
const url = formatDownloadUrl(
7386
repository,
7487
firstArtifact.workflow_run.id,
75-
firstArtifact.id,
88+
firstArtifact.id
7689
);
77-
console.log('Stable download URL:', url);
90+
console.log("Stable download URL:", url);
7891

7992
let artifactName = name;
8093
// There are artifacts from PR but the base artifact is gone, recreate with the original name
@@ -84,12 +97,12 @@ async function run() {
8497
} else if (prNumber && reSign) {
8598
artifactName = `${name}-${prNumber}`;
8699
}
87-
core.setOutput('artifact-name', artifactName);
88-
core.setOutput('artifact-id', firstArtifact.id);
89-
core.setOutput('artifact-url', url);
100+
core.setOutput("artifact-name", artifactName);
101+
core.setOutput("artifact-id", firstArtifact.id);
102+
core.setOutput("artifact-url", url);
90103
core.setOutput(
91-
'artifact-ids',
92-
artifactsByPrNumber.map(artifact => artifact.id).join(' '),
104+
"artifact-ids",
105+
artifactsByPrNumber.map((artifact) => artifact.id).join(" ")
93106
);
94107
} catch (error) {
95108
core.setFailed(`Action failed with error: ${error.message}`);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "find-artifact",
3+
"version": "1.0.0",
4+
"description": "Find existing artifact for RNEF builds",
5+
"main": "index.mjs",
6+
"dependencies": {
7+
"@actions/core": "^1.11.1",
8+
"@actions/github": "^6.0.0"
9+
}
10+
}

.github/actions/rnef-native-fingerprint/action.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ inputs:
1111
outputs:
1212
hash:
1313
description: 'The fingerprint hash'
14+
value: ${{ steps.fingerprint.outputs.hash }}
1415
runs:
15-
using: 'node20'
16-
main: 'index.mjs'
16+
using: 'composite'
17+
steps:
18+
- name: Install dependencies
19+
run: npm install
20+
shell: bash
21+
working-directory: ${{ github.action_path }}
22+
- name: Run fingerprint
23+
id: fingerprint
24+
env:
25+
INPUT_PLATFORM: ${{ inputs.platform }}
26+
INPUT_WORKING_DIRECTORY: ${{ inputs.working-directory }}
27+
run: node ${{ github.action_path }}/index.mjs
28+
shell: bash
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import path from 'node:path';
2-
import core from '@actions/core';
3-
import {getConfig} from '@rnef/config';
4-
import {nativeFingerprint} from '@rnef/tools';
1+
import path from "node:path";
2+
import core from "@actions/core";
3+
import { getConfig } from "@rnef/config";
4+
import { nativeFingerprint } from "@rnef/tools";
55

6-
const ALLOWED_PLATFORMS = ['android', 'ios'];
6+
const ALLOWED_PLATFORMS = ["android", "ios"];
77

88
async function run() {
9-
const platform = core.getInput('platform');
10-
const workingDirectory = core.getInput('working-directory');
9+
const platform = core.getInput("platform");
10+
const workingDirectory = core.getInput("working-directory");
1111
if (!ALLOWED_PLATFORMS.includes(platform)) {
1212
throw new Error(`Invalid platform: ${platform}`);
1313
}
@@ -22,10 +22,10 @@ async function run() {
2222
...fingerprintOptions,
2323
});
2424

25-
console.log('Hash:', fingerprint.hash);
26-
console.log('Sources:', fingerprint.sources);
25+
console.log("Hash:", fingerprint.hash);
26+
console.log("Sources:", fingerprint.sources);
2727

28-
core.setOutput('hash', fingerprint.hash);
28+
core.setOutput("hash", fingerprint.hash);
2929
}
3030

3131
await run();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "rnef-native-fingerprint",
3+
"version": "1.0.0",
4+
"description": "Generate native fingerprint for RNEF builds",
5+
"main": "index.mjs",
6+
"dependencies": {
7+
"@rnef/config": "^0.4.1",
8+
"@actions/core": "^1.11.1"
9+
}
10+
}
Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: 'Post Build'
2-
description: 'Post Build info'
2+
description: 'Post build comment for RNEF builds'
33

44
inputs:
55
artifact-url:
@@ -10,8 +10,19 @@ inputs:
1010
required: true
1111
github-token:
1212
description: A GitHub Personal Access Token with write access to the project
13-
required: false
14-
default: ${{ github.token }}
13+
required: true
1514
runs:
16-
using: 'node20'
17-
main: 'index.js'
15+
using: 'composite'
16+
steps:
17+
- name: Install dependencies
18+
run: npm install
19+
shell: bash
20+
working-directory: ${{ github.action_path }}
21+
- name: Post build
22+
id: post-build
23+
env:
24+
INPUT_ARTIFACT_URL: ${{ inputs.artifact-url }}
25+
INPUT_TITLE: ${{ inputs.title }}
26+
INPUT_GITHUB_TOKEN: ${{ inputs.github-token }}
27+
run: node ${{ github.action_path }}/index.mjs
28+
shell: bash
Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
1-
const core = require('@actions/core');
2-
const github = require('@actions/github');
1+
import core from "@actions/core";
2+
import github from "@actions/github";
33

44
async function run() {
5-
const token = core.getInput('github-token');
6-
const titleInput = core.getInput('title');
7-
const artifactUrl = core.getInput('artifact-url');
5+
const token = core.getInput("github_token") || process.env.GITHUB_TOKEN;
6+
if (!token) {
7+
throw new Error("GitHub token is required");
8+
}
9+
10+
const titleInput = core.getInput("title");
11+
if (!titleInput) {
12+
throw new Error("Title is required");
13+
}
14+
15+
const artifactUrl = core.getInput("artifact_url");
16+
if (!artifactUrl) {
17+
throw new Error("Artifact URL is required");
18+
}
819

920
const title = `## ${titleInput}`;
1021
const body = `🔗 [Download link](${artifactUrl}).\n\n
1122
Note: if the download link expires, please re-run the workflow to generate a new build.\n\n
1223
*Generated at ${new Date().toISOString()} UTC*\n`;
1324

1425
const octokit = github.getOctokit(token);
15-
const {data: comments} = await octokit.rest.issues.listComments({
26+
const { data: comments } = await octokit.rest.issues.listComments({
1627
...github.context.repo,
1728
issue_number: github.context.issue.number,
1829
});
1930

2031
const botComment = comments.find(
21-
comment =>
22-
comment.user.login === 'github-actions[bot]' &&
23-
comment.body.includes(title),
32+
(comment) =>
33+
comment.user.login === "github-actions[bot]" &&
34+
comment.body.includes(title)
2435
);
2536

2637
if (botComment) {
@@ -29,14 +40,14 @@ Note: if the download link expires, please re-run the workflow to generate a new
2940
comment_id: botComment.id,
3041
body: `${title}\n\n${body}`,
3142
});
32-
console.log('Updated comment');
43+
console.log("Updated comment");
3344
} else {
3445
await octokit.rest.issues.createComment({
3546
...github.context.repo,
3647
issue_number: github.context.issue.number,
3748
body: `${title}\n\n${body}`,
3849
});
39-
console.log('Created comment');
50+
console.log("Created comment");
4051
}
4152
}
4253

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "rnef-post-build",
3+
"version": "1.0.0",
4+
"description": "Post build comment for RNEF builds",
5+
"main": "index.mjs",
6+
"dependencies": {
7+
"@actions/core": "^1.11.1",
8+
"@actions/github": "^6.0.0"
9+
}
10+
}

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
uses: callstackincubator/android@v1
3333
with:
3434
variant: 'debug' # or else
35+
github-token: ${{ secrets.GITHUB_TOKEN }}
3536
# For release builds, add these:
3637
# sign: true
3738
# keystore-base64: ${{ secrets.KEYSTORE_BASE64 }}
@@ -45,7 +46,7 @@ jobs:
4546

4647
| Input | Description | Required | Default |
4748
| ------------------------- | --------------------------------------- | -------- | --------------------- |
48-
| `github-token` | GitHub Token | No | `${{ github.token }}` |
49+
| `github-token` | GitHub Token | Yes | - |
4950
| `working-directory` | Working directory for the build command | No | `.` |
5051
| `validate-gradle-wrapper` | Whether to validate the Gradle wrapper | No | `true` |
5152
| `variant` | Build variant (debug/release) | No | `debug` |

0 commit comments

Comments
 (0)