Skip to content

Commit

Permalink
feat: support semantic-release (#18)
Browse files Browse the repository at this point in the history
* feat: support GitHub Actions CI and semantic-release

* feat: support  and semantic-release

* feat: support  and semantic-release

* feat: support  and semantic-release

* feat: support  and semantic-release

* feat: support semantic-release

* feat: support semantic-release

* feat: support semantic-release

* feat: support semantic-release

* feat: support semantic-release

* feat: support semantic-release

* feat: support semantic-release

* feat: support semantic-release

* feat: support semantic-release

* feat: support semantic-release

* feat: support semantic-release

* feat: support semantic-release

* feat: support semantic-release

* feat: support semantic-release

* feat: support semantic-release

* feat: support semantic-release

* feat: support semantic-release

* feat: support semantic-release

* feat: support semantic-release

* feat: support semantic-release

* feat: support semantic-release

* feat: support semantic-release

* feat: support semantic-release

* feat: support semantic-release
  • Loading branch information
palp1tate committed Aug 3, 2023
1 parent fb951c5 commit 0f2da6c
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 0 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web/node_modules/
12 changes: 12 additions & 0 deletions .github/semantic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Always validate the PR title AND all the commits
titleAndCommits: true
# Require at least one commit to be valid
# this is only relevant when using commitsOnly: true or titleAndCommits: true,
# which validate all commits by default
anyCommit: true
# Allow use of Merge commits (eg on github: "Merge branch 'master' into feature/ride-unicorns")
# this is only relevant when using commitsOnly: true (or titleAndCommits: true)
allowMergeCommits: false
# Allow use of Revert commits (eg on github: "Revert "feat: ride unicorns"")
# this is only relevant when using commitsOnly: true (or titleAndCommits: true)
allowRevertCommits: false
94 changes: 94 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Build

on: [ push, pull_request ]

jobs:
coveralls:
name: Test with Coverage
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.16'
- name: Check out code
uses: actions/checkout@v2
- name: Install dependencies
run: |
go mod download
- name: Run Unit tests
run: |
go test -race -covermode atomic -coverprofile=covprofile ./...
- name: Install goveralls
run: go get github.com/mattn/goveralls@latest
- name: Send coverage
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: goveralls -coverprofile=covprofile -service=github

release-and-push:
name: Release And Push
runs-on: ubuntu-latest
if: github.repository == 'casbin/caswaf' && github.event_name == 'push'
needs: [ coveralls ]
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Fetch Previous version
id: get-previous-tag
uses: actions-ecosystem/action-get-latest-tag@v1.6.0

- name: Run semantic-release
run: |
npm install --save-dev semantic-release@17.2.4
npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Fetch Current version
id: get-current-tag
uses: actions-ecosystem/action-get-latest-tag@v1.6.0

- name: Decide Should Push Or Not
id: should_push
run: |
old_version=${{steps.get-previous-tag.outputs.tag}}
new_version=${{steps.get-current-tag.outputs.tag }}
old_array=(${old_version//\./ })
new_array=(${new_version//\./ })
if [ ${old_array[0]} != ${new_array[0]} ]
then
echo ::set-output name=push::'true'
elif [ ${old_array[1]} != ${new_array[1]} ]
then
echo ::set-output name=push::'true'
else
echo ::set-output name=push::'false'
fi
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up buildx
id: buildx
uses: docker/setup-buildx-action@v2
with:
version: latest

- name: Log in to Docker Hub
uses: docker/login-action@v1
if: github.repository == 'casbin/caswaf' && github.event_name == 'push' && steps.should_push.outputs.push=='true'
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Push to Docker Hub
uses: docker/build-push-action@v3
if: github.repository == 'casbin/caswaf' && github.event_name == 'push' && steps.should_push.outputs.push=='true'
with:
target: STANDARD
platforms: linux/amd64
push: true
tags: casbin/caswaf:${{steps.get-current-tag.outputs.tag }},casbin/caswaf:latest
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Node.js CI

on:
pull_request

jobs:
deploy:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [ 16.x ]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: yarn install

- name: Build website
run: yarn build --locale en
23 changes: 23 additions & 0 deletions .releasec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"debug": true,
"branches": [
"+([0-9])?(.{+([0-9]),x}).x",
"master",
{
"name": "rc"
},
{
"name": "beta",
"prerelease": true
},
{
"name": "alpha",
"prerelease": true
}
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/github"
]
}
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM node:16.18.0 AS FRONT
WORKDIR /web
COPY ./web .
RUN yarn config set registry https://registry.npmmirror.com
RUN yarn install --frozen-lockfile --network-timeout 1000000 && yarn run build

FROM golang:1.19.9 AS BACK
WORKDIR /go/src/caswaf
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o server . \
&& apt update && apt install wait-for-it && chmod +x /usr/bin/wait-for-it

FROM alpine:latest AS STANDARD
LABEL MAINTAINER="https://waf.casbin.com/"

COPY --from=BACK /go/src/caswaf/ ./
COPY --from=BACK /usr/bin/wait-for-it ./
RUN mkdir -p web/build && apk add --no-cache bash coreutils
COPY --from=FRONT /web/build /web/build
ENTRYPOINT ["./wait-for-it", "db:3306 ", "--", "./server"]

22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: '3.1'
services:
caswaf:
build:
context: ./
dockerfile: Dockerfile
ports:
- "17000:17000"
depends_on:
- db
command: ["./wait-for-it db:3306 -- ./server"]
volumes:
- ./conf:/conf/
db:
restart: always
image: mysql:8.0.25
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: 123
volumes:
- /usr/local/docker/mysql:/var/lib/mysql

0 comments on commit 0f2da6c

Please sign in to comment.