From b96734a00162c5caf755df9ab7ef65f0533b4333 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Sun, 26 Jul 2020 21:17:29 +0100 Subject: [PATCH 1/7] Specify GOOS in Dockerfile Enable switching of target operating system. --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index a678bef..25f9a1a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,8 @@ FROM golang:1.14-alpine USER nobody:nogroup +ARG GOOS + ENV CGO_ENABLED=0 XDG_CACHE_HOME=/tmp/.cache WORKDIR /go/src/go-mailin8 From 5ed9bcfc8b3b9e71fcbd2277983ea3d72c3bdabc Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Sun, 26 Jul 2020 21:19:45 +0100 Subject: [PATCH 2/7] Add Windows build to Makefile --- Makefile | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 7f9e4db..98a21d4 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,10 @@ -build: +build-linux: docker build . -t go-mailin8 - docker run --rm --entrypoint cat go-mailin8 /go/bin/go-mailin8 > go-mailin8 - chmod u+x go-mailin8 + docker run --rm --entrypoint cat go-mailin8 /go/bin/go-mailin8 > go-mailin8_linux_amd64 + chmod u+x go-mailin8_linux_amd64 -.PHONY: build +build-windows: + docker build --build-arg GOOS=windows . -t go-mailin8 + docker run --rm --entrypoint cat go-mailin8 /go/bin/windows_amd64/go-mailin8.exe > go-mailin8.exe + +.PHONY: build-linux build-windows From bb9adb70756ef4f7445472f7a83d3df015fb3d90 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Sun, 26 Jul 2020 21:19:55 +0100 Subject: [PATCH 3/7] Update .gitignore to ignore binaries --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 483f81f..dfb68a7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -/go-mailin8 +# Compiled binaries +/go-mailin8_linux_amd64 +/go-mailin8.exe From 017c4c4bc3f5646ce190e2063ab88dcc8200aba8 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Sun, 26 Jul 2020 21:25:28 +0100 Subject: [PATCH 4/7] Add release workflow Initiated by pushing a version tag. --- .github/workflows/release.yml | 70 +++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..d8c57ab --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,70 @@ +on: + push: + tags: + - 'v*' + +name: Build and release binary + +jobs: + build: + name: Build and release binary + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Build Linux binary + run: | + make build-linux + + - name: Build Windows binary + run: | + make build-windows + + - name: Calculate SHA256 + run: | + sha256sum go-mailin8_linux_amd64 go-mailin8.exe > SHA256SUMS + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: ${{ github.ref }} + draft: true + prerelease: false + + - name: Upload Linux binary to GitHub + id: upload-linux-binary + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./go-mailin8_linux_amd64 + asset_name: go-mailin8_linux_amd64 + asset_content_type: application/octet-stream + + - name: Upload Windows binary to GitHub + id: upload-windows-binary + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./go-mailin8.exe + asset_name: go-mailin8.exe + asset_content_type: application/octet-stream + + - name: Upload SHA256SUMS to GitHub + id: upload-sha256sums + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./SHA256SUMS + asset_name: SHA256SUMS + asset_content_type: text/plain From bbce04d1be9f23c2df3fdc345efe40dbdb01cfd1 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Sun, 26 Jul 2020 21:26:01 +0100 Subject: [PATCH 5/7] Update README With details of Windows build. --- README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3bc3aaa..04821d1 100644 --- a/README.md +++ b/README.md @@ -20,19 +20,27 @@ email service. ## Build +### Download + +If you don't want to build from source, [Linux and Windows +binaries](https://github.com/StevenMaude/go-mailin8/releases) are built +from tagged versions via GitHub Actions. + ### With Go installed -`go build` +`go build` or `go install` ### With Docker installed -`make` +* `make build-linux` (for a Linux build) +* `make build-windows` (for a Windows build) ## Usage 1. Send, or get an email sent to a [nada](https://getnada.com) email address of your choosing. -2. Run `go-mailin8 ` +2. Run the binary supplying `` as an argument, e.g. + `go-mailin8_linux_amd64 ` ## TODO: From 2784844e44799652b8df7e7ea22ed4ef17303ad7 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Sun, 26 Jul 2020 22:05:21 +0100 Subject: [PATCH 6/7] Avoid hardcoding binary name May have different names, e.g. the GitHub release for Linux is `go-mailin8_linux_amd64`. --- main.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index f8473a8..532b5c3 100644 --- a/main.go +++ b/main.go @@ -19,6 +19,7 @@ import ( "fmt" "net/http" "os" + "path/filepath" ) type mail struct { @@ -85,7 +86,7 @@ func getInbox(address string) (inbox, error) { func main() { // TODO: consider allow to retrieve more than one message. if len(os.Args) != 2 { - fmt.Println("Usage: go-mailin8
") + fmt.Printf("Usage: %v
\n", filepath.Base(os.Args[0])) os.Exit(1) } From 79f43a6e56372364bbd01d28ec4a63090b3310b7 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Sun, 26 Jul 2020 22:06:14 +0100 Subject: [PATCH 7/7] Update build workflow To reflect changes in how the code is built. --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 98c1d72..4ed23e8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,8 +20,8 @@ jobs: - name: Build code run: | - make build + make build-linux - name: Run code run: | - ./go-mailin8 | grep "Usage: go-mailin8
" + ./go-mailin8_linux_amd64 | grep "Usage: go-mailin8_linux_amd64
"