From b268d03e30dd07741ab90c758ee40eed3cd8f5ad Mon Sep 17 00:00:00 2001 From: lwnmengjing Date: Tue, 12 Jul 2022 11:54:24 +0800 Subject: [PATCH] :green_heart: update workflow --- .github/workflows/dev-lwx.yml | 60 ----------------------------------- .github/workflows/go.yml | 34 ++++++++++---------- Makefile | 6 ++-- 3 files changed, 21 insertions(+), 79 deletions(-) delete mode 100644 .github/workflows/dev-lwx.yml diff --git a/.github/workflows/dev-lwx.yml b/.github/workflows/dev-lwx.yml deleted file mode 100644 index b62a4c6..0000000 --- a/.github/workflows/dev-lwx.yml +++ /dev/null @@ -1,60 +0,0 @@ -name: build - -on: - push: - branches: [ dev-lwx ] - pull_request: - branches: [ dev-lwx ] - -jobs: - build: - name: Build - runs-on: ubuntu-latest - steps: - - name: Set up Go 1.15 - uses: actions/setup-go@v1 - with: - go-version: 1.15 - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - name: Get dependencies - run: | - go get -v -t -d ./... - if [ -f Gopkg.toml ]; then - curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh - dep ensure - fi - - name: Build - run: | - CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -a -installsuffix cgo -o go-admin . - mv go-admin ./scripts - - - uses: Azure/docker-login@v1 - with: - login-server: registry.cn-shanghai.aliyuncs.com - username: ${{ secrets.REGISTRY_USERNAME }} - password: ${{ secrets.REGISTRY_PASSWORD }} - - run: | - docker build ./scripts -t registry.cn-shanghai.aliyuncs.com/go-admin-team/go-admin:${{ github.sha }} - docker push registry.cn-shanghai.aliyuncs.com/go-admin-team/go-admin:${{ github.sha }} - - uses: Azure/k8s-set-context@v1 - with: - kubeconfig: ${{ secrets.KUBE_CONFIG }} - - - uses: Azure/k8s-create-secret@v1 - with: - namespace: 'go-admin' - container-registry-url: registry.cn-shanghai.aliyuncs.com - container-registry-username: ${{ secrets.REGISTRY_USERNAME }} - container-registry-password: ${{ secrets.REGISTRY_PASSWORD }} - secret-name: aliyuncs-k8s-secret - - - uses: Azure/k8s-deploy@v1 - with: - namespace: 'go-admin' - manifests: 'scripts/k8s/deploy.yml' - images: 'registry.cn-shanghai.aliyuncs.com/go-admin-team/go-admin:${{ github.sha }}' - imagepullsecrets: 'aliyuncs-k8s-secret' - kubectl-version: 'latest' diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index bf741c0..123e1eb 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -16,29 +16,23 @@ jobs: runs-on: ubuntu-latest steps: - - name: Set up Go 1.14 - uses: actions/setup-go@v1 + - name: Set up Go 1.15 + uses: actions/setup-go@v3 with: - go-version: 1.14 + go-version: 1.15 id: go - name: Check out code into the Go module directory - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Get dependencies - run: | - go get -v -t -d ./... - if [ -f Gopkg.toml ]; then - curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh - dep ensure - fi + run: go mod tidy - name: Build - run: | - ref=${{ github.ref }} - CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -a -installsuffix cgo -o go-admin . + run: make build - name: Log in to the Container registry - uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + uses: docker/login-action@v2 + if: startsWith(${{github.ref}}, 'refs/tags/') with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} @@ -46,12 +40,20 @@ jobs: - name: Extract metadata (tags, labels) for Docker id: meta - uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + if: startsWith(${{github.ref}}, 'refs/tags/') + uses: docker/metadata-action@v4 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + flavor: | + latest=auto + tags: | + type=schedule + type=ref,event=tag + type=sha,prefix=,format=long,enable=true,priority=100 - name: Build and push Docker image - uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + uses: docker/build-push-action@v3 + if: startsWith(${{github.ref}}, 'refs/tags/') with: context: . file: scripts/Dockerfile diff --git a/Makefile b/Makefile index 24509c9..135c7e7 100644 --- a/Makefile +++ b/Makefile @@ -2,11 +2,11 @@ PROJECT:=go-admin .PHONY: build build: - CGO_ENABLED=0 go build -o go-admin main.go + CGO_ENABLED=0 go build -ldflags="-w -s" -a -installsuffix -o go-admin . build-linux: - env GOOS=linux GOARCH=amd64 go build + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -a -installsuffix -o go-admin . build-sqlite: - go build -tags sqlite3 -o go-admin main.go + go build -tags sqlite3 -ldflags="-w -s" -a -installsuffix -o go-admin . #.PHONY: test #test: # go test -v ./... -cover