From e5e10ba33e91cf2cbc601af71cb0d6982c6b77a5 Mon Sep 17 00:00:00 2001 From: Chris Grieser <73286100+chrisgrieser@users.noreply.github.com> Date: Tue, 11 Jun 2024 15:35:45 +0200 Subject: [PATCH] build: bump & update changelog via GitHub action instead of locally --- .github/workflows/build-and-bump.yml | 67 ++++++++++++++++++++++++++++ Justfile | 27 +++++------ bump-version-and-changelog.sh | 42 ----------------- 3 files changed, 77 insertions(+), 59 deletions(-) create mode 100644 .github/workflows/build-and-bump.yml delete mode 100755 bump-version-and-changelog.sh diff --git a/.github/workflows/build-and-bump.yml b/.github/workflows/build-and-bump.yml new file mode 100644 index 00000000..ea710b64 --- /dev/null +++ b/.github/workflows/build-and-bump.yml @@ -0,0 +1,67 @@ +name: Build, Bump version numbers, and update changelog + +on: + push: + branches: [main] # not on insider release branch + workflow_dispatch: + +permissions: + contents: write + +jobs: + bump: + runs-on: macos-latest + name: Build, Bump version numbers, and update changelog + steps: + - name: Checkout + uses: actions/checkout@v4 + # by default, no tags and only a single commit is fetched. To use git + # history in the changelog steop, we need to fetch all history. + with: + fetch-depth: 0 # 0 = all history + fetch-tags: true + + #───────────────────────────────────────────────────────────────────────── + + - name: Build + run: | + cat ./source/*.css <(echo "/* @settings") ./source/style-settings.yaml <(echo "*/") \ + > ./theme.css + + - name: Bump version numbers + run: | + theme_header="./source/00 header.css" + + versionLine=$(grep --line-number --max-count=1 "^Version" "$theme_header") + versionLnum=$(echo "$versionLine" | cut -d: -f1) + + currentVer=$(echo "$versionLine" | cut -d. -f2) + nextVer=$((currentVer + 1)) + + sed -E -i '' "${versionLnum} s/$currentVer/$nextVer/" "$theme_header" + sed -E -i '' "${versionLnum} s/$currentVer/$nextVer/" "./theme.css" + sed -E -i '' "/version/ s/$currentVer/$nextVer/" "./manifest.json" + + - name: Update Download Count in Readme + run: | + dl=$(curl -s "https://releases.obsidian.md/stats/theme" | + grep -oe '"Shimmering Focus","download":[[:digit:]]*' | + cut -d: -f2) + sed -E -i '' "s/badge.*-[[:digit:]]+-/badge\/downloads-$dl-/" ./README.md + + - name: Update Changelog + run: | + commits_since_last_publish=$(git log :/bump.. --format="- %cs %s") + + echo "$commits_since_last_publish" | + grep -vE "build|ci|style|bump" | # don't include internal changes + sed -E "s/^(- [0-9-]+) ([^ ]+): /\1 **\2**: /" >> "temp.md" # bold title + grep -v "^$" "Changelog.md" >> "temp.md" + mv -f "temp.md" "Changelog.md" + + #───────────────────────────────────────────────────────────────────────── + + - uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "bump: version & update changelog" + branch: ${{ github.head_ref }} diff --git a/Justfile b/Justfile index a0455a7d..d9221be6 100644 --- a/Justfile +++ b/Justfile @@ -1,32 +1,25 @@ set quiet := true +vault_to_open := "main-vault" + #─────────────────────────────────────────────────────────────────────────────── -_build: +# uses personal vaults saved in `~/.config/perma-repos.csv` +build_and_push_to_local_vaults: #!/usr/bin/env zsh + # BUILD # Due to globbing, the source files are inserted in alphabetical order. # To keep things predictable, they are simply number in the order they # should be included in. cat ./source/*.css <(echo "/* @settings") ./source/style-settings.yaml <(echo "*/") \ - > ./theme.css + > /tmp/theme.css -# uses personal vaults saved in `~/.config/perma-repos.csv` -_push-to-local-vaults: - #!/usr/bin/env zsh + # PUSH TO LOCAL VAULTS cut -d, -f2 "$HOME/.config/perma-repos.csv" | sed "s|^~|$HOME|" | xargs -I {} find {} -maxdepth 1 -name ".obsidian" | # only vaults xargs dirname | # vault root - xargs -I {} cp -f "./theme.css" "{}/.obsidian/themes/Shimmering Focus/theme.css" - -#────────────────────────────────────────────────────────────────────────────── - -build-and-reload: && _build _push-to-local-vaults - open -a "Obsidian" - -theme_header := "./source/00 header.css" - -bump-version-and-changelog: && _build _push-to-local-vaults - zsh ./bump-version-and-changelog.sh "{{ theme_header }}" + xargs -I {} cp -f "/tmp/theme.css" "{}/.obsidian/themes/Shimmering Focus/theme.css" -only-build: _build + # OPEN OBSIDIAN + open "obsidian://open?vault={{ vault_to_open }}" diff --git a/bump-version-and-changelog.sh b/bump-version-and-changelog.sh deleted file mode 100755 index 808ed7eb..00000000 --- a/bump-version-and-changelog.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env zsh -#─────────────────────────────────────────────────────────────────────────────── - -# BUMP VERSION NUMBERS -theme_header="$1" - -versionLine=$(grep --line-number --max-count=1 "^Version" "$theme_header") -versionLnum=$(echo "$versionLine" | cut -d: -f1) - -currentVer=$(echo "$versionLine" | cut -d. -f2) -nextVer=$((currentVer + 1)) - -sed -E -i '' "${versionLnum} s/$currentVer/$nextVer/" "$theme_header" -sed -E -i '' "${versionLnum} s/$currentVer/$nextVer/" "./theme.css" -sed -E -i '' "/version/ s/$currentVer/$nextVer/" "./manifest.json" - -#─────────────────────────────────────────────────────────────────────────────── -# DOWNLOAD COUNT (in Readme.md) - -dl=$(curl -s "https://releases.obsidian.md/stats/theme" | - grep -oe '"Shimmering Focus","download":[[:digit:]]*' | - cut -d: -f2) -sed -E -i '' "s/badge.*-[[:digit:]]+-/badge\/downloads-$dl-/" ./README.md - -#─────────────────────────────────────────────────────────────────────────────── -# UPDATE CHANGELOG - -# only add to changelog if on `main` -if [[ "$(git branch --show-current)" == "main" ]]; then - commits_since_last_publish=$(git log :/bump.. --format="- %cs %s") - - echo "$commits_since_last_publish" | - grep -vE "build|ci|style|bump" | # don't include internal changes - sed -E "s/^(- [0-9-]+) ([^ ]+): /\1 **\2**: /" >> "temp.md" # bold title - grep -v "^$" "Changelog.md" >> "temp.md" - mv -f "temp.md" "Changelog.md" -fi - -# ─────────────────────────────────────────────────────────────────────────────── -# COMMIT -git add "$theme_header" Changelog.md manifest.json README.md theme.css && - git commit -m "bump: version & update changelog" --author="🤖 bump"