Skip to content

Commit 8f73920

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

48 files changed

Lines changed: 6194 additions & 106 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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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: macos-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-go@v5
19+
with:
20+
go-version-file: go.mod
21+
- uses: golangci/golangci-lint-action@v6
22+
with:
23+
version: latest
24+
25+
test:
26+
name: Test
27+
runs-on: macos-latest
28+
steps:
29+
- uses: actions/checkout@v4
30+
- uses: actions/setup-go@v5
31+
with:
32+
go-version-file: go.mod
33+
- run: make test
34+
35+
smoke:
36+
name: Smoke Tests
37+
runs-on: macos-latest
38+
needs: test
39+
steps:
40+
- uses: actions/checkout@v4
41+
- uses: actions/setup-go@v5
42+
with:
43+
go-version-file: go.mod
44+
- run: make smoke

.github/workflows/release.yml

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ permissions: {}
77

88
jobs:
99
release:
10-
name: Build, Sign & Release
10+
name: Build & Release
1111
runs-on: ubuntu-latest
12-
environment: release
1312
permissions:
14-
contents: write # create tag, release, and upload assets
15-
id-token: write # Sigstore OIDC keyless signing
16-
attestations: write # SLSA build provenance
13+
contents: write # create tag, release, and upload assets
14+
attestations: write # SLSA build provenance
1715

1816
steps:
1917
- name: Harden the runner (Audit all outbound calls)
@@ -23,13 +21,15 @@ jobs:
2321

2422
- name: Checkout repository
2523
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
24+
with:
25+
fetch-depth: 0
2626

27-
- name: Extract version from script
27+
- name: Extract version from source
2828
id: version
2929
run: |
30-
version=$(grep -m1 '^AGENT_VERSION=' stepsecurity-dev-machine-guard.sh | sed 's/AGENT_VERSION="//;s/"//')
30+
version=$(grep -m1 'Version' internal/buildinfo/version.go | sed 's/.*"//;s/".*//')
3131
if [ -z "$version" ]; then
32-
echo "::error::Could not extract AGENT_VERSION from script"
32+
echo "::error::Could not extract Version from internal/buildinfo/version.go"
3333
exit 1
3434
fi
3535
tag="v${version}"
@@ -40,52 +40,47 @@ jobs:
4040
- name: Check tag does not already exist
4141
run: |
4242
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."
43+
echo "::error::Tag ${{ steps.version.outputs.tag }} already exists. Bump Version in internal/buildinfo/version.go before releasing."
4444
exit 1
4545
fi
4646
47-
- name: Install cosign
48-
uses: sigstore/cosign-installer@faadad0cce49287aee09b3a48701e75088a2c6ad # v4.0.0
49-
50-
- name: Sign script with Sigstore (keyless)
51-
run: |
52-
cosign sign-blob stepsecurity-dev-machine-guard.sh \
53-
--bundle stepsecurity-dev-machine-guard.sh.bundle \
54-
--yes
55-
56-
- name: Verify signature
57-
run: |
58-
cosign verify-blob stepsecurity-dev-machine-guard.sh \
59-
--bundle stepsecurity-dev-machine-guard.sh.bundle \
60-
--certificate-identity-regexp "github.com/step-security/dev-machine-guard" \
61-
--certificate-oidc-issuer "https://token.actions.githubusercontent.com"
62-
63-
- name: Generate checksums
64-
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
69-
7047
- name: Create tag
7148
run: |
7249
git config user.name "github-actions[bot]"
7350
git config user.email "github-actions[bot]@users.noreply.github.com"
7451
git tag -a "${{ steps.version.outputs.tag }}" -m "Release ${{ steps.version.outputs.tag }}"
7552
git push origin "${{ steps.version.outputs.tag }}"
7653
77-
- name: Create GitHub Release
78-
uses: step-security/action-gh-release@d45511d7589f080cf54961ff056b9705a74fd160 # v2.5.0
54+
- name: Set up Go
55+
uses: actions/setup-go@v5
7956
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
57+
go-version-file: go.mod
58+
59+
- name: Run GoReleaser
60+
uses: goreleaser/goreleaser-action@v6
61+
with:
62+
distribution: goreleaser
63+
version: latest
64+
args: release --clean
65+
env:
66+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
68+
- name: Generate checksums for shell script
69+
run: |
70+
sha256sum stepsecurity-dev-machine-guard.sh >> dist/stepsecurity-dev-machine-guard_${{ steps.version.outputs.version }}_SHA256SUMS
71+
72+
- name: Upload shell script checksum to release
73+
env:
74+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75+
run: |
76+
gh release upload "${{ steps.version.outputs.tag }}" \
77+
dist/stepsecurity-dev-machine-guard_${{ steps.version.outputs.version }}_SHA256SUMS \
78+
--clobber
8779
8880
- name: Attest build provenance
8981
uses: actions/attest-build-provenance@a2bbfa25375fe432b6a289bc6b6cd05ecd0c4c32 # v4.1.0
9082
with:
91-
subject-path: stepsecurity-dev-machine-guard.sh
83+
subject-path: |
84+
dist/stepsecurity-dev-machine-guard_darwin_amd64_v1/stepsecurity-dev-machine-guard
85+
dist/stepsecurity-dev-machine-guard_darwin_arm64_v1/stepsecurity-dev-machine-guard
86+
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: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
- linux
11+
goarch:
12+
- amd64
13+
- arm64
14+
mod_timestamp: "{{ .CommitTimestamp }}"
15+
flags:
16+
- -trimpath
17+
ldflags:
18+
- -s -w
19+
- -X github.com/step-security/dev-machine-guard/internal/buildinfo.GitCommit={{.FullCommit}}
20+
- -X github.com/step-security/dev-machine-guard/internal/buildinfo.ReleaseTag={{.Tag}}
21+
- -X github.com/step-security/dev-machine-guard/internal/buildinfo.ReleaseBranch={{.Branch}}
22+
env:
23+
- CGO_ENABLED=0
24+
25+
archives:
26+
- format: binary
27+
name_template: "{{ .Binary }}_{{ .Os }}_{{ .Arch }}"
28+
29+
checksum:
30+
name_template: "{{ .ProjectName }}_{{ .Version }}_SHA256SUMS"
31+
algorithm: sha256
32+
33+
release:
34+
extra_files:
35+
- 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)