diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..f6861fe --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,53 @@ +name: Build + +on: + workflow_dispatch: + push: + branches: [master] + pull_request: + branches: [master] + workflow_call: + +jobs: + build: + name: build + runs-on: ubuntu-latest + steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: "1.21" + cache: false + + - 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 + go mod tidy + + - name: Verify dependencies + run: go mod verify + + - name: lint + uses: golangci/golangci-lint-action@v4 + with: + # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. + version: v1.55 + args: --skip-files .*_test.go --enable wsl --enable misspell --out-format=colored-line-number --timeout 180s + + - name: Build + run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v cmd/arcade/arcade.go + + - name: Test + run: go test -v ./... + + - uses: actions/upload-artifact@v3 + with: + name: build + path: arcade diff --git a/.github/workflows/docker-push.yml b/.github/workflows/docker-push.yml new file mode 100644 index 0000000..0bc3c9f --- /dev/null +++ b/.github/workflows/docker-push.yml @@ -0,0 +1,67 @@ +name: Docker +on: + workflow_call: + +env: + CONTAINER_REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + push: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: actions/download-artifact@v3 + with: + name: build + + - name: Add executable permissions + run: | + chmod +x arcade + + - name: Set release info + run: | + event_type=${{ github.event.action }} + release_version=$(echo ${{ github.ref_name }} | sed 's/v//g' | sed 's/+/-/g') + echo "RELEASE_VERSION=$release_version" >> $GITHUB_ENV + if [[ $event_type == "released" ]]; then + echo "TAGS=${{ env.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:$release_version,${{ env.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_ENV + else + echo "TAGS=${{ env.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:$release_version" >> $GITHUB_ENV + fi + + - name: Login + uses: docker/login-action@v3 + with: + registry: ${{ env.CONTAINER_REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up docker context for buildx + id: buildx-context + run: | + docker context create builders + + - name: Set up docker buildx + uses: docker/setup-buildx-action@v2 + with: + endpoint: builders + driver-opts: | + image=moby/buildkit:master + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ env.TAGS }} + labels: | + org.opencontainers.image.source=https://github.com/${{ env.IMAGE_NAME }} + org.opencontainers.image.version=${{ env.RELEASE_VERSION }} diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml deleted file mode 100644 index 6d35c66..0000000 --- a/.github/workflows/go.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: Go - -on: - workflow_dispatch: - push: - branches: [master] - pull_request: - branches: [master] - -jobs: - build: - name: Build - runs-on: ubuntu-latest - steps: - - name: Set up Go 1.x - uses: actions/setup-go@v4 - with: - go-version: ^1.21 - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v4 - - - name: Get dependencies - run: make setup - - - name: Test - run: make test - - - name: Build - run: make build - - golangci: - name: Lint - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: golangci-lint - uses: golangci/golangci-lint-action@v2 - with: - # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v1.55 - - args: --skip-files .*_test.go --enable wsl --enable misspell --timeout 180s diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3d49f18..de36b91 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,32 +1,13 @@ name: Release -on: - workflow_dispatch: - inputs: - version: - type: string - description: version to tag image -jobs: +on: release: - runs-on: ubuntu-latest - env: - VERSION: ${{ github.event.inputs.version }} - steps: - - name: Setup - checkout - uses: actions/checkout@v4 + types: [prereleased, released] - - name: Set up Go 1.x - uses: actions/setup-go@v4 - with: - go-version: ^1.21 - id: go - - - name: Login to DockerHub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} +jobs: + build: + uses: ./.github/workflows/build.yml - - name: docker - shell: bash - run: docker/docker-build.sh -v ${VERSION} + docker: + needs: build + uses: ./.github/workflows/docker-push.yml