Repository: goreleaser/goreleaser
Pull request #1784 (2020-09-02 13:34:48)

feat: support ghcr.io
refs #1783

vercel[bot]: This pull request is being automatically deployed with Vercel ([learn more](https://vercel.link/github-learn-more)).  
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: [https://vercel.com/goreleaser/goreleaser/cgujof6kr](https://vercel.com/goreleaser/goreleaser/cgujof6kr)  
✅ Preview: *In Progress*


codecov[bot]: # [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1784?src=pr&el=h1) Report
> Merging [#1784](https://codecov.io/gh/goreleaser/goreleaser/pull/1784?src=pr&el=desc) into [master](https://codecov.io/gh/goreleaser/goreleaser/commit/e014ad0ae88480406206c7758f3607168b45ced9?el=desc) will **increase** coverage by `0.00%`.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/goreleaser/goreleaser/pull/1784/graphs/tree.svg?width=650&height=150&src=pr&token=3bJvv6b7hN)](https://codecov.io/gh/goreleaser/goreleaser/pull/1784?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master    #1784   +/-   ##
=======================================
  Coverage   82.54%   82.55%           
=======================================
  Files          72       72           
  Lines        4177     4179    +2     
=======================================
+ Hits         3448     3450    +2     
  Misses        608      608           
  Partials      121      121           
```


| [Impacted Files](https://codecov.io/gh/goreleaser/goreleaser/pull/1784?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pkg/config/config.go](https://codecov.io/gh/goreleaser/goreleaser/pull/1784/diff?src=pr&el=tree#diff-cGtnL2NvbmZpZy9jb25maWcuZ28=) | `94.44% <0.00%> (ø)` | |
| [internal/builders/golang/build.go](https://codecov.io/gh/goreleaser/goreleaser/pull/1784/diff?src=pr&el=tree#diff-aW50ZXJuYWwvYnVpbGRlcnMvZ29sYW5nL2J1aWxkLmdv) | `94.66% <0.00%> (+0.07%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1784?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1784?src=pr&el=footer). Last update [e014ad0...f1196eb](https://codecov.io/gh/goreleaser/goreleaser/pull/1784?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index e77810ff..37ddee2c 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -58,8 +58,10 @@ jobs:
         env:
           DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
           DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
+          GITHUB_TOKEN: ${{ secrets.GH_PAT }}
         run: |
           echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin
+          echo "${GITHUB_TOKEN}" | docker login ghcr.io --username $GITHUB_ACTOR --password-stdin
       -
         name: Snapcraft Login
         if: success() && startsWith(github.ref, 'refs/tags/v')
diff --git a/.goreleaser.yml b/.goreleaser.yml
index d34b870a..e87dfbf7 100644
--- a/.goreleaser.yml
+++ b/.goreleaser.yml
@@ -35,8 +35,11 @@ changelog:
 dockers:
 - image_templates:
   - 'goreleaser/goreleaser:{{ .Tag }}-cgo'
+  - 'ghcr.io/goreleaser/goreleaser:{{ .Tag }}-cgo'
   - 'goreleaser/goreleaser:v{{ .Major }}.{{ .Minor }}-cgo'
+  - 'ghcr.io/goreleaser/goreleaser:v{{ .Major }}.{{ .Minor }}-cgo'
   - 'goreleaser/goreleaser:latest-cgo'
+  - 'ghcr.io/goreleaser/goreleaser:latest-cgo'
   dockerfile: Dockerfile.cgo
   binaries:
   - goreleaser
@@ -50,8 +53,11 @@ dockers:
   - scripts/entrypoint.sh
 - image_templates:
   - 'goreleaser/goreleaser:{{ .Tag }}'
+  - 'ghcr.io/goreleaser/goreleaser:{{ .Tag }}'
   - 'goreleaser/goreleaser:v{{ .Major }}.{{ .Minor }}'
+  - 'ghcr.io/goreleaser/goreleaser:v{{ .Major }}.{{ .Minor }}'
   - 'goreleaser/goreleaser:latest'
+  - 'ghcr.io/goreleaser/goreleaser:latest'
   dockerfile: Dockerfile
   binaries:
   - goreleaser
diff --git a/internal/artifact/artifact.go b/internal/artifact/artifact.go
index 2883acf2..72539422 100644
--- a/internal/artifact/artifact.go
+++ b/internal/artifact/artifact.go
@@ -55,16 +55,13 @@ func (t Type) String() string {
 		return "Archive"
 	case UploadableFile:
 		return "File"
-	case UploadableBinary:
-	case Binary:
+	case UploadableBinary, Binary:
 		return "Binary"
 	case LinuxPackage:
 		return "Linux Package"
-	case DockerImage:
-	case PublishableDockerImage:
+	case PublishableDockerImage, DockerImage:
 		return "Docker Image"
-	case PublishableSnapcraft:
-	case Snapcraft:
+	case PublishableSnapcraft, Snapcraft:
 		return "Snap"
 	case Checksum:
 		return "Checksum"
@@ -72,8 +69,9 @@ func (t Type) String() string {
 		return "Signature"
 	case UploadableSourceArchive:
 		return "Source"
+	default:
+		return "unknown"
 	}
-	return "unknown"
 }
 
 // Artifact represents an artifact and its relevant info.
@@ -123,7 +121,7 @@ func (a Artifact) Checksum(algorithm string) (string, error) {
 	case "sha512":
 		h = sha512.New()
 	default:
-		return "", fmt.Errorf("invalid algorith: %s", algorithm)
+		return "", fmt.Errorf("invalid algorithm: %s", algorithm)
 	}
 	_, err = io.Copy(h, file)
 	if err != nil {
diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh
index dbcda536..d684b533 100644
--- a/scripts/entrypoint.sh
+++ b/scripts/entrypoint.sh
@@ -1,8 +1,8 @@
 #!/usr/bin/env bash
 
 if [ -n "$DOCKER_USERNAME" ] && [ -n "$DOCKER_PASSWORD" ]; then
-    echo "Login to the docker..."
-    echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin $DOCKER_REGISTRY
+	echo "Login to the docker..."
+	echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin "$DOCKER_REGISTRY"
 fi
 
 # Workaround for github actions when access to different repositories is needed.
@@ -11,12 +11,14 @@ fi
 # Access to different repositories is needed by brew for example.
 
 if [ -n "$GORELEASER_GITHUB_TOKEN" ] ; then
-  export GITHUB_TOKEN=$GORELEASER_GITHUB_TOKEN
+	export GITHUB_TOKEN=$GORELEASER_GITHUB_TOKEN
 fi
 
 if [ -n "$GITHUB_TOKEN" ]; then
-  # Log into GitHub package registry
-  echo $GITHUB_TOKEN | docker login docker.pkg.github.com -u docker --password-stdin
+	# Log into GitHub package registry
+	echo "$GITHUB_TOKEN" | docker login docker.pkg.github.com -u docker --password-stdin
+	echo "$GITHUB_TOKEN" | docker login ghcr.io -u docker --password-stdin
 fi
 
+# shellcheck disable=SC2068
 goreleaser $@


Test patch:
diff --git a/internal/artifact/artifact_test.go b/internal/artifact/artifact_test.go
index b452d94c..bf122cf9 100644
--- a/internal/artifact/artifact_test.go
+++ b/internal/artifact/artifact_test.go
@@ -198,7 +198,7 @@ func TestInvalidAlgorithm(t *testing.T) {
 		Path: f.Name(),
 	}
 	sum, err := artifact.Checksum("sha1ssss")
-	require.EqualError(t, err, `invalid algorith: sha1ssss`)
+	require.EqualError(t, err, `invalid algorithm: sha1ssss`)
 	require.Empty(t, sum)
 }