From 091f27f2bdb0bce302ea9b341dc7416bef62bffb Mon Sep 17 00:00:00 2001 From: TP Honey Date: Tue, 29 Nov 2022 16:44:33 +0000 Subject: [PATCH] (fix) add better windows support and move to harness.drone.io --- .drone.yml | 287 ++++++++++++++++++ .gitignore | 1 - cmd/drone-github-release/main.go | 4 +- docker/Dockerfile.linux.arm | 9 - docker/Dockerfile.windows.1909 | 10 - docker/Dockerfile.windows.2004 | 10 - ...ndows.1903 => Dockerfile.windows.ltsc2022} | 2 +- docker/manifest.tmpl | 23 +- plugin/utils.go | 5 +- 9 files changed, 296 insertions(+), 55 deletions(-) create mode 100644 .drone.yml delete mode 100644 docker/Dockerfile.linux.arm delete mode 100644 docker/Dockerfile.windows.1909 delete mode 100644 docker/Dockerfile.windows.2004 rename docker/{Dockerfile.windows.1903 => Dockerfile.windows.ltsc2022} (75%) diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 000000000..4a80f2f66 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,287 @@ +kind: pipeline +type: vm +name: testing +platform: + os: linux + arch: amd64 +pool: + use: ubuntu + +steps: + - name: static check + image: golang:1.19 + pull: always + commands: + - go get honnef.co/go/tools/cmd/staticcheck + - go run honnef.co/go/tools/cmd/staticcheck ./... + volumes: + - name: gopath + path: "/go" + - name: lint + image: golang:1.19 + pull: always + commands: + - go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest + - golangci-lint version + - golangci-lint run + volumes: + - name: gopath + path: "/go" + - name: test + image: golang:1.19 + commands: + - go test -cover ./... + volumes: + - name: gopath + path: "/go" +volumes: + - name: gopath + temp: {} +trigger: + ref: + - refs/heads/master + - refs/tags/** + - refs/pull/** + +--- +kind: pipeline +type: vm +name: linux-amd64 +platform: + os: linux + arch: amd64 +pool: + use: ubuntu + +steps: + - name: environment + image: golang:1.19 + pull: always + environment: + CGO_ENABLED: "0" + commands: + - go version + - go env + - name: build + image: golang:1.19 + environment: + CGO_ENABLED: "0" + commands: + - go build -v -ldflags "-X main.version=" -a -tags netgo -o release/linux/amd64/drone-github-release ./cmd/drone-github-release + - name: executable + image: golang:1.19 + commands: + - ./release/linux/amd64/drone-github-release --help + - name: docker + image: plugins/docker + settings: + dockerfile: docker/Dockerfile.linux.amd64 + repo: plugins/github-release + username: + from_secret: docker_username + password: + from_secret: docker_password + auto_tag: true + auto_tag_suffix: linux-amd64 + when: + ref: + - refs/heads/master + - refs/tags/** +depends_on: + - testing +trigger: + ref: + - refs/heads/master + - refs/tags/** + - refs/pull/** + +--- +kind: pipeline +type: vm +name: linux-arm64 +platform: + os: linux + arch: amd64 +pool: + use: ubuntu_arm64 + +steps: + - name: environment + image: golang:1.19 + pull: always + environment: + CGO_ENABLED: "0" + commands: + - go version + - go env + - name: build + image: golang:1.19 + environment: + CGO_ENABLED: "0" + commands: + - go build -v -ldflags "-X main.version=" -a -tags netgo -o release/linux/arm64/drone-github-release ./cmd/drone-github-release + - name: executable + image: golang:1.19 + commands: + - ./release/linux/arm64/drone-github-release --help + - name: docker + image: plugins/docker + settings: + dockerfile: docker/Dockerfile.linux.arm64 + repo: plugins/github-release + username: + from_secret: docker_username + password: + from_secret: docker_password + auto_tag: true + auto_tag_suffix: linux-arm64 + when: + ref: + - refs/heads/master + - refs/tags/** +depends_on: + - testing +trigger: + ref: + - refs/heads/master + - refs/tags/** + - refs/pull/** + +--- +kind: pipeline +type: vm +name: windows-1809 +platform: + os: windows + arch: amd64 +pool: + use: windows + +steps: + - name: environment + image: golang:1.19 + pull: always + environment: + CGO_ENABLED: "0" + commands: + - go version + - go env + - name: build + image: golang:1.19 + environment: + CGO_ENABLED: "0" + commands: + - go build -v -ldflags "-X main.version=" -a -tags netgo -o release/windows/amd64/drone-github-release.exe ./cmd/drone-github-release + - name: executable + image: golang:1.19 + commands: + - ./release/windows/amd64/drone-github-release.exe --help + - name: docker + image: plugins/docker + settings: + dockerfile: docker/Dockerfile.windows.1809 + repo: plugins/github-release + username: + from_secret: docker_username + password: + from_secret: docker_password + auto_tag: true + auto_tag_suffix: windows-1809-amd64 + daemon_off: true + purge: false + when: + ref: + - refs/heads/master + - refs/tags/** +depends_on: + - testing +trigger: + ref: + - refs/heads/master + - refs/tags/** + - refs/pull/** + +--- +kind: pipeline +type: vm +name: windows-ltsc2022 +platform: + os: windows + arch: amd64 +pool: + use: windows-2022 + +steps: + - name: environment + image: golang:1.19 + pull: always + environment: + CGO_ENABLED: "0" + commands: + - go version + - go env + - name: build + image: golang:1.19 + environment: + CGO_ENABLED: "0" + commands: + - go build -v -ldflags "-X main.version=" -a -tags netgo -o release/windows/amd64/drone-github-release.exe ./cmd/drone-github-release + - name: executable + image: golang:1.19 + commands: + - ./release/windows/amd64/drone-github-release.exe --help + - name: docker + image: plugins/docker + settings: + dockerfile: docker/Dockerfile.windows.ltsc2022 + repo: plugins/github-release + username: + from_secret: docker_username + password: + from_secret: docker_password + auto_tag: true + auto_tag_suffix: windows-ltsc2022-amd64 + daemon_off: true + purge: false + when: + ref: + - refs/heads/master + - refs/tags/** +depends_on: + - testing +trigger: + ref: + - refs/heads/master + - refs/tags/** + - refs/pull/** + +--- +kind: pipeline +type: vm +name: manifest +platform: + os: linux + arch: amd64 +pool: + use: ubuntu + +steps: + - name: manifest + image: plugins/manifest + settings: + auto_tag: "true" + username: + from_secret: docker_username + password: + from_secret: docker_password + spec: docker/manifest.tmpl + ignore_missing: true +depends_on: + - linux-amd64 + - linux-arm64 + - windows-1809 + - windows-ltsc2022 +trigger: + ref: + - refs/heads/master + - refs/tags/** diff --git a/.gitignore b/.gitignore index 182b69714..9635a6d3d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,3 @@ /drone-github-release* coverage.out -.drone.yml diff --git a/cmd/drone-github-release/main.go b/cmd/drone-github-release/main.go index c415bc7af..3b4d2a1f3 100644 --- a/cmd/drone-github-release/main.go +++ b/cmd/drone-github-release/main.go @@ -10,11 +10,11 @@ package main import ( "os" + "github.com/drone-plugins/drone-github-release/plugin" "github.com/drone-plugins/drone-plugin-lib/errors" "github.com/drone-plugins/drone-plugin-lib/urfave" "github.com/joho/godotenv" "github.com/urfave/cli/v2" - "github.com/drone-plugins/drone-github-release/plugin" ) var version = "unknown" @@ -23,7 +23,7 @@ func main() { settings := &plugin.Settings{} if _, err := os.Stat("/run/drone/env"); err == nil { - godotenv.Overload("/run/drone/env") + _ = godotenv.Overload("/run/drone/env") } app := &cli.App{ diff --git a/docker/Dockerfile.linux.arm b/docker/Dockerfile.linux.arm deleted file mode 100644 index 7271602f2..000000000 --- a/docker/Dockerfile.linux.arm +++ /dev/null @@ -1,9 +0,0 @@ -FROM plugins/base:multiarch@sha256:61f243abf3f1ea407faae94ab4698b51c4cc38b9e734e30ae16e8ec7e6250f6b - -LABEL maintainer="Drone.IO Community " \ - org.label-schema.name="Drone GitHub Release" \ - org.label-schema.vendor="Drone.IO Community" \ - org.label-schema.schema-version="1.0" - -ADD release/linux/arm/drone-github-release /bin/ -ENTRYPOINT [ "/bin/drone-github-release" ] diff --git a/docker/Dockerfile.windows.1909 b/docker/Dockerfile.windows.1909 deleted file mode 100644 index ec4c92377..000000000 --- a/docker/Dockerfile.windows.1909 +++ /dev/null @@ -1,10 +0,0 @@ -# escape=` -FROM plugins/base:windows-1909-amd64@sha256:fc1978bbe23e889dd7c5729cc8c44c2447a3ad00b539872167fe09ea43a136c7 - -LABEL maintainer="Drone.IO Community " ` - org.label-schema.name="Drone GitHub Release" ` - org.label-schema.vendor="Drone.IO Community" ` - org.label-schema.schema-version="1.0" - -ADD release/windows/amd64/drone-github-release.exe C:/bin/drone-github-release.exe -ENTRYPOINT [ "C:\\bin\\drone-github-release.exe" ] diff --git a/docker/Dockerfile.windows.2004 b/docker/Dockerfile.windows.2004 deleted file mode 100644 index 8d737a4a7..000000000 --- a/docker/Dockerfile.windows.2004 +++ /dev/null @@ -1,10 +0,0 @@ -# escape=` -FROM plugins/base:windows-2004-amd64 - -LABEL maintainer="Drone.IO Community " ` - org.label-schema.name="Drone GitHub Release" ` - org.label-schema.vendor="Drone.IO Community" ` - org.label-schema.schema-version="1.0" - -ADD release/windows/amd64/drone-github-release.exe C:/bin/drone-github-release.exe -ENTRYPOINT [ "C:\\bin\\drone-github-release.exe" ] diff --git a/docker/Dockerfile.windows.1903 b/docker/Dockerfile.windows.ltsc2022 similarity index 75% rename from docker/Dockerfile.windows.1903 rename to docker/Dockerfile.windows.ltsc2022 index a6950f43a..f4a023d35 100644 --- a/docker/Dockerfile.windows.1903 +++ b/docker/Dockerfile.windows.ltsc2022 @@ -1,5 +1,5 @@ # escape=` -FROM plugins/base:windows-1903-amd64@sha256:338cdba56a7f30d721b6567d382b95465642993f85564cb385e65b2f3f84352c +FROM plugins/base:windows-ltsc2022-amd64@sha256:0f90d5bceb432f1ee6f93cf44eed6a38c322834edd55df8a6648c9e6f15131f4 LABEL maintainer="Drone.IO Community " ` org.label-schema.name="Drone GitHub Release" ` diff --git a/docker/manifest.tmpl b/docker/manifest.tmpl index 6356f6674..821c36ab6 100644 --- a/docker/manifest.tmpl +++ b/docker/manifest.tmpl @@ -17,28 +17,13 @@ manifests: architecture: arm64 os: linux variant: v8 - - image: plugins/github-release:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm - platform: - architecture: arm - os: linux - variant: v7 - - image: plugins/github-release:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-2004-amd64 - platform: - architecture: amd64 - os: windows - version: 2004 - - image: plugins/github-release:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1909-amd64 - platform: - architecture: amd64 - os: windows - version: 1909 - - image: plugins/github-release:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1903-amd64 + - image: plugins/github-release:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1809-amd64 platform: architecture: amd64 os: windows - version: 1903 - - image: plugins/github-release:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1809-amd64 + version: 1809 + - image: plugins/github-release:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-ltsc2022-amd64 platform: architecture: amd64 os: windows - version: 1809 + version: ltsc2022 \ No newline at end of file diff --git a/plugin/utils.go b/plugin/utils.go index 9d680af4a..cd2b4e3c0 100644 --- a/plugin/utils.go +++ b/plugin/utils.go @@ -14,7 +14,6 @@ import ( "hash/adler32" "hash/crc32" "io" - "io/ioutil" "os" "path/filepath" "strconv" @@ -40,7 +39,7 @@ func readStringOrFile(input string) (string, error) { } else if err != nil { return "", err } - result, err := ioutil.ReadFile(input) + result, err := os.ReadFile(input) if err != nil { return "", err } @@ -48,7 +47,7 @@ func readStringOrFile(input string) (string, error) { } func checksum(r io.Reader, method string) (string, error) { - b, err := ioutil.ReadAll(r) + b, err := io.ReadAll(r) if err != nil { return "", err