diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/build-and-release.yml index 75f869f..8bb0026 100644 --- a/.github/workflows/build-and-release.yml +++ b/.github/workflows/build-and-release.yml @@ -1,84 +1,152 @@ -name: Run tests and publish +name: Run tests and release npm package on: workflow_dispatch: push: branches: - master + - main - development - beta + - auto-build paths-ignore: - 'docs/**' - 'README.md' - '.all-contributorsrc' pull_request: + branches: + - master + - main + - beta paths-ignore: - 'docs/**' - 'README.md' - '.all-contributorsrc' jobs: - run-build-on-node12: + # Install dependencies, run tests and try to build + test: + name: 'Build and test on Node v${{ matrix.node }}' runs-on: ubuntu-latest + strategy: + matrix: + node: [12, 14, 16] steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2 with: - node-version: 12 + node-version: ${{ matrix.node }} - name: Install depencencies run: npm ci - name: Run tests run: npm test - name: Build library run: npm run build + + # Release to NPM if its not a pull request + npm-release: + runs-on: ubuntu-latest + name: NPM Release + if: github.event_name != 'pull_request' + needs: [test] + outputs: + released: ${{ steps.semantic.outputs.new_release_published }} + version: ${{ steps.semantic.outputs.new_release_version }} + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: 16 + - name: Install depencencies + run: npm ci + - name: Build library + run: npm run build - name: Semantic Release uses: cycjimmy/semantic-release-action@v2 id: semantic env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + - name: Setup node for Github Registry + if: steps.semantic.outputs.new_release_published == 'true' + uses: actions/setup-node@v2 + with: + node-version: 16 + registry-url: 'https://npm.pkg.github.com' + scope: 'svrooij' + - name: Publish To GitHub Package Registry + if: steps.semantic.outputs.new_release_published == 'true' + run: | + sed -i 's+"name": "sonos2mqtt"+"name": "@svrooij/sonos2mqtt"+g' package**.json + npm publish + env: + NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} + + # Release container if it released to npm. + container-release: + runs-on: ubuntu-latest + name: Container release + needs: [npm-release] + if: needs.npm-release.released == 'true' + steps: + - uses: actions/checkout@v2 + - name: Set up QEMU (multi platform) uses: docker/setup-qemu-action@v1 - if: steps.semantic.outputs.new_release_published == 'true' with: platforms: all + - name: Set up Docker Buildx id: buildx - if: steps.semantic.outputs.new_release_published == 'true' uses: docker/setup-buildx-action@v1 with: version: latest + - name: Login to DockerHub uses: docker/login-action@v1 - if: steps.semantic.outputs.new_release_published == 'true' with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - - name: Publish to docker with buildx as latest - if: steps.semantic.outputs.new_release_published == 'true' && github.ref == 'refs/heads/master' + - + name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Publish container as latest + if: github.ref == 'refs/heads/master' run: | docker buildx build \ --platform linux/amd64,linux/arm/v7,linux/arm64 \ --push \ + -f ./Dockerfile.npm \ -t $GITHUB_REPOSITORY:latest \ - -t $GITHUB_REPOSITORY:${{ steps.semantic.outputs.new_release_version }} \ + -t $GITHUB_REPOSITORY:${{ needs.npm-release.version }} \ + -t ghcr.io/svrooij/sonos2mqtt:latest \ + -t ghcr.io/svrooij/sonos2mqtt:${{ needs.npm-release.version }} \ --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \ - --build-arg BUILD_VERSION=${{ steps.semantic.outputs.new_release_version }} \ + --build-arg BUILD_VERSION=${{ needs.npm-release.version }} \ --build-arg VSC_REF=$(echo ${GITHUB_SHA} | cut -c1-8) \ . - - name: Publish to docker with buildx as beta - if: steps.semantic.outputs.new_release_published == 'true' && github.ref != 'refs/heads/master' + + - name: Publish container as beta + if: github.ref != 'refs/heads/master' run: | docker buildx build \ --platform linux/amd64,linux/arm/v7,linux/arm64 \ --push \ + -f ./Dockerfile.npm \ -t $GITHUB_REPOSITORY:beta \ - -t $GITHUB_REPOSITORY:${{ steps.semantic.outputs.new_release_version }} \ + -t $GITHUB_REPOSITORY:${{ needs.npm-release.version }} \ + -t ghcr.io/svrooij/sonos2mqtt:beta \ + -t ghcr.io/svrooij/sonos2mqtt:${{ needs.npm-release.version }} \ --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \ - --build-arg BUILD_VERSION=${{ steps.semantic.outputs.new_release_version }} \ + --build-arg BUILD_VERSION=${{ needs.npm-release.version }} \ --build-arg VSC_REF=$(echo ${GITHUB_SHA} | cut -c1-8) \ . diff --git a/Dockerfile.npm b/Dockerfile.npm new file mode 100644 index 0000000..1a233d4 --- /dev/null +++ b/Dockerfile.npm @@ -0,0 +1,26 @@ +# FROM node:current-alpine as build +# WORKDIR /usr/src/app +# COPY package*.json tsconfig.json ./ +# RUN npm ci +# COPY ./src ./src +# RUN npm run build + +FROM node:current-alpine as prod +ENV SONOS2MQTT_RUNNING_IN_CONTAINER=true +WORKDIR /usr/src/app + +ARG BUILD_VERSION=latest + +RUN npm install -g sonos2mqtt@${BUILD_VERSION} + +ARG BUILD_DATE=unknown +ARG VCS_REF=unknown +LABEL org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.description="Connecting your sonos speakers to mqtt" \ + org.label-schema.name=sonos2mqtt \ + org.label-schema.schema-version=1.0 \ + org.label-schema.url=https://github.com/svrooij/sonos2mqtt/ \ + org.label-schema.version=$BUILD_VERSION \ + org.label-schema.vcs-ref=$VCS_REF +EXPOSE 6329 +CMD ["sonos2mqtt"] diff --git a/README.md b/README.md index ded6bb5..f6a250c 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ See: [https://svrooij.github.io/sonos2mqtt](https://svrooij.github.io/sonos2mqtt ## Node-sonos-ts +[![Sonos typescript this library][badge_sonos-typescript]][link_sonos-typescript] + This library depends on [node-sonos-ts](https://github.com/svrooij/node-sonos-ts/) which I also developed. All other libraries using node-sonos-ts should also be able to implemented all the nice features included there. Like **notifications** or **text-to-speech** which are the coolest new additions for **sonos2mqtt**! ## Beer or Coffee @@ -78,7 +80,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! -[badge_build]: https://github.com/svrooij/sonos2mqtt/workflows/Run%20tests%20and%20publish/badge.svg +[badge_build]: https://github.com/svrooij/sonos2mqtt/workflows/Run%20tests%20and%20release%20npm%20package/badge.svg [badge_docker]: https://img.shields.io/docker/pulls/svrooij/sonos2mqtt [badge_discord]: https://img.shields.io/discord/782374564054564875?style=flat-square [badge_issues]: https://img.shields.io/github/issues/svrooij/sonos2mqtt?style=flat-square