Update CHANGELOG.md with new sections (#19) #18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 'Build,Publish Docker and NPM' | |
| on: | |
| workflow_dispatch: {} | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| id-token: write | |
| contents: write | |
| env: | |
| DOCKER_IMAGE_NAME: wifidb/contour-generator | |
| jobs: | |
| release-check: | |
| name: Check if version is published | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| shell: bash | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version: '24' | |
| check-latest: true | |
| cache: 'npm' | |
| - name: Install NPM dependencies 🚀 | |
| run: npm ci | |
| - name: Check if version is published | |
| id: check | |
| run: | | |
| PACKAGE_VERSION="$( node -e "console.log(require('./package.json').version)" )" | |
| RELEASE_TYPE="$(node -e "const semver = require('semver'); const prerelease = semver.prerelease('$PACKAGE_VERSION'); console.log(prerelease ? 'prerelease' : 'regular')")" | |
| isPublished="$( npm view contour-generator versions --json | jq -c --arg cv "$PACKAGE_VERSION" 'any(. == $cv)' )" | |
| echo "version=$PACKAGE_VERSION" >> "$GITHUB_OUTPUT" | |
| echo "published=$isPublished" >> "$GITHUB_OUTPUT" | |
| echo "release_type=$RELEASE_TYPE" >> "$GITHUB_OUTPUT" | |
| echo "PACKAGE_VERSION: $PACKAGE_VERSION" | |
| echo "RELEASE_TYPE: $RELEASE_TYPE" | |
| echo "isPublished: $isPublished" | |
| outputs: | |
| published: ${{ steps.check.outputs.published }} | |
| version: ${{ steps.check.outputs.version }} | |
| release_type: ${{ steps.check.outputs.release_type }} | |
| # Build and push individual architecture images (with tests) | |
| build_docker_images: | |
| name: Build Docker ${{ matrix.arch }} Image | |
| runs-on: ${{ matrix.runs-on }} | |
| needs: release-check | |
| if: ${{ needs.release-check.outputs.published == 'false' }} | |
| environment: release | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - runs-on: ubuntu-24.04 | |
| arch: amd64 | |
| - runs-on: ubuntu-24.04-arm | |
| arch: arm64 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USER }} | |
| password: ${{ secrets.DOCKER_TOKEN }} | |
| # Build and Push Main Image | |
| - name: Build and Push Main ${{ matrix.arch }} Image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| push: true | |
| platforms: linux/${{ matrix.arch }} | |
| tags: | | |
| ${{ env.DOCKER_IMAGE_NAME }}:v${{ needs.release-check.outputs.version }}-${{ matrix.arch }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| # Create manifests, publish NPM, and create GitHub release | |
| release: | |
| name: Release | |
| runs-on: ubuntu-latest | |
| needs: [release-check, build_docker_images] | |
| if: ${{ needs.release-check.outputs.published == 'false' }} | |
| environment: release | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| - name: Setup node env 📦 | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: '24' | |
| check-latest: true | |
| cache: 'npm' | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Install NPM dependencies 🚀 | |
| run: npm ci | |
| - name: Get release type | |
| id: prepare_release | |
| run: | | |
| if [[ ${{ needs.release-check.outputs.release_type }} == 'regular' ]]; then | |
| echo "prerelease=false" >> "$GITHUB_OUTPUT" | |
| echo "tag=latest" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "prerelease=true" >> "$GITHUB_OUTPUT" | |
| echo "tag=next" >> "$GITHUB_OUTPUT" | |
| fi | |
| # NPM Publishing | |
| - name: Publish to NPM | |
| # Uses OIDC + GitHub Trusted Publishing; requires `permissions: id-token: write` and | |
| # the repository to be configured as a Trusted Publisher for the npm package. | |
| run: | | |
| npm publish --access public --tag ${{ steps.prepare_release.outputs.tag }} | |
| # Docker Manifest Creation | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USER }} | |
| password: ${{ secrets.DOCKER_TOKEN }} | |
| - name: Create and push Main Multi-Arch Manifest | |
| run: | | |
| PACKAGE_VERSION="${{ needs.release-check.outputs.version }}" | |
| docker buildx imagetools create \ | |
| --tag "${{ env.DOCKER_IMAGE_NAME }}:${{ steps.prepare_release.outputs.tag }}" \ | |
| --tag "${{ env.DOCKER_IMAGE_NAME }}:v${PACKAGE_VERSION}" \ | |
| "${{ env.DOCKER_IMAGE_NAME }}:v${PACKAGE_VERSION}-amd64" \ | |
| "${{ env.DOCKER_IMAGE_NAME }}:v${PACKAGE_VERSION}-arm64" | |
| # GitHub Release | |
| - name: Extract changelog for version | |
| run: | | |
| VERSION="${{ needs.release-check.outputs.version }}" | |
| awk -v ver="## $VERSION" 'BEGIN{p=0} $0==ver{p=1; next} /^## / && p==1{exit} p==1{print}' CHANGELOG.md > changelog_for_version.md | |
| if [ ! -s changelog_for_version.md ]; then | |
| echo "No changelog found for version $VERSION" > changelog_for_version.md | |
| fi | |
| cat changelog_for_version.md | |
| - name: Publish to GitHub Release | |
| uses: ncipollo/release-action@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag: v${{ needs.release-check.outputs.version }} | |
| name: v${{ needs.release-check.outputs.version }} | |
| bodyFile: changelog_for_version.md | |
| allowUpdates: true | |
| draft: false | |
| prerelease: ${{ steps.prepare_release.outputs.prerelease }} |