|
| 1 | +name: Build |
| 2 | + |
| 3 | +on: [push, pull_request] |
| 4 | + |
| 5 | +jobs: |
| 6 | + backend: |
| 7 | + name: Back-end |
| 8 | + runs-on: ubuntu-latest |
| 9 | + steps: |
| 10 | + - uses: actions/checkout@v3 |
| 11 | + - uses: actions/setup-go@v4 |
| 12 | + with: |
| 13 | + go-version: '1.23.6' |
| 14 | + cache-dependency-path: ./go.mod |
| 15 | + - run: go version |
| 16 | + - name: Build |
| 17 | + run: | |
| 18 | + go build -race -ldflags "-extldflags '-static'" |
| 19 | + working-directory: ./ |
| 20 | + |
| 21 | + linter: |
| 22 | + name: Go-Linter |
| 23 | + runs-on: ubuntu-latest |
| 24 | + needs: [ backend ] |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v3 |
| 27 | + - uses: actions/setup-go@v4 |
| 28 | + with: |
| 29 | + go-version: '1.23.6' |
| 30 | + cache: false |
| 31 | + |
| 32 | + # gen a dummy config file |
| 33 | + - run: touch dummy.yml |
| 34 | + |
| 35 | + - name: golangci-lint |
| 36 | + uses: golangci/golangci-lint-action@v3 |
| 37 | + with: |
| 38 | + version: latest |
| 39 | + args: --disable-all -c dummy.yml -E=gofumpt --max-same-issues=0 --timeout 5m --modules-download-mode=mod |
| 40 | + |
| 41 | + release-and-push: |
| 42 | + name: Release And Push |
| 43 | + runs-on: ubuntu-latest |
| 44 | + permissions: |
| 45 | + contents: write |
| 46 | + issues: write |
| 47 | + if: github.repository == 'casibase/chainserver' && github.event_name == 'push' |
| 48 | + needs: [ backend, linter ] |
| 49 | + steps: |
| 50 | + - name: Checkout |
| 51 | + uses: actions/checkout@v3 |
| 52 | + with: |
| 53 | + fetch-depth: -1 |
| 54 | + - name: Setup Node.js |
| 55 | + uses: actions/setup-node@v3 |
| 56 | + with: |
| 57 | + node-version: 20 |
| 58 | + |
| 59 | + - name: Fetch Previous version |
| 60 | + id: get-previous-tag |
| 61 | + uses: actions-ecosystem/action-get-latest-tag@v1.6.0 |
| 62 | + |
| 63 | + - name: Release |
| 64 | + run: yarn global add semantic-release@17.4.4 && semantic-release |
| 65 | + env: |
| 66 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 67 | + |
| 68 | + - name: Fetch Current version |
| 69 | + id: get-current-tag |
| 70 | + uses: actions-ecosystem/action-get-latest-tag@v1.6.0 |
| 71 | + |
| 72 | + - name: Decide Should_Push Or Not |
| 73 | + id: should_push |
| 74 | + run: | |
| 75 | + old_version=${{steps.get-previous-tag.outputs.tag}} |
| 76 | + new_version=${{steps.get-current-tag.outputs.tag }} |
| 77 | +
|
| 78 | + old_array=(${old_version//\./ }) |
| 79 | + new_array=(${new_version//\./ }) |
| 80 | +
|
| 81 | + if [ ${old_array[0]} != ${new_array[0]} ] |
| 82 | + then |
| 83 | + echo ::set-output name=push::'true' |
| 84 | + elif [ ${old_array[1]} != ${new_array[1]} ] |
| 85 | + then |
| 86 | + echo ::set-output name=push::'true' |
| 87 | + else |
| 88 | + echo ::set-output name=push::'false' |
| 89 | + fi |
| 90 | +
|
| 91 | + - name: Set up QEMU |
| 92 | + uses: docker/setup-qemu-action@v2 |
| 93 | + |
| 94 | + - name: Set up buildx |
| 95 | + id: buildx |
| 96 | + uses: docker/setup-buildx-action@v2 |
| 97 | + with: |
| 98 | + version: latest |
| 99 | + |
| 100 | + - name: Log in to Docker Hub |
| 101 | + uses: docker/login-action@v1 |
| 102 | + if: github.repository == 'casibase/chainserver' && github.event_name == 'push' && steps.should_push.outputs.push=='true' |
| 103 | + with: |
| 104 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 105 | + password: ${{ secrets.DOCKERHUB_PASSWORD }} |
| 106 | + |
| 107 | + - name: Push to Docker Hub |
| 108 | + uses: docker/build-push-action@v3 |
| 109 | + if: github.repository == 'casibase/chainserver' && github.event_name == 'push' && steps.should_push.outputs.push=='true' |
| 110 | + with: |
| 111 | + context: . |
| 112 | + target: STANDARD |
| 113 | + platforms: linux/amd64 |
| 114 | + push: true |
| 115 | + tags: casbin/chainserver:${{steps.get-current-tag.outputs.tag }},casbin/chainserver:latest |
0 commit comments