All checks were successful
Package component / package (push) Successful in 2m23s
128 lines
4.2 KiB
YAML
128 lines
4.2 KiB
YAML
name: Package component
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
package:
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 30
|
|
steps:
|
|
- name: Check out repository
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
server_url="${{ gitea.server_url }}"
|
|
repository_url="${server_url%/}/${{ gitea.repository }}.git"
|
|
git init .
|
|
git remote add origin "$repository_url"
|
|
git fetch --depth 1 origin "${{ gitea.sha }}"
|
|
git checkout --detach FETCH_HEAD
|
|
|
|
- name: Set up pnpm
|
|
run: |
|
|
corepack enable
|
|
corepack prepare pnpm@10.32.1 --activate
|
|
|
|
- name: Install dependencies
|
|
run: pnpm install --frozen-lockfile
|
|
|
|
- name: Set package version
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
source_version="$(node -p "require('./package.json').version")"
|
|
latest_version="$(
|
|
find /downloads -maxdepth 1 -type f -name 'waveform-analysis-*-*.tgz' -printf '%f\n' \
|
|
| sed -nE 's/^waveform-analysis-([0-9]+\.[0-9]+\.[0-9]+)-[0-9a-f]+\.tgz$/\1/p' \
|
|
| sort -V \
|
|
| tail -n 1
|
|
)"
|
|
next_version="$(node - "$source_version" "$latest_version" <<'NODE'
|
|
const source = process.argv[2]
|
|
const latest = process.argv[3]
|
|
const parse = (version) => {
|
|
const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(version)
|
|
if (!match) throw new Error(`Unsupported package version: ${version}`)
|
|
return match.slice(1).map(Number)
|
|
}
|
|
const compare = (left, right) => {
|
|
for (let index = 0; index < 3; index += 1) {
|
|
if (left[index] !== right[index]) return left[index] - right[index]
|
|
}
|
|
return 0
|
|
}
|
|
const sourceParts = parse(source)
|
|
if (!latest) {
|
|
process.stdout.write(source)
|
|
} else {
|
|
const latestParts = parse(latest)
|
|
if (compare(sourceParts, latestParts) > 0) {
|
|
process.stdout.write(source)
|
|
} else {
|
|
latestParts[2] += 1
|
|
process.stdout.write(latestParts.join('.'))
|
|
}
|
|
}
|
|
NODE
|
|
)"
|
|
pnpm pkg set version="$next_version"
|
|
printf 'Packaging waveform-analysis@%s\n' "$next_version"
|
|
|
|
- name: Type check
|
|
run: pnpm typecheck
|
|
|
|
- name: Lint
|
|
run: pnpm lint
|
|
|
|
- name: Test with coverage
|
|
run: pnpm test:coverage
|
|
|
|
- name: Build component
|
|
run: pnpm build
|
|
|
|
- name: Pack component
|
|
run: pnpm pack --pack-destination artifacts
|
|
|
|
- name: Verify component package
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
package_file="$(find artifacts -maxdepth 1 -type f -name '*.tgz' -print -quit)"
|
|
test -n "$package_file"
|
|
package_contents="$(tar -tzf "$package_file")"
|
|
for required_file in \
|
|
package/dist/index.js \
|
|
package/dist/index.cjs \
|
|
package/dist/types/index.d.ts \
|
|
package/dist/style.css \
|
|
package/package.json \
|
|
package/README.md; do
|
|
grep -Fxq "$required_file" <<< "$package_contents"
|
|
done
|
|
|
|
- name: Publish component package
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
package_file="$(find artifacts -maxdepth 1 -type f -name '*.tgz' -print -quit)"
|
|
package_version="$(node -p "require('./package.json').version")"
|
|
short_sha="$(printf '%.12s' '${{ gitea.sha }}')"
|
|
published_name="waveform-analysis-${package_version}-${short_sha}.tgz"
|
|
install -m 644 "$package_file" "/downloads/$published_name"
|
|
cd /downloads
|
|
sha256sum "$published_name" > "$published_name.sha256"
|
|
ln -sfn "$published_name" waveform-analysis-latest.tgz
|
|
ln -sfn "$published_name.sha256" waveform-analysis-latest.tgz.sha256
|
|
|
|
- name: Upload component package
|
|
uses: https://lqycustomsite.online/admin/actions-upload-artifact@v3
|
|
with:
|
|
name: waveform-analysis-${{ gitea.sha }}
|
|
path: artifacts/*.tgz
|
|
if-no-files-found: error
|
|
retention-days: 7
|