-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from polarsignals/ci
Add basic CI for running tests and building containers
- Loading branch information
Showing
5 changed files
with
183 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
name: Artifacts | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
push: | ||
tags: | ||
- v* | ||
branches: | ||
- '**' | ||
|
||
jobs: | ||
artifacts: | ||
name: Goreleaser release | ||
runs-on: ubuntu-latest | ||
permissions: | ||
packages: write | ||
contents: write | ||
container: | ||
image: docker.io/goreleaser/goreleaser-cross:v1.22.4 | ||
options: --privileged | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
steps: | ||
- name: Check out the code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
# https://github.com/actions/checkout/issues/766 | ||
- name: Add repository directory to the git global config as a safe directory | ||
run: git config --global --add safe.directory "${GITHUB_WORKSPACE}" | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: go.mod | ||
|
||
- name: Fetch all tags | ||
run: git fetch --force --tags | ||
|
||
- name: Login to registry | ||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/') | ||
run: | | ||
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | ||
- name: Login to registry | ||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') | ||
run: | | ||
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | ||
- name: Run Goreleaser release | ||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') | ||
run: goreleaser release --clean --verbose | ||
|
||
- name: Run Goreleaser snapshot | ||
run: | | ||
goreleaser release --clean --verbose --snapshot | ||
- name: Set snapshot tag | ||
id: vars | ||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/') | ||
run: | | ||
echo "tag=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | ||
echo "git_tag=v0.0.0" >> $GITHUB_OUTPUT | ||
# Use this again once we have a frist release | ||
# echo "git_tag=$(git describe --tags --abbrev=0)" >> $GITHUB_OUTPUT | ||
|
||
- name: Push snapshot images | ||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/') | ||
run: | | ||
docker tag ghcr.io/polarsignals/gpu-metrics-agent:${{ steps.vars.outputs.git_tag }}-amd64 ghcr.io/polarsignals/gpu-metrics-agent:${{ steps.vars.outputs.tag }}-amd64 | ||
docker push ghcr.io/polarsignals/gpu-metrics-agent:${{ steps.vars.outputs.tag }}-amd64 | ||
docker manifest create ghcr.io/polarsignals/gpu-metrics-agent:${{ steps.vars.outputs.tag }} --amend ghcr.io/polarsignals/gpu-metrics-agent:${{ steps.vars.outputs.tag }}-amd64 | ||
docker manifest annotate ghcr.io/polarsignals/gpu-metrics-agent:${{ steps.vars.outputs.tag }} ghcr.io/polarsignals/gpu-metrics-agent:${{ steps.vars.outputs.tag }}-amd64 --os linux --arch amd64 | ||
docker manifest push ghcr.io/polarsignals/gpu-metrics-agent:${{ steps.vars.outputs.tag }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Test | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out the code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: go.mod | ||
|
||
- name: Run Tests | ||
run: go test -race -v ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/dist/ | ||
/gpu-metrics-agent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
version: 2 | ||
builds: | ||
- id: linux-amd64 | ||
main: ./ | ||
binary: gpu-metrics-agent | ||
goos: | ||
- linux | ||
goarch: | ||
- amd64 | ||
flags: | ||
- -mod=readonly | ||
- -trimpath | ||
- -v | ||
ldflags: | ||
# https://goreleaser.com/customization/build/#reproducible-builds | ||
# {{.CommitDate}} is the date of the commit to make builds reproducible. | ||
- -X main.version={{.Version}} -X main.commit={{.FullCommit}} -X main.date={{.CommitDate}} -X main.goArch=amd64 | ||
tags: | ||
- osusergo | ||
- netgo | ||
archives: | ||
- name_template: >- | ||
{{ .ProjectName }}_ | ||
{{- trimprefix .Version "v" }}_ | ||
{{- title .Os }}_ | ||
{{- if eq .Arch "amd64" }}x86_64 | ||
{{- else if eq .Arch "arm64" }}aarch64 | ||
{{- else }}{{ .Arch }}{{ end }} | ||
format: binary | ||
format_overrides: | ||
- goos: windows | ||
format: zip | ||
files: | ||
- 'LICENSE*' | ||
- 'README*' | ||
checksum: | ||
name_template: 'checksums.txt' | ||
snapshot: | ||
name_template: "{{ .Branch }}-{{ .ShortCommit }}" | ||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- '^docs:' | ||
- '^test:' | ||
release: | ||
github: | ||
owner: polarsignals | ||
name: gpu-metrics-agent | ||
prerelease: auto | ||
draft: false | ||
name_template: '{{ .Tag }}' | ||
dockers: | ||
- image_templates: ["ghcr.io/polarsignals/{{ .ProjectName }}:{{ .Tag }}-amd64"] | ||
dockerfile: Dockerfile | ||
use: buildx | ||
build_flag_templates: | ||
- --pull | ||
- --platform=linux/amd64 | ||
- --label=org.opencontainers.image.title={{ .ProjectName }} | ||
- --label=org.opencontainers.image.description={{ .ProjectName }} | ||
- --label=org.opencontainers.image.url=https://polarsignals.com | ||
- --label=org.opencontainers.image.source=https://github.com/polarsignals/{{ .ProjectName }} | ||
- --label=org.opencontainers.image.version={{ .Tag }} | ||
- --label=org.opencontainers.image.revision={{ .FullCommit }} | ||
- --label=org.opencontainers.image.licenses=Apache-2.0 | ||
docker_manifests: | ||
- name_template: ghcr.io/polarsignals/{{ .ProjectName }}:{{ .Tag }} | ||
image_templates: | ||
- ghcr.io/polarsignals/{{ .ProjectName }}:{{ .Tag }}-amd64 | ||
- name_template: ghcr.io/polarsignals/{{ .ProjectName }}:latest | ||
image_templates: | ||
- ghcr.io/polarsignals/{{ .ProjectName }}:{{ .Tag }}-amd64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FROM cgr.dev/chainguard/static:latest | ||
USER root | ||
|
||
COPY gpu-metrics-agent /gpu-metrics-agent | ||
|
||
ENTRYPOINT ["/gpu-metrics-agent"] |