Skip to content

Commit

Permalink
Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamgilbert committed Feb 22, 2024
1 parent d25da0b commit a2a0469
Show file tree
Hide file tree
Showing 36 changed files with 1,461 additions and 163 deletions.
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build --action_env=CGO_ENABLED=1
28 changes: 28 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Test Coverage

on: [pull_request]

jobs:
coverage:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.21.3"

- name: Test Coverage
run: make coverage

- name: Setup LCOV
uses: hrishikesh-kadam/setup-lcov@d100c36c45e4f64950fb746cd28713f6c756a9c1
- name: Report code coverage
uses: zgosalvez/github-actions-report-lcov@5f5c6e77851c41ab9c69a212690c1040bb916016
with:
coverage-files: coverage/lcov.info
minimum-coverage: 40
github-token: ${{ secrets.GITHUB_TOKEN }}
update-comment: true
15 changes: 15 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Run linting

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.21.3"
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
17 changes: 17 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Go Test

on: [push]

jobs:
test:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}

- name: Test
run: make test
2 changes: 1 addition & 1 deletion Crypt/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>236</string>
<string>238</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2021 The Crypt Project. All rights reserved.</string>
<key>NSPrincipalClass</key>
Expand Down
26 changes: 19 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,31 @@ PAYLOAD=\
pack-scripts \
remove-xattrs

#################################################
.PHONY: coverage

#################################################
## Why is all the bazel stuff commented out? It seems to have issues with Cgo.
gazelle:
bazel run //:gazelle

run:
# bazel run --platforms=@io_bazel_rules_go//go/toolchain:darwin_amd64 -- //cmd:crypt-arm64
go run cmd/main.go

update-repos:
bazel run //:gazelle-update-repos -- -from_file=go.mod

test:
bazel test --test_output=errors //...
# bazel test --test_output=errors //...
go test -v ./...

coverage:
rm -rf coverage
mkdir -p coverage
bazel coverage --combined_report=lcov //...
mv $(BAZEL_OUTPUT_PATH)/_coverage/_coverage_report.dat coverage/lcov.info

build: check_variables clean-crypt
build: check_variables clean-crypt build_binary
xcodebuild -project Crypt.xcodeproj -configuration Release

clean-crypt:
Expand All @@ -52,17 +59,22 @@ pack-scripts:
@sudo ${INSTALL} -o root -g wheel -m 755 Package/preinstall ${SCRIPT_D}

build_binary:
bazel build //cmd:crypt-amd
bazel build //cmd:crypt-arm
tools/bazel_to_builddir.sh
# bazel build --platforms=@io_bazel_rules_go//go/toolchain:darwin_amd64 //:cmd:crypt-amd
# bazel build --platforms=@io_bazel_rules_go//go/toolchain:darwin_arm //cmd:crypt-arm
# tools/bazel_to_builddir.sh
GOOS=darwin GOARCH=arm64 go build -o build/checkin.arm64 cmd/main.go
GOOS=darwin GOARCH=amd64 go build -o build/checkin.amd64 cmd/main.go
/usr/bin/lipo -create -output build/checkin build/checkin.arm64 build/checkin.amd64
/bin/rm build/checkin.arm64
/bin/rm build/checkin.amd64
@sudo chown root:wheel build/checkin
@sudo chmod 755 build/checkin


sign_binary:
@sudo codesign --timestamp --force --deep -s "${DEV_APP_CERT}" build/checkin

pack-checkin: l_Library build_binary
pack-checkin: l_Library build_binary sign_binary
@sudo mkdir -p ${WORK_D}/Library/Crypt
@sudo ${CP} checkin ${WORK_D}/Library/Crypt/checkin
@sudo chown -R root:wheel ${WORK_D}/Library/Crypt
Expand Down
6 changes: 4 additions & 2 deletions Package/checkin
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,10 @@ def rotate_if_used(key_path):
def main():
plist_path = pref("OutputPath")
logging.info(f"OutputPath Pref is set to: {plist_path}")
if pref("RotateUsedKey"):
rotate_if_used(plist_path)

# Not usable after macos 10.15
# if pref("RotateUsedKey"):
# rotate_if_used(plist_path)

if pref("RotateUsedKey") and pref("ValidateKey") and not pref("RemovePlist"):
rotate_invalid_key(plist_path)
Expand Down
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ go_dependencies()

go_rules_dependencies()

go_register_toolchains(version = "1.20.5")
go_register_toolchains(version = "1.21.3")

gazelle_dependencies()
23 changes: 22 additions & 1 deletion cmd/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_cross_binary", "go_library")

go_library(
name = "cmd_lib",
srcs = ["main.go"],
importpath = "github.com/grahamgilbert/crypt/cmd",
visibility = ["//visibility:private"],
deps = [
"//pkg/checkin",
"//pkg/pref",
"//pkg/utils",
],
)

go_binary(
Expand All @@ -15,10 +20,26 @@ go_binary(
visibility = ["//visibility:public"],
)

go_cross_binary(
name = "crypt-arm64",
platform = "@io_bazel_rules_go//go/toolchain:darwin_arm64",
tags = ["manual"],
target = "crypt-arm", # matches go_binary target name
visibility = ["//visibility:public"],
)

go_binary(
name = "crypt-amd",
embed = [":cmd_lib"],
goarch = "amd64",
goos = "darwin",
visibility = ["//visibility:public"],
)

go_cross_binary(
name = "crypt-amd64",
platform = "@io_bazel_rules_go//go/toolchain:darwin_amd64",
tags = ["manual"],
target = "crypt-amd", # matches go_binary target name
visibility = ["//visibility:public"],
)
20 changes: 18 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
package main

import "fmt"
import (
"log"
"os"

"github.com/grahamgilbert/crypt/pkg/checkin"
"github.com/grahamgilbert/crypt/pkg/pref"

Check failure on line 8 in cmd/main.go

View workflow job for this annotation

GitHub Actions / lint

could not import github.com/grahamgilbert/crypt/pkg/pref (-: # github.com/grahamgilbert/crypt/pkg/pref

Check failure on line 8 in cmd/main.go

View workflow job for this annotation

GitHub Actions / lint

could not import github.com/grahamgilbert/crypt/pkg/pref (-: # github.com/grahamgilbert/crypt/pkg/pref
"github.com/grahamgilbert/crypt/pkg/utils"
)

func main() {
fmt.Println("Hello world")

p := pref.New()
r := utils.NewRunner()

err := checkin.RunEscrow(r, p)
if err != nil {
log.Println(err)
os.Exit(1)
}
os.Exit(0)
}
12 changes: 12 additions & 0 deletions deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ def go_dependencies():
sum = "h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=",
version = "v1.1.1",
)
go_repository(
name = "com_github_groob_plist",
importpath = "github.com/groob/plist",
sum = "h1:saaSiB25B1wgaxrshQhurfPKUGJ4It3OxNJUy0rdOjU=",
version = "v0.0.0-20220217120414-63fa881b19a5",
)
go_repository(
name = "com_github_pkg_errors",
importpath = "github.com/pkg/errors",
sum = "h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=",
version = "v0.9.1",
)
go_repository(
name = "com_github_pmezard_go_difflib",
importpath = "github.com/pmezard/go-difflib",
Expand Down
8 changes: 6 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ module github.com/grahamgilbert/crypt

go 1.21

require github.com/stretchr/testify v1.8.4
require (
github.com/groob/plist v0.0.0-20220217120414-63fa881b19a5
github.com/hashicorp/go-version v1.6.0
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.4
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/groob/plist v0.0.0-20220217120414-63fa881b19a5 h1:saaSiB25B1wgaxrshQhurfPKUGJ4It3OxNJUy0rdOjU=
github.com/groob/plist v0.0.0-20220217120414-63fa881b19a5/go.mod h1:itkABA+w2cw7x5nYUS/pLRef6ludkZKOigbROmCTaFw=
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
26 changes: 26 additions & 0 deletions pkg/checkin/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "checkin",
srcs = ["escrow.go"],
importpath = "github.com/grahamgilbert/crypt/pkg/checkin",
visibility = ["//visibility:public"],
deps = [
"//pkg/pref",
"//pkg/utils",
"@com_github_groob_plist//:plist",
"@com_github_hashicorp_go_version//:go_default_library",
"@com_github_pkg_errors//:errors",
],
)

go_test(
name = "checkin_test",
srcs = ["escrow_test.go"],
embed = [":checkin"],
deps = [
"//pkg/utils",
"@com_github_groob_plist//:plist",
"@com_github_stretchr_testify//assert",
],
)
Loading

0 comments on commit a2a0469

Please sign in to comment.