Skip to content

Commit

Permalink
chore: Add workflow file
Browse files Browse the repository at this point in the history
  • Loading branch information
sirateek committed Apr 22, 2023
1 parent 6347f46 commit a38286d
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Build Docker Image and Release Github

on:
push:
branches: ["master"]

jobs:
release-on-github:
runs-on: ubuntu-latest
outputs:
newTag: ${{ steps.semver_rel.outputs.new_tag }}
previousTag: ${{ steps.semver_rel.outputs.previous_tag }}
changeLogs: ${{ steps.github_release.outputs.changelog }}
steps:
# Fetch all repository details (Including tag for semver).
- uses: actions/checkout@v3
with:
fetch-depth: 0

# Determan new version by using Semver logic.
- name: Semver Release
id: semver_rel
uses: hennejg/github-tag-action@v4.3.1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

# Generate Change Log
- name: Release Changelog Builder
id: github_release
uses: mikepenz/release-changelog-builder-action@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
fromTag: ${{ steps.semver_rel.outputs.previous_tag }}
toTag: ${{ steps.semver_rel.outputs.new_tag }}

# Create a release on Github Repo.
- name: Create Release
uses: mikepenz/action-gh-release@v0.2.0-a03 #softprops/action-gh-release
with:
body: ${{ steps.github_release.outputs.changelog }}
tag_name: ${{ steps.semver_rel.outputs.new_tag }}

build-docker-image-matrix:
runs-on: ubuntu-latest
needs: release-on-github
strategy:
matrix:
apps: ["gb-tag-create-consumer", "gb-tag-delete-consumer"]
steps:
# Fetch all repository details (Including tag for semver).
- uses: actions/checkout@v3
with:
fetch-depth: 0

# Check if the watched path is updated.
- name: Get changed files in the docs folder
id: changed-files-specific
uses: tj-actions/changed-files@v32
with:
files: |
cmd/${{ matrix.apps }}/**
Dockerfiles/**
pkg/**
# Generate Dockerfile
- name: Generate Docker file from Template
run: |
./Dockerfiles/render.sh
env:
BUILD_APP: ${{ matrix.apps }}

# Setup SSH Private Key
- uses: webfactory/ssh-agent@v0.5.4
if: steps.changed-files-specific.outputs.any_changed == 'true'
with:
ssh-private-key: ${{ secrets.SSH_COMMON_GO_PRIVATE_KEY }}

# Login to DockerHub by using the credentials.
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

# Setup BuildX
- name: Set up Docker Buildx
if: steps.changed-files-specific.outputs.any_changed == 'true'
uses: docker/setup-buildx-action@v2

# Build Docker Image and push to docker hub.
- name: Build and push Docker image
if: steps.changed-files-specific.outputs.any_changed == 'true'
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ${{ format('ghcr.io/garnbarn/{0}:{1}', matrix.apps, needs.release-on-github.outputs.newTag) }},${{ format('ghcr.io/garnbarn/{0}:latest', matrix.apps) }}
github-token: ${{ secrets.GITHUB_TOKEN }}
platforms: |
linux/amd64
linux/arm64
ssh: |
default

0 comments on commit a38286d

Please sign in to comment.