Skip to content

Commit e183fd6

Browse files
authored
Merge pull request #3 from stuartleeks/sl/devcontainer-action
Add devcontainer build/release
2 parents a78cef4 + 9f23646 commit e183fd6

File tree

6 files changed

+69
-7
lines changed

6 files changed

+69
-7
lines changed

.devcontainer/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ RUN \
4747
&& go get github.com/acroca/[email protected] && go get github.com/ramya-rao-a/go-outline@7182a932836a71948db4a81991a494751eccfe77 \
4848
# --> GolangCI-lint
4949
&& curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sed 's/tar -/tar --no-same-owner -/g' | sh -s -- -b $(go env GOPATH)/bin \
50+
# --> Go releaser
51+
&& curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh -s -- "v0.132.1"\
5052
# --> Install junit converter
5153
&& go get github.com/jstemmer/[email protected] \
5254
&& rm -rf /go/src/ && rm -rf /go/pkg
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: build
1+
name: build-and-release
22

33
on:
44
push:
@@ -19,5 +19,11 @@ jobs:
1919
- name: Build devcontainer for tooling
2020
run: sudo -E make devcontainer
2121

22-
- name: Run the build
23-
run: sudo -E make devcontainer-build
22+
- name: Run the release
23+
run: sudo -E make devcontainer-release
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
BUILD_NUMBER: ${{ github.run_id }}
27+
IS_CI: 1
28+
IS_PR: ${{ github.head_ref }}
29+
BRANCH: ${{ github.ref }}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
/devcontainer
1+
/devcontainer
2+
/dist

.goreleaser.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
builds:
2+
- env:
3+
- CGO_ENABLED=0
4+
goos:
5+
- linux
6+
- darwin
7+
- windows
8+
goarch:
9+
- 386
10+
- amd64
11+
main: ./cmd/devcontainer/
12+
ldflags:
13+
- -s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}}
14+
changelog:
15+
sort: asc
16+
filters:
17+
exclude:
18+
- '^docs:'
19+
- '^test:'

Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ build:
44
devcontainer:
55
docker build -f ./.devcontainer/Dockerfile ./.devcontainer -t devcontainer-cli
66

7-
8-
devcontainer-build:
7+
devcontainer-release:
98
ifdef DEVCONTAINER
109
$(error This target can only be run outside of the devcontainer as it mounts files and this fails within a devcontainer. Don't worry all it needs is docker)
1110
endif
1211
@docker run -v ${PWD}:${PWD} \
12+
-e BUILD_NUMBER="${BUILD_NUMBER}" \
13+
-e IS_CI="${IS_CI}" \
14+
-e IS_PR="${IS_PR}" \
15+
-e BRANCH="${BRANCH}" \
16+
-e GITHUB_TOKEN="${GITHUB_TOKEN}" \
1317
--entrypoint /bin/bash \
1418
--workdir "${PWD}" \
1519
devcontainer-cli \
16-
-c "make build"
20+
-c "${PWD}/scripts/ci_release.sh"

scripts/ci_release.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
set -e
2+
3+
# Fail if build number not set
4+
if [ -z "$BUILD_NUMBER" ]; then
5+
echo "Env var 'BUILD_NUMBER' must be set for this script to work correctly"
6+
exit 1
7+
fi
8+
9+
# If running inside CI login to docker
10+
if [ -z ${IS_CI} ]; then
11+
echo "Not running in CI, skipping CI setup"
12+
else
13+
if [ -z $IS_PR ] && [[ $BRANCH == "refs/heads/master" ]]; then
14+
echo "On master setting PUBLISH=true"
15+
export PUBLISH=true
16+
else
17+
echo "Skipping publish as is from PR: $PR_NUMBER or not 'refs/heads/master' BRANCH: $BRANCH"
18+
fi
19+
fi
20+
21+
# Set version for release (picked up later by goreleaser)
22+
git tag -f v0.1.$BUILD_NUMBER
23+
24+
if [ -z ${PUBLISH} ]; then
25+
echo "Running with --skip-publish as PUBLISH not set"
26+
goreleaser --skip-publish --rm-dist
27+
else
28+
echo "Publishing release"
29+
goreleaser
30+
fi

0 commit comments

Comments
 (0)