Skip to content

Commit 0f315f0

Browse files
feat(mdm): migrate script to go module
1 parent e9e5cee commit 0f315f0

48 files changed

Lines changed: 6166 additions & 93 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/go.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Go
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
lint:
14+
name: Lint
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-go@v5
19+
with:
20+
go-version: "1.24"
21+
- uses: golangci/golangci-lint-action@v6
22+
with:
23+
version: latest
24+
env:
25+
GOOS: darwin
26+
27+
test:
28+
name: Test
29+
runs-on: macos-latest
30+
steps:
31+
- uses: actions/checkout@v4
32+
- uses: actions/setup-go@v5
33+
with:
34+
go-version: "1.24"
35+
- run: make test
36+
37+
smoke:
38+
name: Smoke Tests
39+
runs-on: macos-latest
40+
needs: test
41+
steps:
42+
- uses: actions/checkout@v4
43+
- uses: actions/setup-go@v5
44+
with:
45+
go-version: "1.24"
46+
- run: make smoke

.github/workflows/release.yml

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ jobs:
1111
runs-on: ubuntu-latest
1212
environment: release
1313
permissions:
14-
contents: write # create tag, release, and upload assets
15-
id-token: write # Sigstore OIDC keyless signing
16-
attestations: write # SLSA build provenance
14+
contents: write # create tag, release, and upload assets
15+
id-token: write # Sigstore OIDC keyless signing
16+
attestations: write # SLSA build provenance
1717

1818
steps:
1919
- name: Harden the runner (Audit all outbound calls)
@@ -23,13 +23,15 @@ jobs:
2323

2424
- name: Checkout repository
2525
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
26+
with:
27+
fetch-depth: 0
2628

27-
- name: Extract version from script
29+
- name: Extract version from source
2830
id: version
2931
run: |
30-
version=$(grep -m1 '^AGENT_VERSION=' stepsecurity-dev-machine-guard.sh | sed 's/AGENT_VERSION="//;s/"//')
32+
version=$(grep -m1 'Version' internal/buildinfo/version.go | sed 's/.*"//;s/".*//')
3133
if [ -z "$version" ]; then
32-
echo "::error::Could not extract AGENT_VERSION from script"
34+
echo "::error::Could not extract Version from internal/buildinfo/version.go"
3335
exit 1
3436
fi
3537
tag="v${version}"
@@ -40,14 +42,35 @@ jobs:
4042
- name: Check tag does not already exist
4143
run: |
4244
if git rev-parse "refs/tags/${{ steps.version.outputs.tag }}" >/dev/null 2>&1; then
43-
echo "::error::Tag ${{ steps.version.outputs.tag }} already exists. Bump AGENT_VERSION in the script before releasing."
45+
echo "::error::Tag ${{ steps.version.outputs.tag }} already exists. Bump Version in internal/buildinfo/version.go before releasing."
4446
exit 1
4547
fi
4648
49+
- name: Create tag
50+
run: |
51+
git config user.name "github-actions[bot]"
52+
git config user.email "github-actions[bot]@users.noreply.github.com"
53+
git tag -a "${{ steps.version.outputs.tag }}" -m "Release ${{ steps.version.outputs.tag }}"
54+
git push origin "${{ steps.version.outputs.tag }}"
55+
56+
- name: Set up Go
57+
uses: actions/setup-go@v5
58+
with:
59+
go-version: "1.24"
60+
61+
- name: Run GoReleaser
62+
uses: goreleaser/goreleaser-action@v6
63+
with:
64+
distribution: goreleaser
65+
version: latest
66+
args: release --clean
67+
env:
68+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
69+
4770
- name: Install cosign
4871
uses: sigstore/cosign-installer@faadad0cce49287aee09b3a48701e75088a2c6ad # v4.0.0
4972

50-
- name: Sign script with Sigstore (keyless)
73+
- name: Sign shell script with Sigstore (keyless)
5174
run: |
5275
cosign sign-blob stepsecurity-dev-machine-guard.sh \
5376
--bundle stepsecurity-dev-machine-guard.sh.bundle \
@@ -60,32 +83,27 @@ jobs:
6083
--certificate-identity-regexp "github.com/step-security/dev-machine-guard" \
6184
--certificate-oidc-issuer "https://token.actions.githubusercontent.com"
6285
63-
- name: Generate checksums
86+
- name: Generate shell script checksum
6487
run: |
65-
sha256sum stepsecurity-dev-machine-guard.sh > checksums.txt
66-
sha256sum stepsecurity-dev-machine-guard.sh.bundle >> checksums.txt
67-
echo "Checksums:"
68-
cat checksums.txt
88+
sha256sum stepsecurity-dev-machine-guard.sh > shell-checksums.txt
89+
sha256sum stepsecurity-dev-machine-guard.sh.bundle >> shell-checksums.txt
6990
70-
- name: Create tag
91+
- name: Upload shell script artifacts to release
92+
env:
93+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7194
run: |
72-
git config user.name "github-actions[bot]"
73-
git config user.email "github-actions[bot]@users.noreply.github.com"
74-
git tag -a "${{ steps.version.outputs.tag }}" -m "Release ${{ steps.version.outputs.tag }}"
75-
git push origin "${{ steps.version.outputs.tag }}"
95+
gh release upload "${{ steps.version.outputs.tag }}" \
96+
stepsecurity-dev-machine-guard.sh.bundle \
97+
shell-checksums.txt
7698
77-
- name: Create GitHub Release
78-
uses: step-security/action-gh-release@d45511d7589f080cf54961ff056b9705a74fd160 # v2.5.0
99+
- name: Attest build provenance (Go binaries)
100+
uses: actions/attest-build-provenance@a2bbfa25375fe432b6a289bc6b6cd05ecd0c4c32 # v4.1.0
79101
with:
80-
tag_name: ${{ steps.version.outputs.tag }}
81-
name: ${{ steps.version.outputs.tag }}
82-
generate_release_notes: true
83-
files: |
84-
stepsecurity-dev-machine-guard.sh
85-
stepsecurity-dev-machine-guard.sh.bundle
86-
checksums.txt
87-
88-
- name: Attest build provenance
102+
subject-path: |
103+
dist/stepsecurity-dev-machine-guard_darwin_amd64_v1/stepsecurity-dev-machine-guard
104+
dist/stepsecurity-dev-machine-guard_darwin_arm64_v1/stepsecurity-dev-machine-guard
105+
106+
- name: Attest build provenance (shell script)
89107
uses: actions/attest-build-provenance@a2bbfa25375fe432b6a289bc6b6cd05ecd0c4c32 # v4.1.0
90108
with:
91109
subject-path: stepsecurity-dev-machine-guard.sh

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,9 @@
1717
!docs/**/*.html
1818
!images/**/*.html
1919

20+
# Go build artifacts
21+
# /stepsecurity-dev-machine-guard
22+
dist/
23+
2024
# Temporary files
2125
todo-remove/

.goreleaser.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
version: 2
2+
project_name: stepsecurity-dev-machine-guard
3+
4+
builds:
5+
- id: stepsecurity-dev-machine-guard
6+
main: ./cmd/stepsecurity-dev-machine-guard
7+
binary: stepsecurity-dev-machine-guard
8+
goos:
9+
- darwin
10+
goarch:
11+
- amd64
12+
- arm64
13+
mod_timestamp: "{{ .CommitTimestamp }}"
14+
flags:
15+
- -trimpath
16+
ldflags:
17+
- -s -w
18+
- -X github.com/step-security/dev-machine-guard/internal/buildinfo.GitCommit={{.FullCommit}}
19+
- -X github.com/step-security/dev-machine-guard/internal/buildinfo.ReleaseTag={{.Tag}}
20+
- -X github.com/step-security/dev-machine-guard/internal/buildinfo.ReleaseBranch={{.Branch}}
21+
env:
22+
- CGO_ENABLED=0
23+
24+
archives:
25+
- format: binary
26+
name_template: "{{ .Binary }}_{{ .Os }}_{{ .Arch }}"
27+
28+
checksum:
29+
name_template: "{{ .ProjectName }}_{{ .Version }}_SHA256SUMS"
30+
algorithm: sha256
31+
32+
release:
33+
extra_files:
34+
- glob: stepsecurity-dev-machine-guard.sh

Makefile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
BINARY := stepsecurity-dev-machine-guard
2+
MODULE := github.com/step-security/dev-machine-guard
3+
VERSION := $(shell grep -m1 'Version' internal/buildinfo/version.go | sed 's/.*"//;s/".*//')
4+
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
5+
BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
6+
TAG := $(shell git describe --tags --exact-match 2>/dev/null || echo "dev")
7+
LDFLAGS := -s -w \
8+
-X $(MODULE)/internal/buildinfo.GitCommit=$(COMMIT) \
9+
-X $(MODULE)/internal/buildinfo.ReleaseTag=$(TAG) \
10+
-X $(MODULE)/internal/buildinfo.ReleaseBranch=$(BRANCH)
11+
12+
.PHONY: build test lint clean smoke
13+
14+
build:
15+
go build -trimpath -ldflags "$(LDFLAGS)" -o $(BINARY) ./cmd/stepsecurity-dev-machine-guard
16+
17+
test:
18+
go test ./... -v -race -count=1
19+
20+
lint:
21+
golangci-lint run ./...
22+
23+
clean:
24+
rm -f $(BINARY)
25+
26+
smoke: build
27+
bash tests/test_smoke_go.sh

0 commit comments

Comments
 (0)