Skip to content

Commit

Permalink
* Deploy to npm using GitHub Action.
Browse files Browse the repository at this point in the history
* Added CLA agreement.
  • Loading branch information
cowwoc committed Oct 31, 2024
1 parent f92aae5 commit 96f5949
Show file tree
Hide file tree
Showing 15 changed files with 962 additions and 656 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
cache: pnpm

- name: Update dependencies
run: pnpm install
run: pnpm install --frozen-lockfile --strict-peer-dependencies

- name: build
run: pnpm run build.debug
- name: Build
run: pnpm run build
44 changes: 44 additions & 0 deletions .github/workflows/cla.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Source: https://github.com/contributor-assistant/github-action
name: "CLA Assistant"
on:
issue_comment:
types: [ created ]
pull_request_target:
types: [ opened,closed,synchronize ]

# explicitly configure permissions, in case your GITHUB_TOKEN workflow permissions are set to read-only in repository settings
permissions:
actions: write
contents: write
pull-requests: write
statuses: write

jobs:
CLAAssistant:
runs-on: ubuntu-latest
steps:
- name: "CLA Assistant"
if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA') || github.event_name == 'pull_request_target'
uses: contributor-assistant/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# the below token should have repo scope and must be manually added by you in the repository's secret
# This token is required only if you have configured to store the signatures in a remote repository/organization
PERSONAL_ACCESS_TOKEN: ${{ secrets.CLA_ACCESS_TOKEN }}
with:
path-to-signatures: 'cla/version1/signatures/cla.json'
path-to-document: 'https://github.com/cowwoc/requirements.js/blob/master/cla/version1/cla.md' # e.g. a CLA or a DCO document
# branch should not be protected
branch: 'main'
allowlist: cowwoc

# the followings are the optional inputs - If the optional inputs are not given, then default values will be taken
#remote-organization-name: enter the remote organization name where the signatures should be stored (Default is storing the signatures in the same repository)
#remote-repository-name: enter the remote repository name where the signatures should be stored (Default is storing the signatures in the same repository)
#create-file-commit-message: 'For example: Creating file for storing CLA Signatures'
#signed-commit-message: 'For example: $contributorName has signed the CLA in $owner/$repo#$pullRequestNo'
#custom-notsigned-prcomment: 'pull request comment with Introductory message to ask new contributors to sign'
#custom-pr-sign-comment: 'The signature to be committed in order to sign the CLA'
#custom-allsigned-prcomment: 'pull request comment when all contributors has signed, defaults to **CLA Assistant Lite bot** All Contributors have signed the CLA.'
#lock-pullrequest-aftermerge: false - if you don't want this bot to automatically lock the pull request after merging (default - true)
#use-dco-flag: true - If you are using DCO instead of CLA
138 changes: 138 additions & 0 deletions .github/workflows/deploy_to_npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
name: Deploy to npm
on:
workflow_dispatch:
concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true
jobs:
open-release:
runs-on: ubuntu-latest
outputs:
INITIAL_MASTER_POSITION: ${{ steps.create-tag.outputs.INITIAL_MASTER_POSITION }}
INITIAL_GH_PAGES_POSITION: ${{ steps.create-tag.outputs.INITIAL_GH_PAGES_POSITION }}
TAG: ${{ steps.create-tag.outputs.TAG }}
VERSION: ${{ steps.create-tag.outputs.VERSION }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}

- name: Configure Git User
run: |
git config user.email "[email protected]"
git config user.name "Gili Tzabari"
# Getting the current git tag: https://stackoverflow.com/a/50465671/14731
#
# Setting a GitHub Action output parameter:
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter
# Extracting the release version number: https://stackoverflow.com/a/16623897/14731
- name: Create tag
id: create-tag
run: |
echo "INITIAL_MASTER_POSITION=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
./mvnw release:prepare --batch-mode -V -e
TAG=$(git describe --tag --abbrev=0)
echo "TAG=${TAG}" >> "$GITHUB_OUTPUT"
echo "VERSION=${TAG#"release-"}" >> "$GITHUB_OUTPUT"
deploy:
name: Deploy
needs: open-release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.open-release.outputs.TAG }}
token: ${{ secrets.WORKFLOW_TOKEN }}
fetch-depth: 0

- name: Install node
uses: actions/setup-node@v4
with:
node-version: latest
registry-url: "https://registry.npmjs.org"

- name: Install pnpm
run: |
corepack enable
corepack prepare pnpm@latest --activate
# pnpm dependencies cannot be cached until pnpm is installed
# WORKAROUND: https://github.com/actions/setup-node/issues/531
- name: Extract cached dependencies
uses: actions/setup-node@v4
with:
cache: pnpm

- name: Test build
run: pnpm run build

- name: Deploy to npm
run: |
cd target\publish
copy ..\..\pnpm-lock.yaml .
pnpm publish --provenance --access=public
mkdir --parents "${{ needs.open-release.outputs.VERSION }}/docs"
mv target/reports/apidocs "${{ needs.open-release.outputs.VERSION }}/docs/api"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

# Cleanup on failure: https://stackoverflow.com/a/74562058/14731
on-failure:
needs: [ open-release, deploy ]
runs-on: ubuntu-latest
if: ${{ failure() || cancelled() }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
token: ${{ secrets.WORKFLOW_TOKEN }}
fetch-depth: 0
- name: Install node
uses: actions/setup-node@v4
with:
node-version: latest
registry-url: "https://registry.npmjs.org"

- name: Install pnpm
run: |
corepack enable
corepack prepare pnpm@latest --activate
# pnpm dependencies cannot be cached until pnpm is installed
# WORKAROUND: https://github.com/actions/setup-node/issues/531
- name: Extract cached dependencies
uses: actions/setup-node@v4
with:
cache: pnpm

- name: Restore the master ref to its original position
if: needs.open-release.outputs.INITIAL_MASTER_POSITION != ''
run: |
CURRENT_REF_POSITION=$(git rev-parse HEAD)
if [ "${CURRENT_REF_POSITION}" != "${{ needs.open-release.outputs.INITIAL_MASTER_POSITION }}" ]; then
git reset --hard ${{ needs.open-release.outputs.INITIAL_MASTER_POSITION }}
if [ "${{ github.ref_type }}" == "tag" ]; then
git ${{ github.ref_type }} -f ${{ github.ref_name }}
fi
git push -f origin ${{ github.ref_name }}
fi
- name: Delete tag
if: needs.open-release.outputs.TAG != ''
run: |
git push --delete origin ${{ needs.open-release.outputs.TAG }}
- name: Restore the gh-pages ref to its original position
if: needs.open-release.outputs.INITIAL_GH_PAGES_POSITION != ''
run: |
CURRENT_REF_POSITION=$(git rev-parse HEAD)
if [ "${CURRENT_REF_POSITION}" != "${{ needs.open-release.outputs.INITIAL_GH_PAGES_POSITION }}" ]; then
git reset --hard ${{ needs.open-release.outputs.INITIAL_GH_PAGES_POSITION }}
if [ "${{ github.ref_type }}" == "tag" ]; then
git ${{ github.ref_type }} -f ${{ github.ref_name }}
fi
git push -f origin ${{ github.ref_name }}
fi
1 change: 1 addition & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 6 additions & 15 deletions build/Project.mts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {minify} from "terser";
import {spawn} from "child_process";
import {default as chokidar} from "chokidar";
import eslintConfig from "../eslint.config.mjs";
import {mode} from "./mode.mjs";
import parseArgs from "minimist";
import {
diary,
Expand All @@ -33,12 +32,6 @@ const rollupTypescript = _rollupTypescript as unknown as (options?: RollupTypesc
class Project
{
private static readonly outputDirectory = "target";
private readonly mode: string;

constructor(mode: string)
{
this.mode = mode;
}

/**
* @param sources - the files to lint
Expand Down Expand Up @@ -190,8 +183,7 @@ class Project
sourcemap: true,
dir: `${Project.outputDirectory}/publish/browser`
});
if (this.mode === "RELEASE")
await this.minifyBrowserSources();
await this.minifyBrowserSources();
}
catch (error)
{
Expand Down Expand Up @@ -298,22 +290,21 @@ class Project
const binPath = path.posix.resolve("./node_modules/.bin");
const c8Path = path.posix.resolve(binPath + "/c8");
const mochaPath = path.posix.resolve(binPath + "/mocha");
const mode = this.mode;

// https://stackoverflow.com/a/53204227/14731
const promise = new Promise(function (resolve, reject)
const promise = new Promise(function(resolve, reject)
{
// https://stackoverflow.com/a/14231570/14731
const process = spawn(c8Path, [mochaPath, "--parallel", "./test/**/*.mts", "--mode=" + mode],
const process = spawn(c8Path, [mochaPath, "--parallel", "./test/**/*.mts"],
{
shell: true,
stdio: "inherit"
});
process.on("error", function (err)
process.on("error", function(err)
{
reject(err);
});
process.on("close", function (code)
process.on("close", function(code)
{
if (code !== 0)
reject(new Error(`Exit code: ${code}`));
Expand Down Expand Up @@ -470,7 +461,7 @@ const __filename = path.posix.basename(posixPath);
const log = diary(__filename);

const startTime = performance.now();
const project = new Project(mode);
const project = new Project();
const command = parseArgs(process.argv.slice(2));
switch (command._[0])
{
Expand Down
10 changes: 0 additions & 10 deletions build/mode.mts

This file was deleted.

18 changes: 18 additions & 0 deletions cla/version1/cla.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Contributor License Agreements

Whenever someone wants to submit a patch to open source projects, they must first sign a Contributor License
Agreement (CLA). This allows the contributor to retain their ownership in the code submitted while granting
the project owner the necessary legal rights to use that contribution. The CLA only needs to be signed once
and it covers projects by the same project owner.

## Why do we even have a CLA?

Our CLA allows open source projects administered by the project owner to safely accept code and documentation
from external contributors.

## What's in the CLA?

Our CLAs are based on the Apache Software Foundation's CLAs.

* [Corporate CLA](corporate-cla.md) - For entities signing on behalf of their employees.
* [Individual CLA](individual-cla.md) - For individuals.
71 changes: 71 additions & 0 deletions cla/version1/corporate-cla.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Software Grant and Corporate Contributor License Agreement

In order to clarify the intellectual property license granted with Contributions from any person or entity,
Gili Tzabari ("The Owner") must have a Contributor License Agreement (CLA) on file that has been signed by
each Contributor, indicating agreement to the license terms below. This license is for your protection as a
Contributor as well as the protection of The Owner and its users; it does not change your rights to use your
own Contributions for any other purpose.

This version of the Agreement allows an entity (the "Corporation") to submit Contributions to The Owner, to
authorize Contributions submitted by its designated employees to The Owner, and to grant copyright and patent
licenses thereto.

You accept and agree to the following terms and conditions for Your present and future Contributions submitted
to The Owner. Except for the license granted herein to The Owner and recipients of software distributed by
The Owner, You reserve all right, title, and interest in and to Your Contributions.

- **Definitions**. "You" (or "Your") shall mean the copyright owner or legal entity authorized by the
copyright owner that is making this Agreement with The Owner. For legal entities, the entity making a
Contribution and all other entities that control, are controlled by, or are under common control with that
entity are considered to be a single Contributor. For the purposes of this definition, "control" means (i)
the power, direct or indirect, to cause the direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial
ownership of such entity.<br>
<br>
"Contribution" shall mean the code, documentation or any original work of authorship, including any
modifications or additions to an existing work, that is intentionally submitted by You to The Owner for
inclusion in, or documentation of, any of the products owned or managed by The Owner (the "Work"). For the
purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent
to The Owner or its representatives, including but not limited to communication on electronic mailing lists,
source code control systems, and issue tracking systems that are managed by, or on behalf of, The Owner for
the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked
or otherwise designated in writing by You as "Not a Contribution."

- **Grant of Copyright License**. Subject to the terms and conditions of this Agreement, You hereby grant to
The Owner and to recipients of software distributed by The Owner a perpetual, worldwide, non-exclusive,
no-charge, royalty-free, irrevocable copyright license to reproduce, prepare derivative works of, publicly
display, publicly perform, sublicense, and distribute Your Contributions and such derivative works.

- **Grant of Patent License**. Subject to the terms and conditions of this Agreement, You hereby grant to The
Owner and to recipients of software distributed by The Owner a perpetual, worldwide, non-exclusive,
no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those
patent claims licensable by You that are necessarily infringed by Your Contribution(s) alone or by
combination of Your Contribution(s) with the Work to which such Contribution(s) was submitted. If any entity
institutes patent litigation against You or any other entity (including a cross-claim or counterclaim in a
lawsuit) alleging that your Contribution, or the Work to which you have contributed, constitutes direct or
contributory patent infringement, then any patent licenses granted to that entity under this Agreement for
that Contribution or Work shall terminate as of the date such litigation is filed.

- You represent that You are legally entitled to grant the above license. You represent further that each
employee of the Corporation designated by You is authorized to submit Contributions on behalf of the
Corporation.

- You represent that each of Your Contributions is Your original creation (see section 7 for submissions on
behalf of others).

- You are not expected to provide support for Your Contributions, except to the extent You desire to provide
support. You may provide support for free, for a fee, or not at all. Unless required by applicable law or
agreed to in writing, You provide Your Contributions on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of
TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.

- Should You wish to submit work that is not Your original creation, You may submit it to The Owner separately
from any Contribution, identifying the complete details of its source and of any license or other
restriction (including, but not limited to, related patents, trademarks, and license agreements) of which
you are personally aware, and conspicuously marking the work as "Submitted on behalf of a
third-party: [named here]".

- It is your responsibility to notify The Owner when any change is required to the list of designated
employees authorized to submit Contributions on behalf of the Corporation, or to the Corporation's Point of
Contact with The Owner.
Loading

0 comments on commit 96f5949

Please sign in to comment.