Skip to content

Commit

Permalink
chore: add ci
Browse files Browse the repository at this point in the history
  • Loading branch information
soulteary committed Jun 12, 2022
1 parent 599e9ab commit 20c1a16
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 18 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Release

on:
workflow_dispatch:
push:
branches:
- 'main'
tags:
- 'v*'

jobs:
build:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.18
-
name: Cache Go modules
uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
-
name: Tests
run: |
go mod tidy
go test -v ./...
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
if: success() && startsWith(github.ref, 'refs/tags/')
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26 changes: 26 additions & 0 deletions .github/workflows/scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "Security Scan"

# Run workflow each time code is pushed to your repository and on a schedule.
# The scheduled workflow runs every at 00:00 on Sunday UTC time.
on:
push:
pull_request:
schedule:
- cron: '0 0 * * 0'

jobs:
scan:
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Security Scan
uses: securego/gosec@master
with:
# we let the report trigger content trigger a failure using the GitHub Security features.
args: '-no-fail -fmt sarif -out results.sarif ./...'
- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v2
with:
# Path to SARIF file relative to the root of the repository
sarif_file: results.sarif
24 changes: 24 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
project_name: apt-proxy
builds:
- env: [CGO_ENABLED=0]
goos:
- linux
- darwin
goarch:
- amd64
- arm64
dockers:
- image_templates:
- "soulteary/apt-proxy:latest"
- "soulteary/apt-proxy:{{ .Tag }}"
dockerfile: docker/Dockerfile.gorelease
build_flag_templates:
- "--pull"
- --label=org.opencontainers.image.title={{ .ProjectName }}
- --label=org.opencontainers.image.description={{ .ProjectName }}
- --label=org.opencontainers.image.url=https://github.com/soulteary/apt-proxy
- --label=org.opencontainers.image.source=https://github.com/soulteary/apt-proxy
- --label=org.opencontainers.image.version={{ .Version }}
- --label=org.opencontainers.image.created={{ .Date }}
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.licenses=Apache-v2
10 changes: 9 additions & 1 deletion cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
)

func TestParseFlags(t *testing.T) {
func TestParseFlagsAndDaemonInit(t *testing.T) {
os.Args = append(os.Args, "--type=not-support-os")
flags := ParseFlags()

Expand All @@ -28,4 +28,12 @@ func TestParseFlags(t *testing.T) {
if flags.CacheDir != DEFAULT_CACHE_DIR {
t.Fatal("Default option `CacheDir` value mismatch")
}

cache, err := initStore(flags)
if err != nil {
t.Fatal("Init Store Failed")
}

ap := initProxy(flags, cache)
initLogger(flags, ap)
}
17 changes: 0 additions & 17 deletions cli/daemon_test.go

This file was deleted.

8 changes: 8 additions & 0 deletions docker/Dockerfile.gorelease
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM alpine:3.15.0 as certs
RUN apk --update add ca-certificates

FROM scratch
COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY apt-proxy /usr/bin/apt-proxy
EXPOSE 8345/tcp
ENTRYPOINT ["/usr/bin/apt-proxy"]

0 comments on commit 20c1a16

Please sign in to comment.