Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

πŸ‘· Auto bump version on PR merge, and trigger new docker tags

Alicia Sykes543258417a66
diff --git a/.github/workflows/bump-and-tag.yml b/.github/workflows/bump-and-tag.yml
new file mode 100644
index 00000000..dd0ad787
--- /dev/null
+++ b/.github/workflows/bump-and-tag.yml
@@ -0,0 +1,108 @@
+# When a PR is merged into master, this workflow handles versioning:
+# - If code files changed but version wasn't bumped: auto-increments patch version
+# - Creates and pushes a git tag for the new version
+# - The tag then triggers Docker publishing and release drafting
+name: πŸ”– Auto Version & Tag
+
+on:
+ pull_request:
+ types: [closed]
+ branches: [master]
+
+concurrency:
+ group: auto-version-and-tag
+ cancel-in-progress: false
+
+permissions:
+ contents: read
+ pull-requests: read
+
+jobs:
+ version-and-tag:
+ if: github.event.pull_request.merged == true
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Check PR for code changes and version bump πŸ“‚
+ id: check_pr
+ uses: actions/github-script@v7
+ with:
+ script: |
+ const { owner, repo } = context.repo;
+ const pull_number = context.payload.pull_request.number;
+
+ const files = await github.paginate(
+ github.rest.pulls.listFiles, { owner, repo, pull_number }
+ );
+ const codePatterns = [
+ /^src\//, /^services\//, /^public\//, /^Dockerfile$/, /^[^/]+\.js$/,
+ ];
+ const codeChanged = files.some(f =>
+ codePatterns.some(p => p.test(f.filename))
+ );
+ const pkgChanged = files.some(f => f.filename === 'package.json');
+
+ if (!codeChanged && !pkgChanged) {
+ core.info('No code or package.json changes, skipping');
+ core.setOutput('needs_bump', 'false');
+ core.setOutput('needs_tag', 'false');
+ return;
+ }
+
+ let versionBumped = false;
+ if (pkgChanged) {
+ const mergeSha = context.payload.pull_request.merge_commit_sha;
+ const { data: mergeCommit } = await github.rest.git.getCommit({
+ owner, repo, commit_sha: mergeSha,
+ });
+ const parentSha = mergeCommit.parents[0].sha;
+ const getVersion = async (ref) => {
+ const { data } = await github.rest.repos.getContent({
+ owner, repo, path: 'package.json', ref,
+ });
+ return JSON.parse(Buffer.from(data.content, 'base64').toString()).version;
+ };
+ const [prevVersion, mergeVersion] = await Promise.all([
+ getVersion(parentSha), getVersion(mergeSha),
+ ]);
+ versionBumped = prevVersion !== mergeVersion;
+ core.info(`Version: ${prevVersion} β†’ ${mergeVersion}`);
+ }
+
+ const needsBump = codeChanged && !versionBumped;
+ const needsTag = codeChanged || versionBumped;
+ core.info(`Needs bump: ${needsBump}, Needs tag: ${needsTag}`);
+ core.setOutput('needs_bump', needsBump.toString());
+ core.setOutput('needs_tag', needsTag.toString());
+
+ - name: Checkout repository πŸ›ŽοΈ
+ if: steps.check_pr.outputs.needs_tag == 'true'
+ uses: actions/checkout@v4
+ with:
+ token: ${{ secrets.BOT_GITHUB_TOKEN }}
+
+ - name: Configure git identity πŸ‘€
+ if: steps.check_pr.outputs.needs_tag == 'true'
+ run: |
+ git config user.name "Liss-Bot"
+ git config user.email "[email protected]"
+
+ - name: Bump patch version ⬆️
+ if: steps.check_pr.outputs.needs_bump == 'true'
+ run: |
+ npm version patch --no-git-tag-version
+ git add package.json
+ git commit -m "⬆️ Bump version to $(node -p "require('./package.json').version")"
+ git push
+
+ - name: Create and push tag 🏷️
+ if: steps.check_pr.outputs.needs_tag == 'true'
+ run: |
+ VERSION=$(node -p "require('./package.json').version")
+ git fetch --tags
+ if git rev-parse "refs/tags/$VERSION" >/dev/null 2>&1; then
+ echo "Tag $VERSION already exists, skipping"
+ exit 0
+ fi
+ git tag -a "$VERSION" -m "Release v$VERSION"
+ git push origin "$VERSION"
diff --git a/.github/workflows/create-tag-for-version.yml b/.github/workflows/create-tag-for-version.yml
index e20cb5d3..a17305c7 100644
--- a/.github/workflows/create-tag-for-version.yml
+++ b/.github/workflows/create-tag-for-version.yml
@@ -1,15 +1,9 @@
-# When Dashy's version in package.json is updated
-# this workflow will create a new tag
-# And then publish it to the repository
+# Manual fallback for creating a tag from the current package.json version.
+# The automated flow is handled by bump-and-tag.yml on PR merge.
name: πŸ—οΈ Tag on Version Change
on:
workflow_dispatch:
- push:
- branches:
- - master
- paths:
- - 'package.json'
jobs:
tag-if-version-updated:
@@ -17,39 +11,25 @@ jobs:
steps:
- name: Check Out Repository πŸ›ŽοΈ
- uses: actions/checkout@v2
-
- - name: Set Up Python 🐍
- uses: actions/setup-python@v4
+ uses: actions/checkout@v4
with:
- python-version: '3.x'
+ token: ${{ secrets.BOT_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
+ fetch-depth: 0
- name: Extract Version from package.json πŸ”’
id: package_version
- run: |
- import json
- with open('package.json', 'r') as f:
- version = json.load(f)['version']
- print(f"::set-output name=VERSION::{version}")
- shell: python
-
+ run: echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
+
- name: Get Latest Tag 🏷️
id: latest_tag
run: |
- git fetch --tags
- latest_tag=$(git describe --tags `git rev-list --tags --max-count=1` 2>/dev/null)
- echo "::set-output name=TAG::${latest_tag:-0}"
-
+ latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1) 2>/dev/null)
+ echo "TAG=${latest_tag:-0}" >> $GITHUB_OUTPUT
+
- name: Create and Push Tag ‴️
if: steps.package_version.outputs.VERSION != steps.latest_tag.outputs.TAG && steps.latest_tag.outputs.TAG != '0'
run: |
- git config --local user.email "[email protected]"
- git config --local user.name "Liss-Bot"
- git tag -a ${{ steps.package_version.outputs.VERSION }} -m "Release v${{ steps.package_version.outputs.VERSION }}"
- git push origin ${{ steps.package_version.outputs.VERSION }}
- env:
- GIT_AUTHOR_NAME: Liss-Bot
- GIT_AUTHOR_EMAIL: [email protected]
- GIT_COMMITTER_NAME: Liss-Bot
- GIT_COMMITTER_EMAIL: [email protected]
- GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
+ git config user.name "Liss-Bot"
+ git config user.email "[email protected]"
+ git tag -a "${{ steps.package_version.outputs.VERSION }}" -m "Release v${{ steps.package_version.outputs.VERSION }}"
+ git push origin "${{ steps.package_version.outputs.VERSION }}"
diff --git a/.github/workflows/docker-build-publish.yml b/.github/workflows/docker-build-publish.yml
index 27851e01..b1112533 100644
--- a/.github/workflows/docker-build-publish.yml
+++ b/.github/workflows/docker-build-publish.yml
@@ -3,15 +3,7 @@ name: 🐳 Build + Publish Multi-Platform Image
on:
workflow_dispatch:
push:
- branches: ['master']
- tags: ['*.*']
- paths:
- - '**.js'
- - 'src/**'
- - 'public/**'
- - 'services/**'
- - '.github/workflows/docker-build-publish.yml'
- - 'Dockerfile'
+ tags: ['*.*.*']
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
@@ -28,26 +20,21 @@ jobs:
docker:
runs-on: ubuntu-latest
permissions: { contents: read, packages: write }
- if: "!contains(github.event.head_commit.message, '[ci-skip]')"
steps:
- name: πŸ›ŽοΈ Checkout Repo
- uses: actions/checkout@v3
-
- - name: πŸ”– Get App Version
- uses: tyankatsu0105/read-package-version-actions@v1
- id: package-version
+ uses: actions/checkout@v4
- name: πŸ—‚οΈ Make Docker Meta
id: meta
- uses: docker/metadata-action@v3
+ uses: docker/metadata-action@v5
with:
images: |
${{ env.DH_IMAGE }}
ghcr.io/${{ env.GH_IMAGE }}
tags: |
type=ref,event=tag
- type=semver,pattern={{version}},enable=false
+ type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}.x
type=raw,value=latest
flavor: |
@@ -61,42 +48,31 @@ jobs:
org.opencontainers.image.licenses=MIT
- name: πŸ”§ Set up QEMU
- uses: docker/setup-qemu-action@v1
+ uses: docker/setup-qemu-action@v3
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7
- name: πŸ”§ Set up Docker Buildx
- uses: docker/setup-buildx-action@v2
- with:
- use-buildkit: true
- buildkit-daemon-opts: "--oci-worker-no-process-sandbox"
-
- - name: πŸ‘€ Inspect builder
- run: |
- echo "Name: ${{ steps.buildx.outputs.name }}"
- echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
- echo "Status: ${{ steps.buildx.outputs.status }}"
- echo "Flags: ${{ steps.buildx.outputs.flags }}"
- echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
+ uses: docker/setup-buildx-action@v3
- name: πŸ”‘ Login to DockerHub
- uses: docker/login-action@v2
+ uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: πŸ”‘ Login to GitHub Container Registry
- uses: docker/login-action@v2
+ uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: 🚦 Check Registry Status
- uses: crazy-max/ghaction-docker-status@v1
+ uses: crazy-max/ghaction-docker-status@v3
- name: βš’οΈ Build and push
- uses: docker/build-push-action@v3
+ uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
diff --git a/.github/workflows/draft-release.yml b/.github/workflows/draft-release.yml
index 251349ef..8de198c7 100644
--- a/.github/workflows/draft-release.yml
+++ b/.github/workflows/draft-release.yml
@@ -3,8 +3,7 @@ name: πŸ—οΈ Draft New Release
on:
push:
tags:
- - '^[0-9]+\.[0-9]+\.[0-9]+$'
- - '**'
+ - '*.*.*'
workflow_dispatch:
inputs:
tag:
@@ -16,21 +15,43 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code πŸ›ŽοΈ
- uses: actions/checkout@v2
+ uses: actions/checkout@v4
with:
- fetch-depth: 0 # We need all history for generating release notes
+ fetch-depth: 0
+
+ - name: Check if major or minor version changed πŸ”
+ id: version_check
+ run: |
+ CURRENT_TAG="${{ github.event.inputs.tag || github.ref_name }}"
+ git fetch --tags
+ PREVIOUS_TAG=$(git tag --sort=-version:refname | grep -v "^${CURRENT_TAG}$" | head -1)
+ if [ -z "$PREVIOUS_TAG" ]; then
+ echo "No previous tag found, creating release"
+ echo "should_release=true" >> $GITHUB_OUTPUT
+ exit 0
+ fi
+ CURRENT_MM=$(echo "$CURRENT_TAG" | sed 's/^v//; s/\([0-9]*\.[0-9]*\)\..*/\1/')
+ PREVIOUS_MM=$(echo "$PREVIOUS_TAG" | sed 's/^v//; s/\([0-9]*\.[0-9]*\)\..*/\1/')
+ if [ "$CURRENT_MM" = "$PREVIOUS_MM" ]; then
+ echo "Patch-only bump ($PREVIOUS_TAG -> $CURRENT_TAG), skipping release"
+ echo "should_release=false" >> $GITHUB_OUTPUT
+ else
+ echo "Major or minor bump ($PREVIOUS_TAG -> $CURRENT_TAG), creating release"
+ echo "should_release=true" >> $GITHUB_OUTPUT
+ fi
- name: Create Draft Release πŸ“
+ if: steps.version_check.outputs.should_release == 'true' || github.event_name == 'workflow_dispatch'
id: create_release
- uses: actions/create-release@v1
- env:
- GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
+ uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.event.inputs.tag || github.ref_name }}
- release_name: Release ${{ github.event.inputs.tag || github.ref_name }}
+ name: Release ${{ github.event.inputs.tag || github.ref_name }}
draft: true
prerelease: false
generate_release_notes: true
+ token: ${{ secrets.BOT_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
- name: Output new release URL ↗️
- run: 'echo "Draft release URL: ${{ steps.create_release.outputs.html_url }}"'
+ if: steps.create_release.outputs.url
+ run: 'echo "Draft release URL: ${{ steps.create_release.outputs.url }}"'