Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ruby workflow #17

Merged
merged 8 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 152 additions & 0 deletions .github/workflows/ruby_app_pull_requests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
name: Pull Request

on:
workflow_call:
inputs:
DATABASE_ADAPTER:
description: 'Database adapter for Postgres test step service'
required: true
type: string
default: postgresql
DATABASE_NAME:
description: 'Database name for Postgres test step service'
required: true
type: string
default: thalamus_test
DATABASE_USERNAME:
description: 'User for Postgres test step service'
required: true
type: string
default: postgres
DATABASE_HOST:
description: 'Database host for Postgres test step service'
required: true
type: string
default: localhost
SQL_PATH:
description: 'SQL path to import Postgres test step service'
required: true
type: string
default: db/structure.sql
secrets:
DATABASE_PASSWORD:
description: 'Database password for Postgres test step service'
required: true

jobs:
commitlint:
#
# ensures commit messages follow conventional commits
#
runs-on: ubuntu-latest
steps:
# checkout the commits to lint.
- uses: actions/checkout@v3
with:
fetch-depth: 0
# setup node, needed to lint commits.
- uses: actions/setup-node@v1
with:
node-version: 18
# Install needed libraries to lint commits.
- run: npm install --save-dev @commitlint/{config-conventional,cli}
# Lint the commits.
- run: npx commitlint --from=${{ github.event.pull_request.base.sha }}

# codelint:
# #
# # ensure ruby/rails code standards
# #
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - uses: ruby/setup-ruby@477b21f02be01bcb8030d50f37cfec92bfa615b6
# with:
# bundler-cache: true
# - run: bundle install
# - name: Rubocop
# run: bundle exec rubocop

test:
#
# ensure ruby standards and tests pass
#
runs-on: ubuntu-latest

services:
database:
image: postgres:12.3
env:
POSTGRES_PASSWORD: th4l4mus
ports:
- 5432:5432

redis:
image: redis:5.0.7
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379

elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.8.6
ports:
- 9200:9200

steps:
# Checkout ruby code to test.
- name: Checkout repo
uses: actions/checkout@v3
# Setup Ruby, by default uses .ruby-version file.
- name: Setup up Ruby
uses: ruby/setup-ruby@477b21f02be01bcb8030d50f37cfec92bfa615b6
with:
bundler-cache: true
- name: Install dependencies
run: bundle install
- name: Setup database
run: psql -h ${{ inputs.DATABASE_HOST }} -U ${{ inputs.DATABASE_USERNAME }} -c 'CREATE DATABASE "thalamus_test";'
env:
PGPASSWORD: '${{ secrets.DATABASE_PASSWORD }}'
- name: Prepare test database
run: psql -h ${{ inputs.DATABASE_HOST }} -U ${{ inputs.DATABASE_USERNAME }} -d ${{ inputs.DATABASE_NAME }} < ${{ inputs.SQL_PATH }}
env:
PGPASSWORD: '${{ secrets.DATABASE_PASSWORD }}'
- name: Run tests
run: bundle exec rspec spec

docker-build:
#
# ensures the docker image will build without pushing to the registry
# uses the git sha for the most recent commit for the version
#
runs-on: ubuntu-latest
steps:
# Checkout code to build.
- name: Checkout repo
uses: actions/checkout@v3
# Setup docker build arguments.
- name: Docker release meta
id: release
uses: docker/metadata-action@v4
with:
images: |
${{ github.repository }}
tags: |
type=sha
# Setup Docker builder to do build.
- name: Setup Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
# Build the app.
- name: Build
uses: docker/build-push-action@v3
with:
push: false
context: .
file: Dockerfile
platforms: linux/amd64
tags: ${{ steps.release.outputs.tags }}
39 changes: 39 additions & 0 deletions .github/workflows/ruby_app_push_main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Create Github Release

on:
workflow_call:
secrets:
GH_CI_PAT:
description: 'Token password for GitHub auth'
required: true

jobs:
release:
#
# Create a GitHub Release based on conventional commits.
#
name: 'Release to GitHub'
runs-on: ubuntu-latest
steps:
# Checkout code to release.
- name: Checkout repo
uses: actions/checkout@v3
# Setup Node needed to create release.
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 18
# Add plugin to make the changelog for the release.
- name: Add plugin for conventional commits
run: npm install conventional-changelog-conventionalcommits
working-directory: ./.github/workflows
# Create the release.
- name: Release to GitHub
working-directory: ./.github/workflows
env:
GITHUB_TOKEN: ${{ secrets.GH_CI_PAT }}
GIT_AUTHOR_NAME: release-bot
GIT_AUTHOR_EMAIL: release@test.com
GIT_COMMITTER_NAME: asyncapi-bot
GIT_COMMITTER_EMAIL: info@asyncapi.io
run: npx semantic-release
112 changes: 112 additions & 0 deletions .github/workflows/ruby_app_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: Release Docker Version

on:
workflow_call:
inputs:
GH_CI_USER:
description: 'User for GitHub auth'
required: true
type: string
secrets:
GH_CI_PAT:
description: 'Token password for GitHub auth'
required: true

# Registry arguments.
# Must supply set of arguments for at least 1 registry.

# Artifact Registry arguments
ARTIFACT_REGISTRY:
description: 'Artifact Registry address to which to publish (leave blank to not publish)'
required: false
ARTIFACT_REGISTRY_JSON_KEY:
description: 'Key for publishing to Artifact Registry'
required: false
# Container Registry arguements
CONTAINER_REGISTRY:
description: 'Container Registry address to which to publish (leave blank to not publish)'
required: false
CONTAINER_REGISTRY_JSON_KEY:
description: 'Key for publishing to Container Registry'
required: false

jobs:
push:
#
# Build the Docker image artifact and deliver it.
#
runs-on: ubuntu-latest
steps:
# Checkout code needed to build docker image.
- uses: actions/checkout@v3
# Parse GitHub repository name for use in constructing docker image names.
- name: Parse Repo Name
id: parse_repo_name
run: |
echo "repo_name=$( echo '${{ github.repository }}' | awk -F '/' '{print $2}' )" >> $GITHUB_OUTPUT
# Make the docker fields for Artifact Registry if we're pushing to it.
- name: Construct Artifact Registry fields
env:
ARTIFACT_REGISTRY: ${{ secrets.ARTIFACT_REGISTRY }}
if: ${{ env.ARTIFACT_REGISTRY }}
run: |
echo "ARTIFACT_REGISTRY_IMAGE_NAME=${{ secrets.ARTIFACT_REGISTRY }}/${{ github.repository }}" >> $GITHUB_ENV
# Make the docker fields for Container Registry if we're pushing to it.
- name: Construct Container Registry fields
env:
CONTAINER_REGISTRY: ${{ secrets.CONTAINER_REGISTRY }}
if: ${{ env.CONTAINER_REGISTRY }}
run: |
echo "CONTAINER_REGISTRY_IMAGE_NAME=${{ secrets.CONTAINER_REGISTRY }}/${{ steps.parse_repo_name.outputs.repo_name }}" >> $GITHUB_ENV
# Create docker image meta data. Docker tags include the Git tag itself and the sematic version parsing of that tag if possible.
- name: Docker release meta
id: release
uses: docker/metadata-action@v4
with:
images: |
${{ env.ARTIFACT_REGISTRY_IMAGE_NAME }}
${{ env.CONTAINER_REGISTRY_IMAGE_NAME }}
flavor: |
latest=false
tags: |
type=ref,event=tag
type=semver,pattern={{version}}
# Login to Artifact Registry if we're pushing to it.
- name: Login to Artifact Registry
env:
ARTIFACT_REGISTRY_JSON_KEY: ${{ secrets.ARTIFACT_REGISTRY_JSON_KEY }}
if: ${{ env.ARTIFACT_REGISTRY_JSON_KEY }}
uses: docker/login-action@v2
with:
registry: ${{ secrets.ARTIFACT_REGISTRY }}
username: _json_key
password: ${{ secrets.ARTIFACT_REGISTRY_JSON_KEY }}
# Login to Container Registry if we're pushing to it.
- name: Login to Container Registry
env:
CONTAINER_REGISTRY_JSON_KEY: ${{ secrets.CONTAINER_REGISTRY_JSON_KEY }}
if: ${{ env.CONTAINER_REGISTRY_JSON_KEY }}
uses: docker/login-action@v2
with:
registry: ${{ secrets.CONTAINER_REGISTRY }}
username: _json_key
password: ${{ secrets.CONTAINER_REGISTRY_JSON_KEY }}
# Setup QEMU needed to build arm64 images.
- name: Setup QEMU
uses: docker/setup-qemu-action@v2
# Setup Docker builder needed to build multi-architectural images.
- name: Setup Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
# Build and push the image.
- name: Build and Push to Artifact Registry and Container Registry
uses: docker/build-push-action@v3
with:
push: true
context: .
file: Dockerfile
platforms: linux/amd64,linux/arm64
build-args: |
VERSION=${{ steps.release.outputs.version }}
tags: ${{ steps.release.outputs.tags }}
labels: ${{ steps.release.outputs.labels }}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This repo contains GitHub Action Workflow Templates for Kochava's various workfl
| Go Library | go_lib | go/lib/{version} | Used for Go library projects intended to be imported. Tests/Lints on PRs, Creates a Release based on conventional commits when merged to main. |
| PHP Library | php_lib | php/lib/{version} | Used for PHP library projects intended to be imported. Tests/Lints on PRs, Creates a Release based on conventional commits when merged to main. |
| Gradle Library | gradle_app | gradle/app/{version} | Used for Gradle Java/Kotlin application projects intended to be deployed as a Jar file. Tests/Lints on PRs, Creates a Release based on conventional commits when merged to main. |
| Ruby on Rails App | rails_app | rails/app/{version} | Used for Ruby on Rails application projects intended to be deployed as a Docker image. Tests on PRs, Creates a Release based on conventional commits when merged to main. |

## Versioning

Expand Down