Skip to content

Commit

Permalink
chore: update CI setup (#2079)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pessimistress committed Apr 30, 2024
1 parent 30be1e2 commit 9775cf3
Show file tree
Hide file tree
Showing 7 changed files with 2,373 additions and 3,950 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/release.yml
@@ -0,0 +1,67 @@
name: release

on:
push:
tags:
- v*

jobs:
check_branch:
runs-on: ubuntu-latest
outputs:
should_build: ${{ steps.permitted.outputs.result }}

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Fetch remote branches
run: |
git fetch origin --depth=1
- name: Check if on permitted branch
id: permitted
run: |
result=
branchName=$(git branch -a --contains $GITHUB_SHA | grep 'remotes/origin/' || echo "")
if [[ $branchName == *"master" || $branchName == *"-release" ]]; then
result=true
fi
echo "result=${result}" >> "$GITHUB_OUTPUT"
release:
runs-on: ubuntu-latest
needs: check_branch
permissions:
contents: write

if: ${{ github.repository_owner == 'visgl' && needs.check_branch.outputs.should_build }}

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_ACCESS_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- uses: volta-cli/action@2d68418f32546fd191eb666e232b321d5726484d # v4.1.1
with:
cache: 'yarn'

- name: Create GitHub release entry
run: |
body=$(node scripts/github-release.js) &&
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/visgl/luma.gl/releases \
-d "${body}" \
-H "Authorization: token ${GITHUB_TOKEN}"
- name: Login to NPM
run: npm config set "//registry.npmjs.org/:_authToken=${NPM_ACCESS_TOKEN}"

- name: Install dependencies
run: yarn

- name: Publish to NPM
run: npx ocular-publish from-git
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Expand Up @@ -15,8 +15,8 @@ jobs:
node-version: [20]

steps:
- uses: actions/checkout@v4.1.1
- uses: volta-cli/action@v4
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: volta-cli/action@2d68418f32546fd191eb666e232b321d5726484d # v4.1.1
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
Expand All @@ -36,6 +36,6 @@ jobs:
yarn test-ci
- name: Coveralls
uses: coverallsapp/github-action@master
uses: coverallsapp/github-action@09b709cf6a16e30b0808ba050c7a6e8a5ef13f8d # v1.2.5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
49 changes: 27 additions & 22 deletions .github/workflows/website.yml
Expand Up @@ -6,41 +6,46 @@ on:
- '*-release'

jobs:
publish-website:
check_branch:
runs-on: ubuntu-latest
outputs:
should_deploy: ${{ endsWith(github.ref, steps.get_version.outputs.latest) }}

if: github.repository_owner == 'visgl'
steps:
- name: Get version
id: get_version
run: |
LATEST=$(npm show @luma.gl/core@latest version | grep -o -E "^[0-9]+\.[0-9]+")
echo "latest=${LATEST}-release" >> "$GITHUB_OUTPUT"
deploy:
runs-on: ubuntu-latest
needs: check_branch

permissions:
contents: write

if: ${{ github.repository_owner == 'visgl' && needs.check_branch.outputs.should_deploy }}

steps:
- uses: actions/checkout@v4.1.1
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
token: ${{ secrets.ADMIN_TOKEN }}
token: ${{ secrets.WEBSITE_DEPLOY_TOKEN }}

- name: Use Node.js
uses: actions/setup-node@v4.0.0
- uses: volta-cli/action@2d68418f32546fd191eb666e232b321d5726484d # v4.1.1
with:
node-version: '18.x'
cache: 'yarn'

- name: Get version
id: get-version
run: LATEST=$(npm show @luma.gl/core version | grep -o -E "^[0-9]+\.[0-9]+") && echo "::set-output name=latest::/${LATEST}-release"

- name: Check version
if: ${{ !endsWith(github.ref, steps.get-version.outputs.latest) }}
- name: Install dependencies
run: |
echo "Website is only published from the latest release branch"
yarn bootstrap
(cd website && yarn)
- name: Build website
if: ${{ endsWith(github.ref, steps.get-version.outputs.latest) }}
run: |
yarn bootstrap
cd website
yarn
yarn build
run: (cd website && yarn build)

- name: Deploy
if: ${{ endsWith(github.ref, steps.get-version.outputs.latest) }}
uses: JamesIves/github-pages-deploy-action@3.7.1
uses: JamesIves/github-pages-deploy-action@132898c54c57c7cc6b80eb3a89968de8fc283505 # 3.7.1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages
Expand Down
7 changes: 4 additions & 3 deletions package.json
Expand Up @@ -29,8 +29,9 @@
"build": "ocular-clean && (cd modules/constants && yarn pre-build) && ocular-build",
"cover": "ocular-test cover",
"lint": "ocular-lint",
"publish": "ocular-publish",
"version": "npm run build",
"publish-beta": "ocular-publish version-only-beta",
"publish-prod": "ocular-publish version-only-prod",
"version": "node scripts/verify-changelog.js && git add CHANGELOG.md",
"test": "ocular-test",
"test-ci": "ocular-lint && ocular-test node && ocular-test cover && yarn test-website",
"test-fast": "ocular-test fast",
Expand All @@ -54,7 +55,7 @@
"eslint-plugin-tree-shaking": "^1.9.2",
"math.gl": "^3.0.0",
"nyc": "^15.1.0",
"ocular-dev-tools": "2.0.0-alpha.29",
"ocular-dev-tools": "2.0.0-alpha.33",
"pre-commit": "^1.2.2",
"pre-push": "^0.1.1",
"puppeteer": "^22.0.0",
Expand Down
53 changes: 53 additions & 0 deletions scripts/github-release.js
@@ -0,0 +1,53 @@
import {execSync} from 'child_process';
import {readFileSync} from 'fs';

// Get the latest tag
const tag = getGitTag();
if (!tag) {
console.error('TAG NOT FOUND');
process.exit(1);
}

// Parse changelog
const changelog = getReleaseNotes(tag);
if (!changelog) {
console.error('CHANGELOG NOT FOUND');
process.exit(1);
}

// Publish release notes to GitHub
// https://docs.github.com/en/rest/reference/repos#create-a-release
const requestBody = {
tag_name: tag,
name: tag,
body: changelog,
prerelease: tag.search(/alpha|beta|rc/) > 0
};

console.log(JSON.stringify(requestBody));

function getGitTag() {
try {
return execSync('git describe --tags --exact-match HEAD', {
stdio: [null, 'pipe', null],
encoding: 'utf-8'
}).trim();
} catch (err) {
// not tagged
return null;
}
}

function getReleaseNotes(version) {
let changelog = readFileSync('CHANGELOG.md', 'utf-8');
const header = changelog.match(new RegExp(`^###.*\\b${version.replace('v', '')}\\b.*$`, 'm'));
if (!header) {
return null;
}
changelog = changelog.slice(header.index + header[0].length);
const endIndex = changelog.search(/^#/m);
if (endIndex > 0) {
changelog = changelog.slice(0, endIndex);
}
return changelog.trim();
}
13 changes: 13 additions & 0 deletions scripts/verify-changelog.js
@@ -0,0 +1,13 @@
/**
* Verifies that CHANGELOG has been updated before publishing a new version
*/
import {readFileSync} from 'fs';

const {version} = JSON.parse(readFileSync('lerna.json'));

const changelog = readFileSync('CHANGELOG.md', 'utf-8');
const header = changelog.match(new RegExp(`^###.*\\b${version}\\b.*$`, 'm'));
if (!header) {
console.error(`Cannot find an entry for ${version} in CHANGELOG.md`);
process.exit(1);
}

0 comments on commit 9775cf3

Please sign in to comment.