feat: semantic versioning, github action features, writes a version file, and tags Docker images

pull/106/head
Jeff Culverhouse 4 months ago
parent 65a3fe5e53
commit 69c4f1ac57

@ -1,4 +1,4 @@
name: Docker Image CI name: Release and Docker Deploy
on: on:
push: push:
@ -6,15 +6,72 @@ on:
- "main" - "main"
workflow_dispatch: workflow_dispatch:
permissions:
contents: write
issues: write
pull-requests: write
packages: write
jobs: jobs:
release:
name: Semantic Release
runs-on: ubuntu-latest
outputs:
release_tag: ${{ steps.get_release.outputs.release_tag }}
release_notes: ${{ steps.semantic.outputs.release_notes }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: npm ci
- name: Run semantic-release
id: semantic
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npx semantic-release
RELEASE_NOTES=$(npx semantic-release --dry-run | grep -A100 "Next release version" || true)
echo "release_notes<<EOF" >> $GITHUB_OUTPUT
echo "$RELEASE_NOTES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Get latest release tag
id: get_release
run: |
TAG=$(git describe --tags --abbrev=0)
echo "$TAG" > VERSION
echo "release_tag=$TAG" >> $GITHUB_OUTPUT
- name: Commit VERSION file
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add VERSION
git commit -m "chore: update VERSION to ${{ steps.get_release.outputs.release_tag }}" || echo "No changes to commit"
git push
docker: docker:
name: Build and Push Docker Image
needs: release
if: ${{ needs.release.result == 'success' }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
env:
RELEASE_TAG: ${{ needs.release.outputs.release_tag }}
RELEASE_NOTES: ${{ needs.release.outputs.release_notes }}
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
# Authenticate to the container registry
- name: Login to Docker Hub - name: Login to Docker Hub
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:
@ -27,7 +84,6 @@ jobs:
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
# Build and push Docker image with Buildx
- name: Build and push - name: Build and push
id: build-and-push id: build-and-push
uses: docker/build-push-action@v6 uses: docker/build-push-action@v6
@ -35,7 +91,14 @@ jobs:
sbom: true sbom: true
provenance: true provenance: true
platforms: linux/arm64,linux/amd64 platforms: linux/arm64,linux/amd64
tags: graystorm/amcrest2mqtt:latest tags: |
graystorm/amcrest2mqtt:latest
graystorm/amcrest2mqtt:${{ env.RELEASE_TAG }}
push: true push: true
cache-from: type=gha cache-from: type=gha
cache-to: type=gha,mode=max cache-to: type=gha,mode=max
labels: |
org.opencontainers.image.version=${{ env.RELEASE_TAG }}
org.opencontainers.image.title=amcrest2mqtt
org.opencontainers.image.description=${{ env.RELEASE_NOTES }}
org.opencontainers.image.source=${{ github.repository }}

15
.gitignore vendored

@ -1,18 +1,29 @@
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files
__pycache__/ __pycache__/
*.py[cod] *.py[cod]
*$py.class
# Distribution / packaging # Distribution / packaging
.Python .Python
build/ build/
dist/ dist/
lib/
include/
node_modules/
# Environments # Environments
.env
.venv
venv/ venv/
# Config testing and notes # Local testing and notes
config config
config/ config/
config.yaml config.yaml
govee2mqtt.dat
npm-debug.log
NOTES NOTES
coverage/
dist/
# Apple
.DS_Store

@ -0,0 +1,13 @@
{
"branches": ["main"],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
["@semantic-release/changelog", { "changelogFile": "CHANGELOG.md" }],
["@semantic-release/git", {
"assets": ["CHANGELOG.md", "package.json", "VERSION"],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}],
"@semantic-release/github"
]
}
Loading…
Cancel
Save