github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/.github/workflows/build.yml (about) 1 name: Build 2 3 on: 4 pull_request: 5 branches: 6 - master 7 types: [opened, synchronize] 8 paths-ignore: 9 - 'scripts/**' 10 - '**/*.md' 11 push: 12 # Build for the master branch. 13 branches: 14 - master 15 release: 16 # Publish released commit as Docker `latest` and `git_revision` images. 17 types: 18 - published 19 workflow_dispatch: 20 inputs: 21 ref: 22 description: 'Ref to build CLI for Ubuntu and Windows Server Core [default: latest master; examples: v0.92.0, 0a4ff9d3e4a9ab432fd5812eb18c98e03b5a7432]' 23 required: false 24 default: '' 25 push_image: 26 description: 'Push images to DockerHub [default: false; examples: true, false]' 27 required: false 28 default: 'false' 29 use_latest_tag: 30 description: 'Use `latest` tag while pushing images to DockerHub (applied to Ubuntu image only) [default: false; examples: true, false]' 31 required: false 32 default: 'false' 33 34 jobs: 35 build_cli: 36 name: Build CLI 37 runs-on: ${{matrix.os.name}} 38 strategy: 39 matrix: 40 os: [{ name: ubuntu-22.04, bin-name: linux }, { name: windows-2022, bin-name: windows }, { name: macos-12, bin-name: darwin }] 41 arch: [amd64, arm64] 42 exclude: 43 - os: { name: windows-2022, bin-name: windows } 44 arch: 'arm64' 45 46 steps: 47 - uses: actions/checkout@v4 48 with: 49 ref: ${{ github.event.inputs.ref }} 50 # Allows to fetch all history for all branches and tags. Need this for proper versioning. 51 fetch-depth: 0 52 53 - name: Set up Go 54 uses: actions/setup-go@v5 55 with: 56 go-version: '1.22' 57 58 - name: Build CLI 59 run: make build 60 env: 61 GOARCH: ${{ matrix.arch }} 62 63 - name: Rename CLI binary 64 run: mv ./bin/neo-go* ./bin/neo-go-${{ matrix.os.bin-name }}-${{ matrix.arch }}${{ (matrix.os.bin-name == 'windows' && '.exe') || '' }} 65 66 - name: Upload artifact 67 uses: actions/upload-artifact@v4 68 with: 69 name: neo-go-${{ matrix.os.bin-name }}-${{ matrix.arch }} 70 path: ./bin/neo-go* 71 if-no-files-found: error 72 73 - name: Attach binary to the release as an asset 74 if: ${{ github.event_name == 'release' }} 75 run: gh release upload ${{ github.event.release.tag_name }} ./bin/neo-go-${{ matrix.os.bin-name }}-${{ matrix.arch }}${{ (matrix.os.bin-name == 'windows' && '.exe') || '' }} 76 env: 77 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 78 79 build_image: 80 needs: build_cli 81 name: Build and push docker image 82 runs-on: ubuntu-22.04 83 84 steps: 85 - uses: actions/checkout@v4 86 with: 87 ref: ${{ github.event.inputs.ref }} 88 fetch-depth: 0 89 90 - name: Set up QEMU 91 uses: docker/setup-qemu-action@v3 92 93 - name: Set up Docker Buildx 94 uses: docker/setup-buildx-action@v3 95 96 - name: Login to DockerHub 97 if: ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_image == 'true') }} 98 uses: docker/login-action@v3 99 with: 100 username: ${{ secrets.DOCKERHUB_USERNAME }} 101 password: ${{ secrets.DOCKERHUB_PASSWORD }} 102 103 - name: Set vars 104 id: setvars 105 run: make gh-docker-vars >> $GITHUB_OUTPUT 106 107 - name: Set latest tag 108 id: setlatest 109 if: ${{ (github.event_name == 'release' && github.event.release.target_commitish == 'master') || (github.event_name == 'workflow_dispatch' && github.event.inputs.use_latest_tag == 'true') }} 110 run: echo "latest=,${{ steps.setvars.outputs.repo }}:latest" >> $GITHUB_OUTPUT 111 112 - name: Build and push 113 uses: docker/build-push-action@v5 114 with: 115 context: . 116 push: ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_image == 'true') }} 117 platforms: linux/amd64,linux/arm64 118 build-args: | 119 REPO=github.com/${{ github.repository }} 120 VERSION=${{ steps.setvars.outputs.version }} 121 tags: ${{ steps.setvars.outputs.repo }}:${{ steps.setvars.outputs.version }}${{ steps.setvars.outputs.suffix }}${{ steps.setlatest.outputs.latest }} 122 123 build_image_wsc: 124 needs: build_cli 125 name: Build and push docker image (Windows Server Core) 126 runs-on: windows-2022 127 128 steps: 129 - uses: actions/checkout@v4 130 with: 131 ref: ${{ github.event.inputs.ref }} 132 fetch-depth: 0 133 134 # For proper `deps` make target execution. 135 - name: Set up Go 136 uses: actions/setup-go@v5 137 with: 138 go-version: '1.22' 139 140 - name: Login to DockerHub 141 if: ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_image == 'true') }} 142 uses: docker/login-action@v3 143 with: 144 username: ${{ secrets.DOCKERHUB_USERNAME }} 145 password: ${{ secrets.DOCKERHUB_PASSWORD }} 146 147 - name: Build Docker image 148 run: make image 149 150 - name: Push image to registry 151 if: ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_image == 'true') }} 152 run: make image-push