diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 2ddfed5..5dfcbda 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -1,4 +1,4 @@ -name: Docker Image CI +name: Release and Docker Deploy on: push: @@ -6,36 +6,99 @@ on: - "main" workflow_dispatch: +permissions: + contents: write + issues: write + pull-requests: write + packages: write + 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<> $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: + name: Build and Push Docker Image + needs: release + if: ${{ needs.release.result == 'success' }} runs-on: ubuntu-latest + env: + RELEASE_TAG: ${{ needs.release.outputs.release_tag }} + RELEASE_NOTES: ${{ needs.release.outputs.release_notes }} steps: - - name: Checkout code - uses: actions/checkout@v4 - - # Authenticate to the container registry - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ vars.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PAT }} - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - # Build and push Docker image with Buildx - - name: Build and push - id: build-and-push - uses: docker/build-push-action@v6 - with: - sbom: true - provenance: true - platforms: linux/arm64,linux/amd64 - tags: graystorm/amcrest2mqtt:latest - push: true - cache-from: type=gha - cache-to: type=gha,mode=max + - name: Checkout code + uses: actions/checkout@v4 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PAT }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push + id: build-and-push + uses: docker/build-push-action@v6 + with: + sbom: true + provenance: true + platforms: linux/arm64,linux/amd64 + tags: | + graystorm/amcrest2mqtt:latest + graystorm/amcrest2mqtt:${{ env.RELEASE_TAG }} + push: true + cache-from: type=gha + 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 }} diff --git a/.gitignore b/.gitignore index 006acbe..0690cb6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,18 +1,29 @@ # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] -*$py.class # Distribution / packaging .Python build/ dist/ +lib/ +include/ +node_modules/ # Environments +.env +.venv venv/ -# Config testing and notes +# Local testing and notes config config/ config.yaml +govee2mqtt.dat +npm-debug.log NOTES +coverage/ +dist/ + +# Apple +.DS_Store \ No newline at end of file diff --git a/.releaserc b/.releaserc new file mode 100644 index 0000000..8159057 --- /dev/null +++ b/.releaserc @@ -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" + ] +}