Skip to content

Commit 300cede

Browse files
authored
Add CI (#2)
1 parent c715aaa commit 300cede

File tree

5 files changed

+104
-5
lines changed

5 files changed

+104
-5
lines changed

.github/workflows/ci.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
pull_request:
9+
10+
workflow_dispatch:
11+
12+
permissions:
13+
actions: none
14+
checks: none
15+
contents: read
16+
deployments: none
17+
issues: none
18+
packages: none
19+
pull-requests: none
20+
repository-projects: none
21+
security-events: none
22+
statuses: none
23+
24+
# Cancel in-progress runs for pull requests when developers push
25+
# additional changes
26+
concurrency:
27+
group: ${{ github.workflow }}-${{ github.ref }}
28+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
29+
30+
jobs:
31+
test:
32+
runs-on: ubuntu-latest
33+
steps:
34+
- name: Checkout
35+
uses: actions/checkout@v3
36+
37+
# Install Go!
38+
- uses: actions/setup-go@v3
39+
with:
40+
go-version: "~1.20"
41+
42+
- name: Test
43+
run: go test ./...

.github/workflows/release.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: release
2+
on:
3+
push:
4+
tags:
5+
- "v*"
6+
7+
permissions:
8+
# Required to publish a release
9+
contents: write
10+
# Necessary to push docker images to ghcr.io.
11+
packages: write
12+
# Necessary for GCP authentication (https://github.com/google-github-actions/setup-gcloud#usage)
13+
id-token: write
14+
15+
concurrency: ${{ github.workflow }}-${{ github.ref }}
16+
17+
jobs:
18+
release:
19+
name: Build and publish
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v3
23+
24+
- uses: actions/setup-go@v3
25+
with:
26+
go-version: "~1.20"
27+
28+
- name: Build
29+
run: ./scripts/build.sh
30+
31+
- name: Push
32+
run: |
33+
VERSION=$(./scripts/version.sh)
34+
IMAGE=ghcr.io/coder/envbuilder:$VERSION
35+
docker tag envbuilder:latest $IMAGE
36+
docker push $IMAGE

git_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import (
66
"net/http/httptest"
77
"os"
88
"testing"
9+
"time"
910

1011
"github.com/coder/envbuilder"
1112
"github.com/coder/envbuilder/gittest"
1213
"github.com/go-git/go-billy/v5/memfs"
1314
"github.com/go-git/go-git/v5"
15+
"github.com/go-git/go-git/v5/plumbing/object"
1416
"github.com/stretchr/testify/require"
1517
)
1618

@@ -28,7 +30,13 @@ func TestCloneRepo(t *testing.T) {
2830
gittest.WriteFile(t, serverFS, "README.md", "Hello, world!")
2931
_, err = tree.Add("README.md")
3032
require.NoError(t, err)
31-
commit, err := tree.Commit("Wow!", &git.CommitOptions{})
33+
commit, err := tree.Commit("Wow!", &git.CommitOptions{
34+
Author: &object.Signature{
35+
Name: "Example",
36+
Email: "in@tests.com",
37+
When: time.Now(),
38+
},
39+
})
3240
require.NoError(t, err)
3341
_, err = repo.CommitObject(commit)
3442
require.NoError(t, err)

gittest/gittest.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/go-git/go-billy/v5"
1010
"github.com/go-git/go-git/v5"
11+
"github.com/go-git/go-git/v5/plumbing"
1112
"github.com/go-git/go-git/v5/plumbing/cache"
1213
"github.com/go-git/go-git/v5/plumbing/format/pktline"
1314
"github.com/go-git/go-git/v5/plumbing/protocol/packp"
@@ -99,6 +100,11 @@ func NewRepo(t *testing.T, fs billy.Filesystem) *git.Repository {
99100
storage := filesystem.NewStorage(fs, cache.NewObjectLRU(cache.DefaultMaxSize))
100101
repo, err := git.Init(storage, fs)
101102
require.NoError(t, err)
103+
104+
h := plumbing.NewSymbolicReference(plumbing.HEAD, plumbing.ReferenceName("refs/heads/main"))
105+
err = storage.SetReference(h)
106+
require.NoError(t, err)
107+
102108
return repo
103109
}
104110

@@ -111,7 +117,3 @@ func WriteFile(t *testing.T, fs billy.Filesystem, path, content string) {
111117
err = file.Close()
112118
require.NoError(t, err)
113119
}
114-
115-
func CommitFile() {
116-
117-
}

scripts/version.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
cd $(dirname "${BASH_SOURCE[0]}")
5+
6+
last_tag="$(git describe --tags --abbrev=0)"
7+
version="$last_tag"
8+
9+
# Remove the "v" prefix.
10+
echo "${version#v}"

0 commit comments

Comments
 (0)