From 4b64d0796d9fc9fc082a3c4abbd9354b494552bc Mon Sep 17 00:00:00 2001 From: Dafydd Jones Date: Sun, 24 Nov 2024 17:35:36 +0000 Subject: [PATCH] ci: deploy Renovate-style JSON to GitHub Pages * On each release, generate a set of JSON files in a directory named after the release tag. * A directory named latest will track the latest tagged release --- .cicd/transform-json | 29 +++++++++++++++++++++++++++++ .github/workflows/main.yml | 32 +++++++++++++++++++++++++++++++- .pre-commit-config.yaml | 5 +++++ .releaserc.cjs | 1 + 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100755 .cicd/transform-json diff --git a/.cicd/transform-json b/.cicd/transform-json new file mode 100755 index 000000000..dcf73b9c4 --- /dev/null +++ b/.cicd/transform-json @@ -0,0 +1,29 @@ +#!/bin/bash + +# Check if the jq binary exists +if ! [ -x "$(command -v jq)" ]; then + echo "Error: 'jq' binary not found or not executable" >&2 + exit 1 +fi + +readonly OUTPUT_DIR="${OUTPUT_DIR:-public}" + +process_repo() { + # For each defined package, output a list of its versions to a file .json in the output directory + echo "$1" | jq -r '.local.repo | to_entries[] | "\(.key).json"' | while read -r filename; do + echo "$1" | jq --arg pkg "${filename%.json}" \ + '{"releases": [ .local.repo[$pkg] | keys[] | {version: .} ]}' > "$OUTPUT_DIR/$filename" + done +} + +repo_as_json=$(cat) + +if ! echo "$repo_as_json" | jq empty 2>/dev/null; then + echo "Error: Valid JSON is required" >&2 + exit 1 +else + if [ ! -d "$OUTPUT_DIR" ]; then + mkdir -p "$OUTPUT_DIR" + fi + process_repo "$repo_as_json" +fi diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8b800a446..f9c7efc52 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -140,8 +140,38 @@ jobs: ignore: Collect results token: ${{ secrets.GITHUB_TOKEN }} - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - uses: codfish/semantic-release-action@b621d34fabe0940f031e89b6ebfea28322892a10 # v3.5.0 + with: + sparse-checkout: | + .cicd/ + .releaserc.cjs + - id: sem-rel + uses: codfish/semantic-release-action@b621d34fabe0940f031e89b6ebfea28322892a10 # v3.5.0 with: additional-packages: conventional-changelog-conventionalcommits@7.0.2 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - uses: actions/download-artifact@v4.1.8 + if: runner.debug || fromJSON(steps.sem-rel.outputs.new-release-published) + - name: Transform dumped repo data to Renovate-style JSON + if: runner.debug || fromJSON(steps.sem-rel.outputs.new-release-published) + run: | + if [ -f "$REPO_JSON_DIR/$REPO_JSON_FILE" ]; then + .cicd/transform-json < "$REPO_JSON_DIR/$REPO_JSON_FILE" + echo "::group::Display resulting directory structure" + ls --almost-all --recursive --ignore node_modules --ignore .git + echo "::endgroup::" + fi + - uses: peaceiris/actions-gh-pages@v4.0.0 + if: fromJSON(steps.sem-rel.outputs.new-release-published) + with: + commit_message: | + deploy: ${{ steps.sem-rel.outputs.git-tag }} + destination_dir: ${{ steps.sem-rel.outputs.git-tag }} + github_token: ${{ secrets.GITHUB_TOKEN }} + - uses: peaceiris/actions-gh-pages@v4.0.0 + if: fromJSON(steps.sem-rel.outputs.new-release-published) + with: + commit_message: | + deploy: ${{ steps.sem-rel.outputs.git-tag }} on ${{ steps.sem-rel.outputs.channel }} + destination_dir: ${{ steps.sem-rel.outputs.channel }} + github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ddc67ee92..3f0d03d83 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -27,3 +27,8 @@ repos: - id: biome-check name: Check JavaScript with biome additional_dependencies: ["@biomejs/biome@1.9.4"] + - repo: https://github.com/shellcheck-py/shellcheck-py + rev: v0.10.0.1 + hooks: + - id: shellcheck + name: Check shell scripts with shellcheck diff --git a/.releaserc.cjs b/.releaserc.cjs index 59c89fb3c..af7ca508b 100644 --- a/.releaserc.cjs +++ b/.releaserc.cjs @@ -23,6 +23,7 @@ const releaseRules = [ ]; const config = { + branches: [{ name: "ma(in|ster)", channel: "latest" }], plugins: [ ["@semantic-release/commit-analyzer", { releaseRules: releaseRules }], "@semantic-release/release-notes-generator",