Skip to content

Commit

Permalink
Merge pull request #4 from leo220yuyaodog/master
Browse files Browse the repository at this point in the history
feat: add semantic release
  • Loading branch information
leo220yuyaodog authored Mar 12, 2024
2 parents 18b028e + 59c9318 commit b7e361f
Showing 1 changed file with 41 additions and 38 deletions.
79 changes: 41 additions & 38 deletions .github/workflows/build-docker.yaml
Original file line number Diff line number Diff line change
@@ -1,54 +1,57 @@
name: Docker image

on:
push:
branches:
- master
on: [push, pull_request]

jobs:
build:
# if: github.repository == 'casvisor/dbgate' && github.event_name == 'push'
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-22.04]

steps:
- name: Context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
fetch-depth: -1
- name: Setup Node.js
uses: actions/setup-node@v3
with:
images: |
casbin/dbgate
flavor: |
latest=false
tags: |
type=raw,value=beta,enable=${{ contains(github.ref_name, '-docker.') || contains(github.ref_name, '-beta.') }}
node-version: 18

type=match,pattern=\d+.\d+.\d+,enable=${{ !contains(github.ref_name, '-docker.') && !contains(github.ref_name, '-beta.') }}
type=raw,value=latest,enable=${{ !contains(github.ref_name, '-docker.') && !contains(github.ref_name, '-beta.') }}
- name: Fetch Previous version
id: get-previous-tag
uses: actions-ecosystem/[email protected]

- name: Docker alpine meta
id: alpmeta
uses: docker/metadata-action@v4
with:
images: |
casbin/dbgate
flavor: |
latest=false
tags: |
type=raw,value=beta-alpine,enable=${{ contains(github.ref_name, '-docker.') || contains(github.ref_name, '-beta.') }}
- name: Release
run: yarn global add [email protected] && semantic-release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Fetch Current version
id: get-current-tag
uses: actions-ecosystem/[email protected]

- 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//\./ })
type=match,pattern=\d+.\d+.\d+,suffix=-alpine,enable=${{ !contains(github.ref_name, '-docker.') && !contains(github.ref_name, '-beta.') }}
type=raw,value=alpine,enable=${{ !contains(github.ref_name, '-docker.') && !contains(github.ref_name, '-beta.') }}
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: Use Node.js 16.x
uses: actions/setup-node@v1
Expand All @@ -75,20 +78,20 @@ jobs:
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Build and push
if: github.repository == 'casvisor/dbgate' && github.event_name == 'push'
if: steps.should_push.outputs.push == 'true'
uses: docker/build-push-action@v3
with:
push: true
context: ./docker
tags: ${{ steps.meta.outputs.tags }}
tags: casbin/dbgate:${{steps.get-current-tag.outputs.tag }},casbin/dbgate:latest
platforms: linux/amd64,linux/arm64,linux/arm/v7

- name: Build and push alpine
if: github.repository == 'casvisor/dbgate' && github.event_name == 'push'
if: steps.should_push.outputs.push == 'true'
uses: docker/build-push-action@v3
with:
push: true
context: ./docker
file: ./docker/Dockerfile-alpine
tags: ${{ steps.alpmeta.outputs.tags }}
tags: casbin/dbgate:${{steps.get-current-tag.outputs.tag }}-alpine
platforms: linux/amd64,linux/arm64,linux/arm/v7

0 comments on commit b7e361f

Please sign in to comment.