Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build for Windows #68

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 4 additions & 29 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,6 @@ on:
- "v*.*.*"

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Docker Labels
id: meta
uses: crazy-max/ghaction-docker-meta@v2
with:
images: cupcakearmy/autorestic
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
with:
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}

release:
runs-on: ubuntu-latest
steps:
Expand All @@ -51,6 +23,9 @@ jobs:
- name: Release
uses: softprops/action-gh-release@v1
with:
files: dist/*
files: |
dist/*.bz2
dist/*.zip
dist/SHA256SUMS
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21 changes: 19 additions & 2 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"path"
"path/filepath"
"sync"

"strings"
"github.com/cupcakearmy/autorestic/internal"
)

Expand All @@ -22,6 +22,7 @@ var targets = map[string][]string{
"linux": {"386", "amd64", "arm", "arm64"},
"netbsd": {"386", "amd64"},
"openbsd": {"386", "amd64"},
"windows": {"386", "amd64"},
}

type buildOptions struct {
Expand All @@ -31,6 +32,12 @@ type buildOptions struct {
func build(options buildOptions, wg *sync.WaitGroup) {
fmt.Printf("Building %s %s\n", options.Target, options.Arch)
out := fmt.Sprintf("autorestic_%s_%s_%s", options.Version, options.Target, options.Arch)

// append .exe for Windows
if (options.Target == "windows") {
out += ".exe"
}

out = path.Join(DIR, out)
out, _ = filepath.Abs(out)
fmt.Println(out)
Expand All @@ -53,7 +60,17 @@ func build(options buildOptions, wg *sync.WaitGroup) {

// Compress
{
c := exec.Command("bzip2", out)
var c *exec.Cmd
switch options.Target {
// use zip for Windows
case "windows":
zipFile := strings.TrimSuffix(out, ".exe") + ".zip"
c = exec.Command("zip", "-j", "-q", "-X", zipFile, out)
// use bzip2 for everything else
default:
c = exec.Command("bzip2", out)
}

c.Dir = DIR
c.Stdout = os.Stdout
c.Stderr = os.Stderr
Expand Down