Skip to content

Commit 13d00c0

Browse files
authored
Merge pull request #1 from stuartleeks/ci
Add GitHub actions for CI build
2 parents 058e1a4 + 688a0e7 commit 13d00c0

File tree

9 files changed

+165
-3
lines changed

9 files changed

+165
-3
lines changed

.devcontainer/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ RUN \
5959
# --> GolangCI-lint
6060
&& 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
6161

62+
# Add goreleaser
63+
RUN \
64+
# --> Go releaser
65+
curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | BINDIR="$GOPATH/bin" sh -s -- "v0.164.0"
66+
6267
# __DEVCONTAINER_SNIPPET_INSERT__ (control where snippets get inserted using the devcontainer CLI)
6368

6469
# Switch back to dialog for any ad-hoc use of apt-get
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: build-and-release
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths-ignore:
7+
- README.md
8+
- 'docs/**'
9+
pull_request:
10+
branches: [ main ]
11+
paths-ignore:
12+
- README.md
13+
- 'docs/**'
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-18.04
18+
19+
steps:
20+
- uses: actions/checkout@v2
21+
22+
- name: CI Tooling
23+
run: sudo apt update && sudo apt install build-essential -y
24+
25+
- name: Build devcontainer for tooling
26+
run: sudo -E make devcontainer
27+
28+
- name: Run the release
29+
run: sudo -E make devcontainer-release
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
BUILD_NUMBER: ${{ github.run_id }}
33+
IS_CI: 1
34+
IS_PR: ${{ github.head_ref }}
35+
BRANCH: ${{ github.ref }}

.goreleaser.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
builds:
2+
- binary: wsl-notify-send
3+
goos:
4+
- windows
5+
goarch:
6+
- 386
7+
- amd64
8+
main: main.go
9+
ldflags:
10+
- -s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}} -X "main.goversion={{.Env.GOVERSION}}"
11+
12+
archives:
13+
- id: zip
14+
name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
15+
format_overrides:
16+
- goos: windows
17+
format: zip
18+
19+
changelog:
20+
sort: asc
21+
filters:
22+
exclude:
23+
- '^docs:'
24+
- '^test:'

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Stuart Leeks
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,21 @@ fmt:
1818

1919
post-create:
2020
go get -u github.com/kyoh86/richgo
21+
22+
devcontainer: ## (Advanced) Build the devcontainer
23+
docker build -f ./.devcontainer/Dockerfile ./.devcontainer -t wsl-notify-send-devcontainer
24+
25+
devcontainer-release: ## (Advanced) Run the devcontainer for release
26+
ifdef DEVCONTAINER
27+
$(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)
28+
endif
29+
@docker run -v ${PWD}:${PWD} \
30+
-e BUILD_NUMBER="${BUILD_NUMBER}" \
31+
-e IS_CI="${IS_CI}" \
32+
-e IS_PR="${IS_PR}" \
33+
-e BRANCH="${BRANCH}" \
34+
-e GITHUB_TOKEN="${GITHUB_TOKEN}" \
35+
--entrypoint /bin/bash \
36+
--workdir "${PWD}" \
37+
wsl-notify-send-devcontainer \
38+
-c "${PWD}/scripts/ci_release.sh"

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# wsl-notify-send
2+
3+
`wsl-notify-send` provides a Windows executable that is intended to be a replacement for the [Linux `notify-send` utility](https://ss64.com/bash/notify-send.html).
4+
5+
6+
7+
8+
notify-send() { wsl-notify-send.exe --category $WSL_DISTRO_NAME "${@}"; }

gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
wsl-notify-send.exe

main.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
package main
22

33
import (
4+
"fmt"
45
"log"
56

67
"github.com/spf13/cobra"
7-
"gopkg.in/toast.v1"
8+
toast "gopkg.in/toast.v1"
9+
)
10+
11+
// Overridden via ldflags
12+
var (
13+
version = "99.0.1-devbuild"
14+
commit = "unknown"
15+
date = "unknown"
16+
goversion = "unknown"
817
)
918

1019
func main() {
1120
var showHelp bool
21+
var showVersion bool
1222
var icon string
1323
var category string
1424
var appID string
@@ -17,9 +27,12 @@ func main() {
1727
Use: "wslnotify-send",
1828
Short: "wsl-notify-send - a WSL integration for notify-send",
1929
Long: "wsl-notify-send provides a Windows.exe that accepts parameters similar to the Linux notify-send utility to aid interop. For more customisability, see the toast CLI at https://github.com/go-toast/toast",
20-
Args: cobra.ExactArgs(1),
2130
Run: func(cmd *cobra.Command, args []string) {
22-
if showHelp {
31+
if showVersion {
32+
fmt.Printf("wl-notify-send version %s\nBuilt %s (commit %s)\n%s\n\n", version, date, commit, goversion)
33+
return
34+
}
35+
if showHelp || len(args) != 1 { // expect single arg with message
2336
_ = cmd.Usage()
2437
return
2538
}
@@ -45,6 +58,7 @@ func main() {
4558
rootCmd.Flags().StringArrayP("urgency", "u", []string{}, "Ignored in wsl-notify-send")
4659
// Custom flags
4760
rootCmd.Flags().StringVar(&appID, "appId", "wsl-notify-send", "[non-standard] Specifies the app ID")
61+
rootCmd.Flags().BoolVar(&showVersion, "version", false, "Show version information")
4862
_ = rootCmd.Execute()
4963
}
5064

scripts/ci_release.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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/main" ]]; then
14+
echo "On main setting PUBLISH=true"
15+
export PUBLISH=true
16+
else
17+
echo "Skipping publish as is from PR: $PR_NUMBER or not 'refs/heads/main' BRANCH: $BRANCH"
18+
fi
19+
fi
20+
21+
sudo chown -R $(whoami) .
22+
23+
# Set version for release (picked up later by goreleaser)
24+
git tag -f v0.1.$BUILD_NUMBER
25+
26+
export GOVERSION=$(go version)
27+
28+
make lint
29+
30+
if [ -z ${PUBLISH} ]; then
31+
echo "Running with --skip-publish as PUBLISH not set"
32+
goreleaser --skip-publish --rm-dist
33+
else
34+
echo "Publishing release"
35+
goreleaser
36+
fi

0 commit comments

Comments
 (0)