Skip to content

Commit

Permalink
Merge pull request #2242 from dafyddj/ci/deploy-json
Browse files Browse the repository at this point in the history
ci: deploy Renovate-style JSON to GitHub Pages
  • Loading branch information
dafyddj authored Nov 24, 2024
2 parents 6299255 + 4b64d07 commit c054684
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
29 changes: 29 additions & 0 deletions .cicd/transform-json
Original file line number Diff line number Diff line change
@@ -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 <package>.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
32 changes: 31 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .releaserc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit c054684

Please sign in to comment.