Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/ISSUE_TEMPLATE/compiled.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: ⚙️ --compiled report
description: A problem with a release compiled to Swift or Kotlin (`ns build|run <platform> --compiled`). Usually filled in by `ns compiled report`.
title: '[compiled] '
labels: [compiled]

body:
- type: markdown
attributes:
value: |
Run `ns compiled report` in your project after a failed `--compiled` build (or with `--error <file>` for a runtime error): it fills in this form, and first looks for an issue with the same signature so you can add a 👍 instead.

Each report becomes a test case in the compiler and then a fix. The labeler reads Platform, Framework and Kind exactly as written below.

- type: input
id: platform
attributes:
label: Platform
description: '`ios` or `android`'
validations:
required: true

- type: input
id: framework
attributes:
label: Framework
description: '`angular`, `vue`, `svelte`, `react`, `solid` or `xml` (XML with TypeScript or JavaScript)'
validations:
required: true

- type: input
id: kind
attributes:
label: Kind
description: '`compile-refused` (the compiler refused a construct), `native-compile` (the generated Swift or Kotlin did not compile) or `runtime` (the compiled app failed while running)'
validations:
required: true

- type: input
id: signature
attributes:
label: Signature
description: The hash `ns compiled report` puts in the title. Reports with the same signature are the same problem.

- type: textarea
id: diagnostic
attributes:
label: Diagnostic
description: The error, as the compiler, Swift, Kotlin, Gradle, Xcode or the app printed it.
render: text
validations:
required: true

- type: textarea
id: source
attributes:
label: Source
description: Where in your code it happens (file:line), and the lines around it if you choose to share them.

- type: textarea
id: environment
attributes:
label: Environment
description: CLI, `@nativescript/compiler`, `@nativescript/core` and framework versions, Xcode or Gradle, OS and dependencies.
validations:
required: true
64 changes: 64 additions & 0 deletions .github/scripts/compiled-issue-labels.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Labels a `--compiled` report from its Platform, Framework and Kind fields, which the
// compiled.yml issue form writes, and `ns compiled report` writes the same way when it files through gh.
import { readFileSync } from 'node:fs';
import { pathToFileURL } from 'node:url';

const FIELDS = {
platform: { label: 'Platform', values: ['ios', 'android'], color: '1d76db' },
framework: { label: 'Framework', values: ['angular', 'vue', 'svelte', 'react', 'solid', 'xml'], color: '5319e7' },
kind: { label: 'Kind', values: ['compile-refused', 'native-compile', 'runtime'], color: 'd93f0b' },
};

export function readField(body, label) {
return new RegExp(`^###\\s+${label}\\s*\\n+([^\\n]*)`, 'm').exec(body ?? '')?.[1].trim().toLowerCase();
}

export function wantedLabels(body) {
const labels = ['compiled'];
for (const [prefix, { label, values }] of Object.entries(FIELDS)) {
const value = readField(body, label);
if (values.includes(value)) labels.push(`${prefix}:${value}`);
}
return labels;
}

async function main() {
const { issue, repository } = JSON.parse(readFileSync(process.env.GITHUB_EVENT_PATH, 'utf8'));
const api = (path, { method = 'GET', body } = {}) =>
fetch(`https://api.github.com/repos/${repository.full_name}${path}`, {
method,
headers: {
authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
accept: 'application/vnd.github+json',
'x-github-api-version': '2022-11-28',
...(body ? { 'content-type': 'application/json' } : {}),
},
body: body && JSON.stringify(body),
});

const wanted = wantedLabels(issue.body);
const current = issue.labels.map((l) => l.name);
// An edit that changes a field replaces its label.
for (const name of current.filter((n) => /^(platform|framework|kind):/.test(n) && !wanted.includes(n))) {
await api(`/issues/${issue.number}/labels/${encodeURIComponent(name)}`, { method: 'DELETE' });
}

const usable = [];
for (const name of wanted.filter((n) => !current.includes(n))) {
if ((await api(`/labels/${encodeURIComponent(name)}`)).ok) {
usable.push(name);
continue;
}
const color = FIELDS[name.split(':')[0]]?.color ?? 'ededed';
const created = await api('/labels', { method: 'POST', body: { name, color } });
if (created.ok) usable.push(name);
else console.log(`Skipping ${name}: it does not exist and this token cannot create it (${created.status}).`);
}
if (usable.length) {
const added = await api(`/issues/${issue.number}/labels`, { method: 'POST', body: { labels: usable } });
if (!added.ok) throw new Error(`Adding ${usable.join(', ')} failed: ${added.status} ${await added.text()}`);
}
console.log(`#${issue.number}: ${wanted.join(', ')}`);
}

if (import.meta.url === pathToFileURL(process.argv[1]).href) await main();
32 changes: 32 additions & 0 deletions .github/workflows/compiled_issue_labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: 'Label --compiled reports'

on:
issues:
types: [opened, edited]

permissions:
contents: read

jobs:
label:
# The form applies `compiled`; `ns compiled report` filing through gh may not be allowed to set labels, so its title counts too.
if: contains(github.event.issue.labels.*.name, 'compiled') || startsWith(github.event.issue.title, '[compiled]')
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
with:
egress-policy: audit

- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
sparse-checkout: .github/scripts

- name: Apply platform, framework and kind labels
run: node .github/scripts/compiled-issue-labels.mjs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Loading