|
| 1 | +name: publish |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ['main'] |
| 6 | + tags: ['v*.*.*'] |
| 7 | + |
| 8 | +concurrency: ${{ github.ref }} |
| 9 | + |
| 10 | +jobs: |
| 11 | + create-draft-release: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + outputs: |
| 14 | + RELEASE_ID: ${{ steps.create-release.outputs.result }} |
| 15 | + steps: |
| 16 | + - run: "echo \"RELEASE_TAG=${GITHUB_REF#refs/tags/}\" >> $GITHUB_ENV" |
| 17 | + - uses: actions/github-script@v6 |
| 18 | + id: create-release |
| 19 | + if: startsWith(github.ref, 'refs/tags/') |
| 20 | + with: |
| 21 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 22 | + result-encoding: string |
| 23 | + script: | |
| 24 | + try { |
| 25 | + const response = await github.rest.repos.createRelease({ |
| 26 | + draft: true, |
| 27 | + generate_release_notes: true, |
| 28 | + name: process.env.RELEASE_TAG, |
| 29 | + owner: context.repo.owner, |
| 30 | + prerelease: false, |
| 31 | + repo: context.repo.repo, |
| 32 | + tag_name: process.env.RELEASE_TAG, |
| 33 | + }); |
| 34 | +
|
| 35 | + return response.data.id; |
| 36 | + } catch (error) { |
| 37 | + core.setFailed(error.message); |
| 38 | + } |
| 39 | +
|
| 40 | + build-binaries: |
| 41 | + strategy: |
| 42 | + matrix: |
| 43 | + os: [linux, darwin, freebsd, windows] |
| 44 | + arch: [amd64, arm64] |
| 45 | + runs-on: ubuntu-latest |
| 46 | + needs: [create-draft-release] |
| 47 | + steps: |
| 48 | + - run: "echo \"RELEASE_TAG=${GITHUB_REF#refs/tags/}\" >> $GITHUB_ENV" |
| 49 | + - uses: actions/checkout@v3 |
| 50 | + - uses: actions/setup-go@v3 |
| 51 | + with: |
| 52 | + go-version: 1.18 |
| 53 | + - name: Build binary |
| 54 | + run: GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} make build |
| 55 | + - name: Upload release asset |
| 56 | + if: startsWith(github.ref, 'refs/tags/') |
| 57 | + run: | |
| 58 | + _filename=tx-submit-api-${{ env.RELEASE_TAG }}-${{ matrix.os }}-${{ matrix.arch }} |
| 59 | + if [[ ${{ matrix.os }} == windows ]]; then |
| 60 | + _filename=${_filename}.exe |
| 61 | + fi |
| 62 | + mv tx-submit-api ${_filename} |
| 63 | + curl \ |
| 64 | + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ |
| 65 | + -H "Content-Type: application/octet-stream" \ |
| 66 | + --data-binary @${_filename} \ |
| 67 | + https://uploads.github.com/repos/${{ github.repository_owner }}/tx-submit-api/releases/${{ needs.create-draft-release.outputs.RELEASE_ID }}/assets?name=${_filename} |
| 68 | +
|
| 69 | + build-images: |
| 70 | + runs-on: ubuntu-latest |
| 71 | + needs: [create-draft-release] |
| 72 | + steps: |
| 73 | + - run: "echo \"RELEASE_TAG=${GITHUB_REF#refs/tags/}\" >> $GITHUB_ENV" |
| 74 | + - uses: actions/checkout@v3 |
| 75 | + - name: Set up QEMU |
| 76 | + uses: docker/setup-qemu-action@v2 |
| 77 | + - name: Set up Docker Buildx |
| 78 | + uses: docker/setup-buildx-action@v2 |
| 79 | + - name: Login to Docker Hub |
| 80 | + uses: docker/login-action@v2 |
| 81 | + with: |
| 82 | + username: blinklabs |
| 83 | + password: ${{ secrets.DOCKER_PASSWORD }} # uses token |
| 84 | + - name: Login to GHCR |
| 85 | + uses: docker/login-action@v2 |
| 86 | + with: |
| 87 | + username: ${{ github.repository_owner }} |
| 88 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 89 | + registry: ghcr.io |
| 90 | + - id: meta |
| 91 | + uses: docker/metadata-action@v4 |
| 92 | + with: |
| 93 | + images: | |
| 94 | + blinklabs/tx-submit-api |
| 95 | + ghcr.io/${{ github.repository }} |
| 96 | + tags: | |
| 97 | + # Only version, no revision |
| 98 | + type=match,pattern=v(.*)-(.*),group=1 |
| 99 | + # branch |
| 100 | + type=ref,event=branch |
| 101 | + # semver |
| 102 | + type=semver,pattern={{version}} |
| 103 | + - name: Build images |
| 104 | + uses: docker/build-push-action@v3 |
| 105 | + with: |
| 106 | + outputs: "type=registry,push=true" |
| 107 | + platforms: linux/amd64,linux/arm64 |
| 108 | + tags: ${{ steps.meta.outputs.tags }} |
| 109 | + labels: ${{ steps.meta.outputs.labels }} |
| 110 | + # Update Docker Hub from README |
| 111 | + - name: Docker Hub Description |
| 112 | + uses: peter-evans/dockerhub-description@v3 |
| 113 | + with: |
| 114 | + username: blinklabs |
| 115 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 116 | + repository: blinklabs/tx-submit-api |
| 117 | + readme-filepath: ./README.md |
| 118 | + short-description: "A Go implementation of the Cardano Submit API service" |
| 119 | + |
| 120 | + finalize-release: |
| 121 | + runs-on: ubuntu-latest |
| 122 | + needs: [create-draft-release, build-binaries, build-images] |
| 123 | + steps: |
| 124 | + - uses: actions/github-script@v6 |
| 125 | + if: startsWith(github.ref, 'refs/tags/ |
0 commit comments