Skip to content

Commit 1dcb2ed

Browse files
ci: Add workflows suite
Fixes #13
1 parent 635dd62 commit 1dcb2ed

File tree

7 files changed

+362
-0
lines changed

7 files changed

+362
-0
lines changed

.github/workflows/build.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: build
2+
3+
on:
4+
workflow_call:
5+
workflow_dispatch:
6+
7+
env:
8+
# Disable git hooks
9+
HUSKY: 0
10+
11+
jobs:
12+
build:
13+
name: Build
14+
runs-on: ${{ matrix.os }}
15+
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
os:
20+
- ubuntu-latest
21+
- macos-latest
22+
node:
23+
- '20.11.1'
24+
25+
steps:
26+
- uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 1
29+
30+
- name: Install Nodejs
31+
uses: actions/setup-node@v4
32+
id: setup-node
33+
with:
34+
node-version: ${{ matrix.node }}
35+
cache: yarn
36+
registry-url: 'https://registry.npmjs.org'
37+
38+
- name: Install dependencies
39+
run: yarn install --frozen-lockfile --immutable
40+
41+
- name: Build on ${{ runner.os }}
42+
shell: bash
43+
run: |
44+
yarn run build-self
45+
yarn run clean-build-template

.github/workflows/lint.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: lint
2+
3+
on:
4+
workflow_call:
5+
workflow_dispatch:
6+
7+
env:
8+
# Disable git hooks
9+
HUSKY: 0
10+
11+
jobs:
12+
lint:
13+
name: Lint on NodeJS ${{ matrix.node }}
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
node:
20+
- '20.11.1'
21+
22+
steps:
23+
- uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 1
26+
27+
- name: Install Nodejs
28+
uses: actions/setup-node@v4
29+
id: setup-node
30+
with:
31+
node-version: ${{ matrix.node }}
32+
cache: yarn
33+
registry-url: 'https://registry.npmjs.org'
34+
35+
- name: Install dependencies
36+
run: yarn install --frozen-lockfile --immutable
37+
38+
- name: Run lint
39+
run: |
40+
echo Would run: yarn run lint

.github/workflows/publish.yml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
name: Publish
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
next_version:
7+
description: |
8+
Next release version. Possible values: x.y.z, major, minor, patch
9+
required: true
10+
type: string
11+
# XXX: does not skip for some reason
12+
# skip_tests:
13+
# description: |
14+
# Skip tests iff === 'true'
15+
# required: true
16+
# default: 'false'
17+
secrets:
18+
NPM_AUTH_TOKEN:
19+
description: |
20+
Auth token to publish to the NPM registry. To be passed from calling workflow.
21+
required: true
22+
23+
env:
24+
# Disable git hooks
25+
HUSKY: 0
26+
27+
jobs:
28+
publish:
29+
name: Publish to NPM Registry
30+
runs-on: ubuntu-latest
31+
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
node:
36+
- '18.x'
37+
38+
steps:
39+
- uses: actions/checkout@v4
40+
with:
41+
fetch-depth: 1
42+
43+
- uses: actions/setup-node@v4
44+
id: setup-node
45+
with:
46+
node-version: ${{ matrix.node }}
47+
cache: yarn
48+
registry-url: 'https://registry.npmjs.org'
49+
50+
- name: Install dependencies
51+
run: yarn install --frozen-lockfile --immutable
52+
53+
- name: Create a new version
54+
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.next_version != 'skip' }}
55+
shell: bash
56+
id: new-version
57+
run: |
58+
git config --global user.name "${GITHUB_ACTOR}"
59+
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
60+
61+
# Running `npm version` to translate `minor` to semver string:
62+
new_version=$(npm version --no-git-tag-version --new-version ${{ github.event.inputs.next_version }})
63+
git add -u
64+
git commit -m "chore(package.json): bump version to ${new_version}"
65+
git pull --rebase
66+
git tag -a "${new_version}" -mBump
67+
echo "new_tag=${new_version}" >> $GITHUB_OUTPUT
68+
# Push commit along with tag
69+
git push origin --tags :
70+
71+
- name: Build all packages
72+
run: yarn run build-self && yarn run clean-build-template
73+
74+
- name: Publish to npm
75+
run: |
76+
# Check if node auth token is valid
77+
if [[ -z "${NODE_AUTH_TOKEN:-}" ]]; then
78+
printf "\e[1;31mError:\e[m Missing NODE_AUTH_TOKEN\n" >&2
79+
exit 1
80+
fi
81+
82+
# Debug what files are in dist/
83+
ls -la dist >&2
84+
85+
# Verify total files and shasum of `pack` and `publish` are the same
86+
pack_filename=$(npm pack | tail -n1)
87+
publish_sout=$(npm publish --access public --no-git-checks --dry-run 2>&1)
88+
89+
printf "\e[1mnpm publish (dry run):\e[m\n" >&2
90+
printf "$publish_sout\n\n\n" >&2
91+
92+
pack_shasum=$(shasum -b -a 1 "${pack_filename}" | awk '{ print $1 }')
93+
publish_shasum=$(<<< "$publish_sout" command sed '/shasum/!d; s/.*:\s*\(.*\)$/\1/')
94+
95+
pack_total_files=$(tar -tvf "${pack_filename}" | wc -l)
96+
publish_total_files=$(<<< "$publish_sout" command sed '/total.files/!d; s/.*:\s*\(.*\)$/\1/')
97+
98+
has_error=
99+
if [[ "$pack_shasum" != "$publish_shasum" ]]; then
100+
printf "\e[1;31mError:\e[m Package shasum do not match:\n" >&2
101+
printf " npm pack shasum: $pack_shasum\n" >&2
102+
printf " npm publish shasum: $publish_shasum\n" >&2
103+
has_error=1
104+
fi
105+
106+
if (( pack_total_files != publish_total_files )); then
107+
printf "\e[1;31mError:\e[m Package total files do not match:\n" >&2
108+
printf " npm pack total files: $pack_total_files\n" >&2
109+
printf " npm publish total files: $publish_total_files\n" >&2
110+
has_error=1
111+
fi
112+
113+
if [[ -n "$has_error" ]]; then
114+
printf "\e[1;38;5;208mWarning:\e[m Aborting due to previous errors.\n" >&2
115+
116+
# Revert tag
117+
printf "\e[1;38;5;208mWarning:\e[m Unpublishing release tag ${{ steps.new-version.outputs.new_tag }}.\n" >&2
118+
git tag -d "${{ steps.new-version.outputs.new_tag }}"
119+
git push --delete origin "${{ steps.new-version.outputs.new_tag }}"
120+
121+
# Revert commit
122+
printf "\e[1;38;5;208mWarning:\e[m Unpublishing release commit.\n" >&2
123+
git reset --hard HEAD^
124+
git push origin --force-with-lease
125+
126+
printf "\e[1;38;5;208mWarning:\e[m Clean up done.\n" >&2
127+
exit 1
128+
fi
129+
130+
npm publish --access public --no-git-checks
131+
env:
132+
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

.github/workflows/release.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: (Test and) Release Site-builder
2+
3+
on:
4+
workflow_call:
5+
push:
6+
tags:
7+
- '*'
8+
workflow_dispatch:
9+
inputs:
10+
next_version:
11+
description: |
12+
Next release version. Possible values: x.y.z, major, minor, patch
13+
required: true
14+
default: patch
15+
type: string
16+
# XXX: does not skip for some reason
17+
# skip_tests:
18+
# description: |
19+
# Skip tests iff === 'true'
20+
# required: true
21+
# default: 'false'
22+
23+
jobs:
24+
tests:
25+
# XXX: does not skip for some reason
26+
# if: github.events.inputs.skip_tests != 'true'
27+
uses: ./.github/workflows/tests.yml
28+
29+
publish:
30+
# needs: [tests]
31+
uses: ./.github/workflows/publish.yml
32+
with:
33+
next_version: ${{ github.event.inputs.next_version }}
34+
secrets:
35+
NPM_AUTH_TOKEN: ${{ secrets.PANERON_CI_NPM_TOKEN }}

.github/workflows/test.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: test
2+
3+
on:
4+
workflow_call:
5+
workflow_dispatch:
6+
7+
env:
8+
# Disable git hooks
9+
HUSKY: 0
10+
11+
jobs:
12+
test:
13+
name: Test
14+
runs-on: ${{ matrix.os }}
15+
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
os:
20+
- macos-latest
21+
- ubuntu-latest
22+
- windows-latest
23+
node:
24+
- '20.11.1'
25+
- '22.x'
26+
27+
steps:
28+
- uses: actions/checkout@v4
29+
with:
30+
fetch-depth: 1
31+
32+
- name: Install Nodejs
33+
uses: actions/setup-node@v4
34+
id: setup-node
35+
with:
36+
node-version: ${{ matrix.node }}
37+
cache: yarn
38+
registry-url: 'https://registry.npmjs.org'
39+
40+
- name: Install dependencies
41+
run: yarn install --frozen-lockfile --immutable
42+
43+
- name: Run tests
44+
run: |
45+
echo Would run: yarn run test

.github/workflows/tests.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: tests
2+
3+
on:
4+
workflow_call:
5+
push:
6+
branches:
7+
- main
8+
- master
9+
paths-ignore:
10+
- '/*.sh'
11+
- '/.*'
12+
- '/_*'
13+
- '**.adoc'
14+
- '**.md'
15+
- '**.nix'
16+
- 'flake.lock'
17+
- '.github/workflows/*.yml'
18+
- '!.github/workflows/tests.yml'
19+
- '!.github/workflows/lint.yml'
20+
- '!.github/workflows/build.yml'
21+
- '!.github/workflows/test.yml'
22+
- '!.github/workflows/*-release.yml'
23+
pull_request:
24+
paths-ignore:
25+
- '/*.sh'
26+
- '/.*'
27+
- '/_*'
28+
- '**.adoc'
29+
- '**.md'
30+
- '**.nix'
31+
- 'flake.lock'
32+
workflow_dispatch:
33+
34+
jobs:
35+
lint:
36+
uses: ./.github/workflows/lint.yml
37+
38+
build:
39+
uses: ./.github/workflows/build.yml
40+
41+
test:
42+
# needs: [build]
43+
uses: ./.github/workflows/test.yml

README.adoc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@
44

55
== Site builder
66

7+
ifdef::env-github[]
8+
image:https://github.com/paneron/site-builder/actions/workflows/tests.yml/badge.svg[
9+
"Test Status",
10+
link="https://github.com/paneron/site-builder/actions/workflows/tests.yml"]
11+
image:https://github.com/paneron/site-builder/actions/workflows/audit.yml/badge.svg[
12+
"Audit Status",
13+
link="https://github.com/paneron/site-builder/actions/workflows/audit.yml"]
14+
15+
image:https://github.com/paneron/site-builder/actions/workflows/release.yml/badge.svg[
16+
"Release Status",
17+
link="https://github.com/paneron/site-builder/actions/workflows/release.yml"]
18+
19+
image:https://img.shields.io/npm/v/%40paneron%2Fsite-builder[
20+
NPM release,
21+
link="https://www.npmjs.com/package/@paneron/site-builder"]
22+
23+
// image:https://img.shields.io/github/v/release/paneron/site-builder?display_name=tag&include_prereleases&sort=semver[
24+
// GitHub release (latest SemVer including pre-releases),
25+
// link="https://www.npmjs.com/package/@paneron/site-builder"
26+
// ]
27+
endif::[]
28+
729
This is a CLI tool to build a static site for given Paneron
830
https://github.com/paneron/registry-kit/[RegistryKit^]-based dataset.
931

0 commit comments

Comments
 (0)