publish #452
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: publish | |
| on: | |
| push: | |
| branches: ['main'] | |
| tags: | |
| - 'v*.*.*' | |
| concurrency: ${{ github.ref }} | |
| jobs: | |
| create-draft-release: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| outputs: | |
| RELEASE_ID: ${{ steps.create-release.outputs.result }} | |
| steps: | |
| - run: "echo \"RELEASE_TAG=${GITHUB_REF#refs/tags/}\" >> $GITHUB_ENV" | |
| - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9 https://github.com/actions/github-script/releases/tag/v9 | |
| id: create-release | |
| if: startsWith(github.ref, 'refs/tags/') | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| result-encoding: string | |
| script: | | |
| try { | |
| const response = await github.rest.repos.createRelease({ | |
| draft: true, | |
| generate_release_notes: true, | |
| name: process.env.RELEASE_TAG, | |
| owner: context.repo.owner, | |
| prerelease: false, | |
| repo: context.repo.repo, | |
| tag_name: process.env.RELEASE_TAG, | |
| }); | |
| return response.data.id; | |
| } catch (error) { | |
| core.setFailed(error.message); | |
| } | |
| build-binaries: | |
| strategy: | |
| matrix: | |
| os: [linux, darwin, freebsd, windows] | |
| arch: [amd64, arm64] | |
| runs-on: ubuntu-latest | |
| needs: [create-draft-release] | |
| permissions: | |
| actions: write | |
| attestations: write | |
| checks: write | |
| contents: write | |
| id-token: write | |
| packages: write | |
| statuses: write | |
| steps: | |
| - run: "echo \"RELEASE_TAG=${GITHUB_REF#refs/tags/}\" >> $GITHUB_ENV" | |
| - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 https://github.com/actions/checkout/releases/tag/v7.0.0 | |
| with: | |
| fetch-depth: '0' | |
| - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6 https://github.com/actions/setup-go/releases/tag/v6 | |
| with: | |
| go-version: 1.26.x | |
| cache: true | |
| - name: Update GeoCity2-Lite DB | |
| if: startsWith(github.ref, 'refs/tags/') | |
| run: resources/update.sh | |
| env: | |
| MAXMIND_API_CREDENTIALS: ${{ secrets.MAXMIND_API_CREDENTIALS }} | |
| - name: Build binary | |
| run: GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} make build | |
| - name: Upload release asset | |
| if: startsWith(github.ref, 'refs/tags/') | |
| run: | | |
| _filename=nview-${{ env.RELEASE_TAG }}-${{ matrix.os }}-${{ matrix.arch }} | |
| if [[ ${{ matrix.os }} == windows ]]; then | |
| _filename=${_filename}.exe | |
| fi | |
| cp nview ${_filename} | |
| curl \ | |
| -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| -H "Content-Type: application/octet-stream" \ | |
| --data-binary @${_filename} \ | |
| https://uploads.github.com/repos/${{ github.repository_owner }}/nview/releases/${{ needs.create-draft-release.outputs.RELEASE_ID }}/assets?name=${_filename} | |
| - name: Attest binary | |
| uses: actions/attest@a1948c3f048ba23858d222213b7c278aabede763 # v4.1.1 https://github.com/actions/attest/releases/tag/v4.1.1 | |
| with: | |
| subject-path: 'nview' | |
| build-images: | |
| runs-on: ubuntu-latest | |
| needs: [create-draft-release] | |
| permissions: | |
| actions: write | |
| attestations: write | |
| checks: write | |
| contents: write | |
| id-token: write | |
| packages: write | |
| statuses: write | |
| steps: | |
| - run: "echo \"RELEASE_TAG=${GITHUB_REF#refs/tags/}\" >> $GITHUB_ENV" | |
| - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 https://github.com/actions/checkout/releases/tag/v7.0.0 | |
| with: | |
| fetch-depth: '0' | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@06116385d9baf250c9f4dcb4858b16962ea869c3 # v4 https://github.com/docker/setup-qemu-action/releases/tag/v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4 https://github.com/docker/setup-buildx-action/releases/tag/v4 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4 https://github.com/docker/login-action/releases/tag/v4 | |
| with: | |
| username: blinklabs | |
| password: ${{ secrets.DOCKER_PASSWORD }} # uses token | |
| - name: Login to GHCR | |
| uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4 https://github.com/docker/login-action/releases/tag/v4 | |
| with: | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| registry: ghcr.io | |
| - id: meta | |
| uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 # v6 https://github.com/docker/metadata-action/releases/tag/v6 | |
| with: | |
| images: | | |
| blinklabs/nview | |
| ghcr.io/${{ github.repository }} | |
| tags: | | |
| # branch | |
| type=ref,event=branch | |
| # semver | |
| type=semver,pattern={{version}} | |
| - name: Update GeoCity2-Lite DB | |
| if: startsWith(github.ref, 'refs/tags/') | |
| run: resources/update.sh | |
| env: | |
| MAXMIND_API_CREDENTIALS: ${{ secrets.MAXMIND_API_CREDENTIALS }} | |
| - name: Build images | |
| uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7 https://github.com/docker/build-push-action/releases/tag/v7 | |
| id: push | |
| with: | |
| outputs: "type=registry,push=true" | |
| platforms: linux/amd64,linux/arm64 | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| build-args: | | |
| VERSION=${{ github.ref_type == 'tag' && github.ref_name || '' }} | |
| COMMIT_HASH=${{ github.sha }} | |
| - name: Attest Docker Hub image | |
| uses: actions/attest@a1948c3f048ba23858d222213b7c278aabede763 # v4.1.1 https://github.com/actions/attest/releases/tag/v4.1.1 | |
| with: | |
| subject-name: index.docker.io/blinklabs/nview | |
| subject-digest: ${{ steps.push.outputs.digest }} | |
| push-to-registry: true | |
| - name: Attest GHCR image | |
| uses: actions/attest@a1948c3f048ba23858d222213b7c278aabede763 # v4.1.1 https://github.com/actions/attest/releases/tag/v4.1.1 | |
| with: | |
| subject-name: ghcr.io/${{ github.repository }} | |
| subject-digest: ${{ steps.push.outputs.digest }} | |
| push-to-registry: true | |
| # Update Docker Hub from README | |
| - name: Docker Hub Description | |
| uses: peter-evans/dockerhub-description@1b9a80c056b620d92cedb9d9b5a223409c68ddfa # v5 https://github.com/peter-evans/dockerhub-description/releases/tag/v5 | |
| with: | |
| username: blinklabs | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| repository: blinklabs/nview | |
| readme-filepath: ./README.md | |
| short-description: "nview is a local monitoring tool for a Cardano node" | |
| finalize-release: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| needs: [create-draft-release, build-binaries, build-images] | |
| steps: | |
| - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9 https://github.com/actions/github-script/releases/tag/v9 | |
| if: startsWith(github.ref, 'refs/tags/') | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| try { | |
| await github.rest.repos.updateRelease({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| release_id: ${{ needs.create-draft-release.outputs.RELEASE_ID }}, | |
| draft: false, | |
| }); | |
| } catch (error) { | |
| core.setFailed(error.message); | |
| } |