From fc8b63c0f5b1780c55ff1124ffe1ec629419afa2 Mon Sep 17 00:00:00 2001 From: Zeno Jiricek Date: Tue, 18 Jun 2024 20:56:00 +0930 Subject: [PATCH] initial commit --- .github/actions/setup-npm-publish/action.yml | 29 +++ .../actions/setup-npm-publish/create-npmrc.sh | 21 +++ .github/actions/setup-tooling/README.md | 54 ++++++ .github/actions/setup-tooling/action.yml | 65 +++++++ .github/actions/setup-yarn/action.yml | 37 ++++ .github/workflows/dependabot.yml | 24 +++ .github/workflows/pr-title.yml | 27 +++ .github/workflows/pr.yml | 38 ++++ .github/workflows/release.yml | 74 ++++++++ .plugin-versions | 8 + .release-please-manifest.json | 2 + .tool-versions | 4 + README.md | 3 + justfile | 67 +++++++ package.json | 17 ++ release-please-config.json | 12 ++ setup.sh | 171 ++++++++++++++++++ 17 files changed, 653 insertions(+) create mode 100644 .github/actions/setup-npm-publish/action.yml create mode 100755 .github/actions/setup-npm-publish/create-npmrc.sh create mode 100644 .github/actions/setup-tooling/README.md create mode 100644 .github/actions/setup-tooling/action.yml create mode 100644 .github/actions/setup-yarn/action.yml create mode 100644 .github/workflows/dependabot.yml create mode 100644 .github/workflows/pr-title.yml create mode 100644 .github/workflows/pr.yml create mode 100644 .github/workflows/release.yml create mode 100644 .plugin-versions create mode 100644 .release-please-manifest.json create mode 100644 .tool-versions create mode 100644 README.md create mode 100644 justfile create mode 100644 package.json create mode 100644 release-please-config.json create mode 100755 setup.sh diff --git a/.github/actions/setup-npm-publish/action.yml b/.github/actions/setup-npm-publish/action.yml new file mode 100644 index 0000000..16a79a4 --- /dev/null +++ b/.github/actions/setup-npm-publish/action.yml @@ -0,0 +1,29 @@ +--- +name: Setup Npm Publishing + +description: Configures Npm for Publishing in Github Actions + +inputs: + NpmRegistryUrl: + description: 'The registry url to use for the install' + default: 'https://registry.npmjs.org' + NpmRcFile: + description: 'The path to the .npmrc file' + default: '~/.npmrc' + +runs: + using: 'composite' + + steps: + - name: create .npmrc + shell: bash + env: + NPM_REGISTRY_URL: ${{ inputs.NpmRegistryUrl }} + NPM_RC_FILE: ${{ inputs.NpmRcFile }} + # Create .npmrc file + # This file is used to authenticate with the npm registry + # The NPM_AUTH_TOKEN is an envvar that will be used later, we + # don't interpolate it here now, hence the escaped $. + # When used in the npm publish command, it's able to + # interpolate the value from Environment Variables. + run: ${{ github.action_path }}/create-npmrc.sh $NPM_REGISTRY_URL $NPM_RC_FILE diff --git a/.github/actions/setup-npm-publish/create-npmrc.sh b/.github/actions/setup-npm-publish/create-npmrc.sh new file mode 100755 index 0000000..b360b7b --- /dev/null +++ b/.github/actions/setup-npm-publish/create-npmrc.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# if 1st argument is not provided, exit +if [ -z "$1" ]; then + echo "Arg 1: Registry URL is required" + exit 1 +fi + +# if 2nd argument is not provided, exit +if [ -z "$2" ]; then + echo "Arg 2: npmrc output file is required" + exit 1 +fi + +# strip http(s):// from registry URL +domain="${1//http:\/\//}" +domain="${domain//https:\/\//}" + +echo "//${domain}/:_authToken=\${NPM_AUTH_TOKEN}" >"$2" +echo "registry=${1}" >>"$2" +echo "always-auth=true" >>"$2" diff --git a/.github/actions/setup-tooling/README.md b/.github/actions/setup-tooling/README.md new file mode 100644 index 0000000..3acf9c0 --- /dev/null +++ b/.github/actions/setup-tooling/README.md @@ -0,0 +1,54 @@ +# setup-tooling + +Installs ASDF with plugins + +## Requirements + +- a `.tool-versions` file in the root of the repo + +## Usage + +```yml + Release: + + runs-on: ubuntu-latest + + permissions: + contents: write + deployments: write + + steps: + + - uses: actions/checkout@v3 + + - name: Setup tooling + uses: ./.github/actions/setup-tooling + env: + # if you use an asdf plugin called "something" and its not in the shortname repo: https://github.com/asdf-vm/asdf-plugins + # then it gets listed here as `ASDF_PLUGIN_URL_: the plugin repo` + ASDF_PLUGIN_URL_something: https://get.thething/asdf-plugin +``` + +- installs asdf plugins for each item listed in your `.tools-version` +- if one of your plugins isn't on the official asdf list, then provide the + install url by defining an ENVVAR of `ASDF_PLUGIN_URL_pluginname=url` + +### Custom ASDF Setup command + +Normally you'd have a `setup.sh` in the root of the repo. If it's somewhere else, +then specify with your own version of the setup command: + +```yml + Release: + + runs-on: ubuntu-latest + + steps: + + - uses: actions/checkout@v3 + + - name: Setup tooling + uses: ./.github/actions/setup-tooling + with: + SetupCommand: ./your/path/to/your/asdf/setup.sh +``` diff --git a/.github/actions/setup-tooling/action.yml b/.github/actions/setup-tooling/action.yml new file mode 100644 index 0000000..33151b5 --- /dev/null +++ b/.github/actions/setup-tooling/action.yml @@ -0,0 +1,65 @@ +name: Setup Asdf + +description: provisions tooling + +inputs: + SetupCommand: + description: "Command to run" + required: false + default: ./setup.bash + +runs: + using: "composite" + + steps: + - name: Ensure setup command available + shell: bash + env: + SETUP_COMMAND: ${{inputs.SetupCommand}} + run: | + if [ ! -f ${SETUP_COMMAND} ]; then + echo "🛑 Missing action input SetupCommand." + exit 1 + fi + + - uses: actions/cache@v3 + id: online-asdf-cache + if: ${{ !env.ACT }} + with: + path: ~/.asdf + key: ${{ runner.os }}-asdf-${{ hashFiles('**/.tool-versions') }} + restore-keys: | + ${{ runner.os }}-asdf- + + # + # This step serves as an interop layer between the online and offline + # when online, we use github cache and this step will report if the cache was hit + # when offline, we use act and this step will report that the cache was not hit + - name: act cache interop + shell: bash + id: cache + run: | + if [ "${{ env.ACT }}" = "true" ]; then + echo "OFFLINE: no cache" + echo "cache-hit=false" >> $GITHUB_OUTPUT + elif [ "${{ steps.online-asdf-cache.outputs.cache-hit }}" = "true" ]; then + echo "ONLINE: cache available" + echo "cache-hit=${{ steps.online-asdf-cache.outputs.cache-hit }}" >> $GITHUB_OUTPUT + fi + + - run: echo "${{ github.action_path }}" >> $GITHUB_PATH + if: steps.cache.outputs.cache-hit != 'true' + shell: bash + + - name: asdf install + if: steps.cache.outputs.cache-hit != 'true' + shell: bash + env: + SETUP_COMMAND: ${{inputs.SetupCommand}} + run: ${SETUP_COMMAND} + + - name: set asdf path + shell: bash + run: | + echo "$HOME/.asdf/bin" >> $GITHUB_PATH + echo "$HOME/.asdf/shims" >> $GITHUB_PATH diff --git a/.github/actions/setup-yarn/action.yml b/.github/actions/setup-yarn/action.yml new file mode 100644 index 0000000..44f8688 --- /dev/null +++ b/.github/actions/setup-yarn/action.yml @@ -0,0 +1,37 @@ +--- +name: Install Nodejs dependencies with Yarn + +description: installs dependancies + +inputs: + AuthToken: + description: 'Auth token for the registry' + required: false + RegistryUrl: + description: 'The registry url to use for the install' + required: false + +runs: + using: 'composite' + + steps: + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT + shell: bash + + - name: Cache node modules + id: yarn-cache + uses: actions/cache@v3 + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: yarn install + shell: bash + env: + HUSKY_SKIP_INSTALL: '1' + HUSKY: '0' + run: yarn install --immutable diff --git a/.github/workflows/dependabot.yml b/.github/workflows/dependabot.yml new file mode 100644 index 0000000..23f0b1e --- /dev/null +++ b/.github/workflows/dependabot.yml @@ -0,0 +1,24 @@ +name: Auto Approve Dependabot PRs + +on: + pull_request_target: + types: [labeled] + pull_request: + types: [labeled] + +jobs: + AutoUpdateDependabot: + name: Auto-Approve and enable Auto-Merge for all Dependabot PRs + runs-on: ubuntu-latest + if: github.event.pull_request.user.login == 'dependabot[bot]' && contains(github.event.pull_request.labels.*.name, 'dependencies') + steps: + # Enable auto-merge *before* issuing an approval. + - name: Enable Github Automerge + uses: alexwilson/enable-github-automerge-action@main + with: + github-token: '${{ secrets.RELEASE_PLEASE_TOKEN }}' + + # We "trust" dependabot updates (this still requires all other checks to pass!) + - uses: hmarr/auto-approve-action@5d04a5ca6da9aeb8ca9f31a5239b96fc3e003029 + with: + github-token: '${{ secrets.RELEASE_PLEASE_TOKEN }}' diff --git a/.github/workflows/pr-title.yml b/.github/workflows/pr-title.yml new file mode 100644 index 0000000..20156ce --- /dev/null +++ b/.github/workflows/pr-title.yml @@ -0,0 +1,27 @@ +name: 'LintPrTitle' + +on: + pull_request_target: + types: + - opened + - edited + - synchronize + +permissions: + pull-requests: read + +jobs: + ValidatePrTitle: + runs-on: ubuntu-latest + steps: + - uses: amannn/action-semantic-pull-request@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + types: | + fix + feat + chore + docs + build + content diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 0000000..932e0d8 --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,38 @@ +name: Pr + +on: + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +# Needed for nx-set-shas within nx-cloud-main.yml, when run on the master branch +permissions: + actions: read + contents: read + +jobs: + Check: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Asdf + uses: ./.github/actions/setup-tooling + + - name: Install Node Modules + uses: ./.github/actions/setup-yarn + + - name: lint + run: just lint + + - name: test + run: just test + + - name: docs + run: just docs + + - name: build + run: just build diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..d2b1543 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,74 @@ +name: Release + +on: + push: + branches: + - master + +env: + HUSKY: 0 # https://typicode.github.io/husky/how-to.html#ci-server-and-docker + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + +# Needed for nx-set-shas within nx-cloud-main.yml, when run on the master branch +permissions: + actions: read + contents: write + deployments: write + pull-requests: write + id-token: write + +jobs: + Process: + runs-on: ubuntu-latest + outputs: + releases_created: ${{ steps.release-please.outputs.releases_created }} + steps: + - uses: google-github-actions/release-please-action@v4 + id: release-please + with: + token: ${{secrets.RELEASE_PLEASE_TOKEN}} + - name: Print Release Data + run: | + echo 'Release Data:' + + echo ''' + ${{ toJSON(steps.release-please.outputs) }} + ''' + + Deploy: + needs: Process + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Asdf + uses: ./.github/actions/setup-tooling + + - name: Yarn + uses: ./.github/actions/setup-yarn + + - name: Configure Publishing + uses: ./.github/actions/setup-npm-publish + with: + NpmRegistryUrl: https://registry.npmjs.org/ + NpmRcFile: .npmrc + + - name: Preflight + run: | + just lint + just types + just test + just build + + - if: ${{ needs.Process.outputs.releases_created == 'true' }} + env: + NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} + run: just stage=production publish + + - if: ${{ needs.Process.outputs.releases_created == 'false' }} + env: + NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} + run: just stage=development publish diff --git a/.plugin-versions b/.plugin-versions new file mode 100644 index 0000000..b02e262 --- /dev/null +++ b/.plugin-versions @@ -0,0 +1,8 @@ +action-validator https://github.com/mpalmer/action-validator.git 8df3ccb +asdf-plugin-manager https://github.com/asdf-community/asdf-plugin-manager.git 6fc3faa +direnv https://github.com/asdf-community/asdf-direnv.git a2219c2 +just https://github.com/olofvndrhr/asdf-just.git 93771e1 +nodejs https://github.com/asdf-vm/asdf-nodejs.git c5b7c40 +shellcheck https://github.com/luizm/asdf-shellcheck.git 780d78d +yarn https://github.com/twuni/asdf-yarn.git 376c540 +just https://github.com/olofvndrhr/asdf-just.git 93771e1 diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000..2c63c08 --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,2 @@ +{ +} diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..c9e3cb6 --- /dev/null +++ b/.tool-versions @@ -0,0 +1,4 @@ +just 1.25.2 +nodejs 20.12.1 +yarn 1.22.19 +shellcheck 0.9.0 diff --git a/README.md b/README.md new file mode 100644 index 0000000..ad358cf --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# @zenobius/remark-nomnoml + +A remark plugin that renders nomnoml diagrams inline as svg. diff --git a/justfile b/justfile new file mode 100644 index 0000000..2647ef9 --- /dev/null +++ b/justfile @@ -0,0 +1,67 @@ +export PATH := justfile_directory() + "/node_modules/.bin:" + env_var('PATH') + +default: + @just --list + +setup: + @echo "" + @echo "🍜 Setting up project" + @echo "" + + @yarn install + + @echo "" + @echo "👍 Done" + @echo "" + +lint: + @eslint --ext .ts . + +types: + tsc --noEmit \ + --project \ + ./tsconfig.json + +test: + vitest + +build: + tsup \ + --dts \ + --cjsInterop + + attw --pack + +docs: + typedoc \ + --plugin typedoc-plugin-markdown \ + --tsconfig ./tsconfig.lib.json \ + --out dist/docs \ + ./src/remark-nomnoml.ts \ + --hideBreadcrumbs true \ + --namedAnchors true \ + --disableSources \ + --readme ./README.md \ + --hideInPageTOC true \ + --hidePageTitle true \ + --hideGenerator true + + inject-markdown ./README.md + + rm -rf dist/docs + +publish STAGE="": + #!/bin/bash + set -e + + local tag + case $(STAGE) in + prod) + tag=latest + ;; + *) + tag=next + ;; + esac + + npm publish --access public --tag "${tag}" diff --git a/package.json b/package.json new file mode 100644 index 0000000..d09cf63 --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "@zenobius/remark-nomnoml", + "version": "0.0.1", + "publishConfig": { + "access": "public" + }, + "keywords": [ + "remark", + "plugin", + "nomnoml", + "diagram" + ], + "author": { + "name": "Zenobius Jiricek", + "email": "airtonix@users.noreply.github.com" + } +} diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 0000000..2c30457 --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json", + "include-component-in-tag": true, + "release-type": "simple", + "bump-minor-pre-major": true, + "bump-patch-for-minor-pre-major": true, + "packages": { + ".": { + "release-type": "node" + } + } +} diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..552e38f --- /dev/null +++ b/setup.sh @@ -0,0 +1,171 @@ +#!/usr/bin/env bash + +# Local vars +ASDF_VERSION=${ASDF_VERSION:-0.14.0} +ASDF_PLUGIN_MANAGER_VERSION=${ASDF_PLUGIN_MANAGER_VERSION:-1.3.1} +ASDF_HOME=$HOME/.asdf +ASDF_BIN=$ASDF_HOME/asdf.sh + +set -e + +colour() { + local colour + local message + + colour="$1" + message="$2" + + case "$colour" in + "red") + printf "\033[0;31m %s \033[0m \n" "$message" + ;; + "green") + printf "\033[0;32m %s \033[0m \n" "$message" + ;; + "yellow") + printf "\033[0;33m %s \033[0m \n" "$message" + ;; + "cyan") + printf "\033[0;36m %s \033[0m \n" "$message" + ;; + *) + printf "%s" "$message" + ;; + esac +} + +log() { + local level + local message + + level="$1" + message="$2" + + case "$level" in + "error") + echo "🍙 🔥 $(colour red "${message}")" + ;; + "success") + # print message in green text color + echo "🍙 🟢 $(colour green "${message}")" + ;; + "warn") + echo "🍙 ⛈️ $(colour yellow "${message}")" + ;; + *) + echo "🍙 $(colour cyan "${message}")" + ;; + + esac +} + +info() { + echo "" + log info "$@" + echo "" +} + +warn() { + echo "" + log warn "$@" + echo "" +} + +success() { + echo "" + log success "$@" + echo "" +} + +error() { + echo "" + log error "$@" + echo "" +} + +does_command_exist() { + command -v "$1" &>/dev/null +} + +require_command() { + if ! command -v "$1" &>/dev/null; then + error "Missing $1" + fi +} + +append_uniquely() { + if ! grep -q "$2" "$1"; then + info "Writing \"$2\" into \"$1\" " + echo "${2}" >>"$1" + fi +} + +get_shell_profile() { + case "${SHELL}" in + /bin/bash) + echo ~/.bashrc + return 0 + ;; + /bin/zsh) + echo ~/.zshrc + return 0 + ;; + esac +} + +add_to_shell_profile() { + local profile + + profile=$(get_shell_profile) + info "Adding to shell profile" + append_uniquely "$profile" ". $ASDF_HOME/asdf.sh" + append_uniquely "$profile" ". $ASDF_HOME/completions/asdf.bash" +} + +install_asdf() { + info "Installing/Updating ASDF" + + if [ ! -f "$ASDF_BIN" ]; then + warn "ASDF not detected ... installing" + git clone https://github.com/asdf-vm/asdf.git "$ASDF_HOME" --branch "v$ASDF_VERSION" + + # if asdf is not on the path, add it and refresh the shell + does_command_exist asdf || add_to_shell_profile + fi + + info "Updating asdf..." + asdf update || true + + # shellcheck disable=SC1090 + source "$ASDF_BIN" +} + +install_asdf_plugin_manager() { + info "Installing ASDF Plugin Manager ${ASDF_PLUGIN_MANAGER_VERSION}" + + asdf plugin add asdf-plugin-manager https://github.com/asdf-community/asdf-plugin-manager.git + asdf plugin update asdf-plugin-manager "v${ASDF_PLUGIN_MANAGER_VERSION}" + asdf install asdf-plugin-manager "${ASDF_PLUGIN_MANAGER_VERSION}" + asdf global asdf-plugin-manager "${ASDF_PLUGIN_MANAGER_VERSION}" + asdf reshim + + info "Installing .plugin-versions" + + asdf-plugin-manager add-all +} + +install_asdf_tooling() { + info "Installing .tool-versions" + + asdf install + asdf reshim +} + +require_command git +require_command curl + +install_asdf +install_asdf_plugin_manager +install_asdf_tooling + +info "Done"