1
0
Fork 0

Add workflows

upload-progress
Ambrose Chua 2021-05-24 00:25:48 +08:00
parent 22ae840871
commit acd2f031f9
4 changed files with 159 additions and 1 deletions

89
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,89 @@
name: Go
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.16
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Test code
run: make test
vet:
name: Vet
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.16
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Vet code
run: go vet ./...
format:
name: Format
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.16
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Set Git user
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
- name: Format code
run: gofmt -l -w -s .
- name: Commit and push changes
run: |
git add .
if output=$(git status --porcelain) && [ ! -z "$output" ]; then
git commit -m "[Action] go fmt" -a
git push
fi
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.16
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Build
run: make TAGS=production
# vim: set et ts=2 sw=2:

39
.github/workflows/publish.yml vendored Normal file
View File

@ -0,0 +1,39 @@
name: Deploy
on:
push:
branches: [ main ]
jobs:
publish:
name: Publish
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Docker Login
uses: docker/login-action@v1.6.0
with:
registry: ghcr.io
username: $GITHUB_ACTOR
password: ${{ secrets.CR_PAT }}
- name: Build and push Docker images
uses: docker/build-push-action@v2.1.0
with:
pull: true
platforms: linux/amd64
push: true
tags: ghcr.io/serverwentdown/upl:latest
# vim: set et ts=2 sw=2:

View File

@ -13,7 +13,7 @@ ARG CGO_ENABLED=0
WORKDIR /src
COPY --from=build-web . .
RUN go build -ldflags="-s -w" -v
RUN make TAGS=production
FROM scratch

30
Makefile Normal file
View File

@ -0,0 +1,30 @@
GO = go
NPM = npm
.PHONY: all
all: web build
.PHONY: clean
clean:
$(RM) -r upl web/assets
.PHONY: build
build: upl
upl: *.go web/*.tmpl
$(GO) build -ldflags="-s -w" -tags "$(TAGS)" -v -o upl
.PHONY: test
test: data
$(GO) test -cover -bench=. -v ./...
.PHONY: web
web: web/assets/bundle.js
web/node_modules:
cd web && $(NPM) install
web/assets/bundle.js: web/node_modules
cd web && $(NPM) run build