Skip to content

feat: add experiment metrics and documentation extraction #33

feat: add experiment metrics and documentation extraction

feat: add experiment metrics and documentation extraction #33

Workflow file for this run

name: Release
on:
push:
tags:
- 'v*'
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: read
jobs:
validate:
name: Validate & Package
runs-on: ubuntu-latest
timeout-minutes: 15
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: Validate release tag
id: version
shell: bash
run: |
if [[ ! "$GITHUB_REF_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Release tag must match vMAJOR.MINOR.PATCH: $GITHUB_REF_NAME" >&2
exit 1
fi
git -c gpg.ssh.allowedSignersFile=.github/allowed_signers verify-tag "$GITHUB_REF_NAME"
version="${GITHUB_REF_NAME#v}"
package_version="$(node --input-type=module -e "import pkg from './package.json' with { type: 'json' }; process.stdout.write(pkg.version)")"
if [[ "$version" != "$package_version" ]]; then
echo "Tag version $version does not match package version $package_version" >&2
exit 1
fi
release_commit="$(git rev-parse "$GITHUB_REF_NAME^{commit}")"
git fetch --no-tags origin main:refs/remotes/origin/main
if ! git merge-base --is-ancestor "$release_commit" origin/main; then
echo "Release commit $release_commit is not reachable from origin/main" >&2
exit 1
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: Setup pnpm
uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
with:
version: 10
- name: Setup Node.js
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: 22
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Install Chrome for browser tests
run: pnpm exec puppeteer browsers install chrome
- name: Typecheck
run: pnpm typecheck
- name: Browser regression tests
run: pnpm test:regression
- name: Package release artifacts
run: pnpm package:all
- name: Verify release artifacts
run: pnpm verify:release -- "${{ steps.version.outputs.version }}"
- name: Stage release bundle
shell: bash
run: |
version="${{ steps.version.outputs.version }}"
mkdir release-bundle
cp dist/userscript/copy-as-markdown.user.js "release-bundle/copy-as-markdown-v${version}.user.js"
cp dist/userscript/copy-as-markdown.user.js release-bundle/copy-as-markdown.user.js
cp dist/userscript/copy-as-markdown.meta.js release-bundle/
cp dist/copy-as-markdown-chrome.zip "release-bundle/copy-as-markdown-chrome-v${version}.zip"
cp dist/copy-as-markdown-firefox.zip "release-bundle/copy-as-markdown-firefox-v${version}.zip"
(
cd release-bundle
sha256sum \
"copy-as-markdown-v${version}.user.js" \
copy-as-markdown.user.js \
copy-as-markdown.meta.js \
"copy-as-markdown-chrome-v${version}.zip" \
"copy-as-markdown-firefox-v${version}.zip" \
> SHA256SUMS
)
- name: Verify release bundle
run: pnpm verify:release -- "${{ steps.version.outputs.version }}" --bundle release-bundle
- name: Generate release notes
shell: bash
run: |
version="${{ steps.version.outputs.version }}"
release_commit="$(git rev-parse "$GITHUB_REF_NAME^{commit}")"
previous_tag="$(git describe --tags --abbrev=0 "$release_commit^" 2>/dev/null || true)"
if [[ -n "$previous_tag" ]]; then
change_range="$previous_tag..$release_commit"
else
change_range="$release_commit"
fi
{
echo "## Install"
echo
echo "### Userscript (Tampermonkey / Violentmonkey)"
echo "[Install the userscript](https://github.com/${GITHUB_REPOSITORY}/releases/latest/download/copy-as-markdown.user.js), or download **copy-as-markdown-v${version}.user.js** below."
echo
echo "### Chrome Extension"
echo "[Install from the Chrome Web Store](https://chromewebstore.google.com/detail/copy-as-markdown/pcjanmkidppaeojkanbjbmmgpjfeecol)."
echo
echo "For local testing, download **copy-as-markdown-chrome-v${version}.zip** below, unzip it, then load the folder from \`chrome://extensions/\` with Developer mode enabled."
echo
echo "### Firefox Extension"
echo "1. Download **copy-as-markdown-firefox-v${version}.zip** below"
echo "2. Open \`about:debugging#/runtime/this-firefox\`, choose Load Temporary Add-on, and select \`manifest.json\`"
echo
echo "## Changes"
echo
git log --first-parent --format="* %s (\`%h\`)" "$change_range"
} > release-bundle/release-notes.md
- name: Upload verified release bundle
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: release-bundle
path: release-bundle/
if-no-files-found: error
retention-days: 14
publish:
name: Publish
needs: validate
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write
steps:
- name: Download verified release bundle
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: release-bundle
path: release-bundle
- name: Create GitHub Release
uses: softprops/action-gh-release@3d0d9888cb7fd7b750713d6e236d1fcb99157228 # v3.0.2
with:
name: "Copy as Markdown v${{ needs.validate.outputs.version }}"
body_path: release-bundle/release-notes.md
fail_on_unmatched_files: true
overwrite_files: true
files: |
release-bundle/copy-as-markdown-v${{ needs.validate.outputs.version }}.user.js
release-bundle/copy-as-markdown.user.js
release-bundle/copy-as-markdown.meta.js
release-bundle/copy-as-markdown-chrome-v${{ needs.validate.outputs.version }}.zip
release-bundle/copy-as-markdown-firefox-v${{ needs.validate.outputs.version }}.zip
release-bundle/SHA256SUMS