Skip to content

Commit

Permalink
ci- circleci -> github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
nektro committed Apr 17, 2022
1 parent 9664594 commit 92f17d4
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 61 deletions.
31 changes: 0 additions & 31 deletions .circleci/config.yml

This file was deleted.

61 changes: 61 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: CI

on:
push:
branches: [master]

jobs:
release:
runs-on: ubuntu-latest

steps:
# debug info about this machine
- run: uname -a
- run: free
- run: env
- run: mount
- run: lscpu
- run: lsmem
- run: lsblk
- run: lspci
- run: lsipc
- run: whoami

# Get the code
- uses: actions/checkout@v2
with:
fetch-depth: 0
- run: git fetch --all --tags
- run: top -b -n 1 | head -n5

# Go
- uses: actions/setup-go@v2
- run: go version
- run: go env
- run: go get -v .
- run: go build
- run: ./build_all.sh

# # Zig
- uses: goto-bus-stop/setup-zig@v1
with:
version: "0.10.0-dev.1860+7b090df66"
- run: zig version
- run: zig env
- uses: nektro/actions-setup-zigmod@v1
- run: zigmod version

# Github Release
- run: ./changelog.sh
- run: zigmod aq install 1/nektro/ghr
- run: ./make_release.sh ${{ secrets.GITHUB_TOKEN }}

# Docker image
- run: echo "RELEASE_NUM=$(./release_num.sh)" >> $GITHUB_ENV
- run: echo ${{ env.RELEASE_NUM }}
- uses: docker/build-push-action@v1
with:
username: nektro
password: ${{ secrets.DOCKER_HUB_TOKEN }}
repository: ${{ env.GITHUB_REPOSITORY }}
tags: latest,r${{ env.RELEASE_NUM }}
18 changes: 2 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
FROM golang:alpine as golang
WORKDIR /app
COPY . .
ARG BUILD_NUM
RUN apk add --no-cache git libc-dev musl-dev build-base gcc ca-certificates \
&& export GO_VERSION=$(go version | cut -d' ' -f3) \
&& export VCS_REF="v${BUILD_NUM}-docker-$GO_VERSION" \
&& echo $VCS_REF \
&& go get -v . \
&& go install -v github.com/rakyll/statik \
&& $GOPATH/bin/statik -src="./www/" \
&& CGO_ENABLED=1 go build -ldflags "-s -w -X main.Version=$VCS_REF" .

FROM alpine
COPY --from=golang /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=golang /app/mantle /app/mantle

WORKDIR /app
COPY ./bin/mantle-linux-amd64 /app/mantle
VOLUME /data
ENTRYPOINT ["/app/mantle", "--port", "8000", "--config", "/data/config.json"]
10 changes: 4 additions & 6 deletions build_go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ export CGO_ENABLED=1
export GOOS=$1
export GOARCH=$2
export GOARM=7
ext=$3
date=$(date +'%Y%m%d')
version=${CIRCLE_BUILD_NUM-$date}
tag=v$version
echo $tag-$GOOS-$GOARCH
go build -ldflags="-s -w -X main.Version=$tag" -o ./bin/mantle-$tag-$GOOS-$GOARCH$ext
tag="r$(./release_num.sh)"
rev=$(git log --format=%h -1)
echo "$tag.$rev $GOOS $GOARCH"
go build -ldflags="-s -w -X main.Version=$tag" -o ./bin/mantle-$GOOS-$GOARCH$ext
5 changes: 4 additions & 1 deletion changelog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

set -e

PROJECT_USERNAME=$(echo $GITHUB_REPOSITORY | cut -d'/' -f1)
PROJECT_REPONAME=$(echo $GITHUB_REPOSITORY | cut -d'/' -f2)

read-log() {
git log --format=format:"%h%n%H%n%an%n%s%n%d%n"
}
Expand Down Expand Up @@ -34,7 +37,7 @@ while IFS= read -r lineVAR; do
if [[ "$t" == '2' ]]; then
break
fi
echo "<li><a href='https://github.com/nektro/$CIRCLE_PROJECT_REPONAME/commit/$hash'><code>$hash_abrev</code></a> $title ($author)</li>"
echo "<li><a href='https://github.com/$PROJECT_USERNAME/$PROJECT_REPONAME/commit/$hash'><code>$hash_abrev</code></a> $title ($author)</li>"
fi
c=$(($c+1))
#
Expand Down
18 changes: 11 additions & 7 deletions make_release.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#!/usr/bin/env bash

date=$(date +'%Y%m%d')
version=${CIRCLE_BUILD_NUM-$date}
tag=v$version
go get -v -u github.com/tcnksm/ghr
$GOPATH/bin/ghr \
set -e

tag=r$(./release_num.sh)

GITHUB_TOKEN="$1"
PROJECT_USERNAME=$(echo $GITHUB_REPOSITORY | cut -d'/' -f1)
PROJECT_REPONAME=$(echo $GITHUB_REPOSITORY | cut -d'/' -f2)

~/.zigmod/bin/ghr \
-t ${GITHUB_TOKEN} \
-u ${CIRCLE_PROJECT_USERNAME} \
-r ${CIRCLE_PROJECT_REPONAME} \
-u ${PROJECT_USERNAME} \
-r ${PROJECT_REPONAME} \
-b "$(./changelog.sh)" \
"$tag" \
"./bin/"
8 changes: 8 additions & 0 deletions release_num.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -e

tagcount=$(git tag | wc -l)
tagcount=$((tagcount+1))

echo $tagcount

0 comments on commit 92f17d4

Please sign in to comment.