Skip to content

Commit d158e64

Browse files
Move CI pipeline to Github actions (#70)
1 parent a014df5 commit d158e64

File tree

11 files changed

+214
-197
lines changed

11 files changed

+214
-197
lines changed

.github/workflows/build.yml

+173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches: [ develop, master ]
6+
pull_request:
7+
branches: [ develop ]
8+
release:
9+
types: [ published ]
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-20.04
14+
15+
services:
16+
postgres:
17+
image: postgres:13.2
18+
env:
19+
POSTGRES_DB: postgres
20+
POSTGRES_PASSWORD: postgres
21+
POSTGRES_USER: postgres
22+
ports:
23+
- 5432:5432
24+
# Set health checks to wait until postgres has started
25+
options: >-
26+
--health-cmd pg_isready
27+
--health-interval 10s
28+
--health-timeout 5s
29+
--health-retries 5
30+
31+
steps:
32+
- uses: actions/checkout@v2
33+
34+
- name: Install Go
35+
uses: actions/setup-go@v2
36+
with:
37+
go-version: 1.16.x
38+
39+
- name: Install Node
40+
uses: actions/setup-node@v2
41+
with:
42+
node-version: '14'
43+
44+
- name: Checkout
45+
run: git fetch --prune --unshallow --tags
46+
47+
- name: Cache node modules
48+
uses: actions/cache@v2
49+
env:
50+
cache-name: cache-node_modules
51+
with:
52+
path: frontend/node_modules
53+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('frontend/yarn.lock') }}
54+
55+
- name: Cache UI build
56+
uses: actions/cache@v2
57+
id: cache-ui
58+
env:
59+
cache-name: cache-ui
60+
with:
61+
path: ui/v2.5/build
62+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('frontend/yarn.lock', 'frontend/public/**', 'frontend/src/**', 'graphql/**/*.graphql') }}
63+
64+
- name: Cache go build
65+
uses: actions/cache@v2
66+
env:
67+
cache-name: cache-go-cache
68+
with:
69+
path: .go-cache
70+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/go.sum') }}
71+
72+
- name: Pre-install
73+
run: make pre-ui
74+
75+
- name: Validate UI
76+
# skip UI validation for pull requests if UI is unchanged
77+
if: ${{ github.event_name != 'pull_request' || steps.cache-ui.outputs.cache-hit != 'true' }}
78+
run: make ui-validate
79+
80+
- name: Generate
81+
run: make generate
82+
83+
- name: Run tests
84+
run: POSTGRES_DB=postgres:postgres@localhost/postgres?sslmode=disable make vet it
85+
86+
- name: Build UI
87+
# skip UI build for pull requests if UI is unchanged (UI was cached)
88+
# this means that the build version/time may be incorrect if the UI is
89+
# not changed in a pull request
90+
if: ${{ github.event_name != 'pull_request' || steps.cache-ui.outputs.cache-hit != 'true' }}
91+
run: make ui-only
92+
93+
- name: Login to DockerHub
94+
uses: docker/login-action@v1
95+
with:
96+
username: ${{ secrets.DOCKERHUB_USERNAME }}
97+
password: ${{ secrets.DOCKERHUB_TOKEN }}
98+
99+
- name: Crosscompile binaries
100+
run: make cross-compile
101+
102+
- name: Generate checksums
103+
run: |
104+
git describe --tags --exclude latest_develop | tee CHECKSUMS_SHA1
105+
sha1sum dist/*/stash-box-* | sed 's/dist\/.*\///g' | tee -a CHECKSUMS_SHA1
106+
echo "STASH_BOX_VERSION=$(git describe --tags --exclude latest_develop)" >> $GITHUB_ENV
107+
echo "RELEASE_DATE=$(date +'%Y-%m-%d %H:%M:%S %Z')" >> $GITHUB_ENV
108+
109+
- name: Upload Windows binary
110+
# only upload binaries for pull requests
111+
if: ${{ github.event_name == 'pull_request' && github.base_ref != 'refs/heads/develop' && github.base_ref != 'refs/heads/master'}}
112+
uses: actions/upload-artifact@v2
113+
with:
114+
name: stash-box-win.exe
115+
path: dist/stash-box_windows_amd64/stash-box-windows.exe
116+
- name: Upload OSX binary
117+
# only upload binaries for pull requests
118+
if: ${{ github.event_name == 'pull_request' && github.base_ref != 'refs/heads/develop' && github.base_ref != 'refs/heads/master'}}
119+
uses: actions/upload-artifact@v2
120+
with:
121+
name: stash-box-darwin
122+
path: dist/stash-box_darwin_amd64/stash-box-darwin
123+
- name: Upload Linux binary
124+
# only upload binaries for pull requests
125+
if: ${{ github.event_name == 'pull_request' && github.base_ref != 'refs/heads/develop' && github.base_ref != 'refs/heads/master'}}
126+
uses: actions/upload-artifact@v2
127+
with:
128+
name: stash-box-linux
129+
path: dist/stash-box_linux_amd64/stash-box-linux
130+
131+
- name: Update latest_develop tag
132+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/develop' }}
133+
run : git tag -f latest_develop; git push -f --tags
134+
- name: Development Release
135+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/develop' }}
136+
uses: meeDamian/[email protected]
137+
with:
138+
token: "${{ secrets.GITHUB_TOKEN }}"
139+
prerelease: true
140+
allow_override: true
141+
tag: latest_develop
142+
name: "${{ env.STASH_BOX_VERSION }}: Latest development build"
143+
body: "**${{ env.RELEASE_DATE }}**\n This is always the latest committed version on the develop branch. Use as your own risk!"
144+
files: |
145+
dist/stash-box_windows_amd64/stash-box-windows.exe
146+
dist/stash-box_linux_amd64/stash-box-linux
147+
dist/stash-box_darwin_amd64/stash-box-darwin
148+
CHECKSUMS_SHA1
149+
gzip: false
150+
- name: Master release
151+
if: ${{ github.event_name == 'release' && github.ref != 'refs/tags/latest_develop' }}
152+
uses: meeDamian/[email protected]
153+
with:
154+
token: "${{ secrets.GITHUB_TOKEN }}"
155+
allow_override: true
156+
files: |
157+
dist/stash-box_windows_amd64/stash-box-windows.exe
158+
dist/stash-box_linux_amd64/stash-box-linux
159+
dist/stash-box_darwin_amd64/stash-box-darwin
160+
CHECKSUMS_SHA1
161+
gzip: false
162+
163+
- name: Development Docker
164+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/develop' }}
165+
run: |
166+
docker build -t stashapp/stash-box:development -f ./docker/ci/x86_64/Dockerfile ./dist
167+
docker push stashapp/stash-box:development
168+
169+
- name: Release Docker
170+
if: ${{ github.event_name == 'release' && github.ref != 'refs/tags/latest_develop' }}
171+
run: |
172+
docker build -t stashapp/stash-box:latest -f ./docker/ci/x86_64/Dockerfile ./dist
173+
docker push stashapp/stash-box:latest

.goreleaser.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
project_name: stash-box
2+
builds:
3+
- id: stash-box
4+
binary: stash-box-{{.Os}}
5+
goos:
6+
- windows
7+
- linux
8+
- darwin
9+
goarch:
10+
- amd64
11+
ldflags:
12+
- -X github.com/stashapp/stash-box/pkg/api.version={{.Version}} -X github.com/stashapp/stash-box/pkg/api.buildstamp={{.Date}} -X github.com/stashapp/stash-box/pkg/api.githash={{.ShortCommit}}
13+
14+
archives:
15+
- format: binary

.travis.yml

-102
This file was deleted.

Makefile

+14-33
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,8 @@
1-
IS_WIN =
2-
ifeq (${SHELL}, sh.exe)
3-
IS_WIN = true
4-
endif
5-
ifeq (${SHELL}, cmd)
6-
IS_WIN = true
7-
endif
8-
9-
ifdef IS_WIN
10-
SEPARATOR := &&
11-
SET := set
12-
else
13-
SEPARATOR := ;
14-
SET := export
15-
endif
16-
17-
# set LDFLAGS environment variable to any extra ldflags required
18-
# set OUTPUT to generate a specific binary name
19-
201
LDFLAGS := $(LDFLAGS)
212
ifdef OUTPUT
223
OUTPUT := -o $(OUTPUT)
234
endif
245

25-
.PHONY: release pre-build install clean
26-
27-
release: generate ui build-release
28-
296
pre-build:
307
ifndef BUILD_DATE
318
$(eval BUILD_DATE := $(shell go run scripts/getDate.go))
@@ -40,16 +17,7 @@ ifndef STASH_BOX_VERSION
4017
endif
4118

4219
build: pre-build
43-
$(eval LDFLAGS := $(LDFLAGS) -X 'github.com/stashapp/stash-box/pkg/api.version=$(STASH_BOX_VERSION)' -X 'github.com/stashapp/stash-box/pkg/api.buildstamp=$(BUILD_DATE)' -X 'github.com/stashapp/stash-box/pkg/api.githash=$(GITHASH)')
44-
$(SET) CGO_ENABLED=1 $(SEPARATOR) go build $(OUTPUT) -v -tags "osusergo netgo" -ldflags "$(LDFLAGS) $(EXTRA_LDFLAGS)"
45-
46-
# strips debug symbols from the release build
47-
# consider -trimpath in go build if we move to go 1.13+
48-
build-release: EXTRA_LDFLAGS := -s -w
49-
build-release: build
50-
51-
build-release-static: EXTRA_LDFLAGS := -extldflags=-static -s -w
52-
build-release-static: build
20+
go build $(OUTPUT) -v -ldflags "-X 'github.com/stashapp/stash-box/pkg/api.version=$(STASH_BOX_VERSION)' -X 'github.com/stashapp/stash-box/pkg/api.buildstamp=$(BUILD_DATE)' -X 'github.com/stashapp/stash-box/pkg/api.githash=$(GITHASH)'"
5321

5422
install:
5523
packr2 install
@@ -119,3 +87,16 @@ ui: ui-only
11987
.PHONY: packr
12088
packr:
12189
packr2
90+
91+
# runs tests and checks on the UI and builds it
92+
.PHONY: ui-validate
93+
ui-validate:
94+
cd frontend && yarn run validate
95+
96+
.PHONY: cross-compile
97+
cross-compile:
98+
docker run --rm --privileged \
99+
-v $(PWD):/go/src/github.com/stashapp/stash-box \
100+
-v /var/run/docker.sock:/var/run/docker.sock \
101+
-w /go/src/github.com/stashapp/stash-box \
102+
goreng/golang-cross:latest --snapshot --rm-dist

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Before building the binary the frontend project needs to be built.
2828

2929
Stash-box requires access to a postgres database server. When stash-box is first run, or when it cannot find a configuration file (defaulting to `stash-box-config.yml` in the current working directory), then it generates a new configuration file with a default postgres connection string (`postgres@localhost/stash-box?sslmode=disable`). It prints a message indicating that the configuration file is generated, and allows you to adjust the default connection string as needed.
3030

31-
The database must be created and available, and `CREATE EXTENSION pg_trgm;` needs to be run by a superuser in the database before rerunning stash-box. The schema will be created within the database if it is not already present.
31+
The database must be created and available. If the postgres user is not a superuser, `CREATE EXTENSION pg_trgm;` needs to be run by a superuser before rerunning stash-box, otherwise you will get a migration error. The schema will be created within the database if it is not already present.
3232

3333
The `sslmode` parameter is documented in the [pq documentation](https://godoc.org/github.com/lib/pq). Use `sslmode=disable` to not use SSL for the database connection. The default value is `require`.
3434

docker/ci/x86_64/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
FROM alpine as app
55
LABEL MAINTAINER="https://discord.gg/Uz29ny"
66

7-
COPY /stash-box-linux /usr/bin/stash-box
7+
COPY stash-box_linux_amd64/stash-box-linux /usr/bin/stash-box
88

99
EXPOSE 9998
1010
CMD ["stash-box", "--config_file", "/root/.stash-box/stash-box-config.yml"]

0 commit comments

Comments
 (0)