+
Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

ci: publish workflow for @rometools/js-api package #3402

Merged
merged 1 commit into from
Oct 17, 2022
Merged
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
149 changes: 149 additions & 0 deletions .github/workflows/release_js_api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
name: Release JavaScript API
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * 2-6'
push:
branches:
- main
paths:
- npm/js-api/package.json

jobs:
check:
name: Check version
runs-on: ubuntu-latest
outputs:
version: ${{ env.version }}
prerelease: ${{ env.prerelease }}
nightly: ${{ env.nightly }}
version_changed: ${{ steps.version.outputs.changed }}
steps:
- uses: actions/checkout@v3

- name: Check nightly status
id: nightly
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
run: echo "nightly=true" >> $GITHUB_ENV

- name: Check version changes
uses: EndBug/version-check@v1
if: env.nightly != 'true'
id: version
with:
diff-search: true
file-name: npm/js-api/package.json

- name: Set version name
run: echo "version=${{ steps.version.outputs.version }}" >> $GITHUB_ENV

- name: Check prerelease status
id: prerelease
if: env.nightly == 'true'
run: echo "prerelease=true" >> $GITHUB_ENV

- name: Check version status
if: steps.version.outputs.changed == 'true'
run: 'echo "Version change found! New version: ${{ steps.version.outputs.version }} (${{ steps.version.outputs.version_type }})"'

build:
name: Package JavaScript APIs
runs-on: ubuntu-latest

needs: check
if: needs.check.outputs.version_changed == 'true' || needs.check.outputs.nightly == 'true'
outputs:
version: ${{ env.version }}
prerelease: ${{ env.prerelease }}

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 1

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 14.x

- name: Cache pnpm modules
uses: actions/cache@v3
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-
- uses: pnpm/action-setup@v2.1.0
with:
version: 7

- name: Set release infos
if: needs.check.outputs.prerelease == 'true'
run: |
echo "prerelease=true" >> $GITHUB_ENV
node npm/rome/scripts/update-nightly-version.mjs >> $GITHUB_ENV
- name: Set release infos
if: needs.check.outputs.prerelease != 'true'
run: |
echo "prerelease=false" >> $GITHUB_ENV
echo "version=${{ needs.check.outputs.version }}" >> $GITHUB_ENV

- name: Build package
working-directory: npm/js-api
run: |
pnpm i
pnpm build

- name: Upload JS API artifact
uses: actions/upload-artifact@v3
with:
name: js-api
path: |
./npm/js-api/dist
if-no-files-found: error

publish:
name: Publish
runs-on: ubuntu-latest
needs: build
environment: npm-publish
steps:
- uses: actions/checkout@v3

- name: Download package artifact
uses: actions/download-artifact@v3
with:
name: js-api
path: npm

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 14.x
registry-url: 'https://registry.npmjs.org'

- name: Publish npm package as latest
run: npm publish @rometools/js-api --tag latest --access public
if: needs.build.outputs.prerelease != 'true'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish npm package as nightly
run: npm publish @rometools/js-api --tag nightly --access public
if: needs.build.outputs.prerelease == 'true'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Create GitHub release and tag
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
name: JavaScript APIs v${{ needs.build.outputs.version }}
tag_name: js-api/v${{ needs.build.outputs.version }}
draft: false
prerelease: ${{ needs.build.outputs.prerelease == 'true' }}
files: |
dist/*
fail_on_unmatched_files: true
generate_release_notes: true
26 changes: 26 additions & 0 deletions editors/vscode/scripts/update-nightly-version.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { resolve } from "node:path";
import { fileURLToPath } from "node:url";
import * as fs from "node:fs";

const ROMECLI_ROOT = resolve(fileURLToPath(import.meta.url), "../");
const MANIFEST_PATH = resolve(ROMECLI_ROOT, "package.json");

const rootManifest = JSON.parse(
fs.readFileSync(MANIFEST_PATH).toString("utf-8"),
);

let version = rootManifest["version"];
if (
typeof process.env.GITHUB_SHA !== "string" ||
process.env.GITHUB_SHA === ""
) {
throw new Error("GITHUB_SHA environment variable is undefined");
}

version += `.${process.env.GITHUB_SHA.substring(0, 7)}`;
rootManifest["version"] = version;

const content = JSON.stringify(rootManifest);
fs.writeFileSync(MANIFEST_PATH, content);

console.log(`version=${version}`);
3 changes: 3 additions & 0 deletions npm/js-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ Official JavaScript bindings for the package [rome](https://www.npmjs.com/packag
## Installation

```shell
npm i rome
npm i @rometools/js-api
```

The package `rome` is marked as **peer dependency** of this package.

## Usage

```js
Expand Down
7 changes: 6 additions & 1 deletion npm/js-api/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@rometools/js-api",
"version": "0.0.0",
"description": "JavaScript bindings for the Rome package",
"description": "JavaScript APIs for the Rome package",
"scripts": {
"tsc": "tsc --noEmit",
"format": "cargo rome-cli-dev format ./ --write",
Expand All @@ -15,11 +15,16 @@
"test:ci": "vitest --run",
"build": "tsc "
},
"files": [
"README.md",
"dist/"
],
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"keywords": [
"JavaScript",
"bindings",
"APIs",
"rome"
],
"license": "MIT",
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载