Skip to content

Commit

Permalink
Merge pull request #1 from gmmcal/move-workflows
Browse files Browse the repository at this point in the history
NEW: Move reusable workflows from gmmcal.com.br repo to here
  • Loading branch information
gmmcal committed May 17, 2024
2 parents 7f540bb + c908c9a commit 175c453
Show file tree
Hide file tree
Showing 9 changed files with 328 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/_cypress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: End-to-end Tests

on:
workflow_call:
inputs:
pattern:
type: string
required: true
name:
type: string
required: true

jobs:
e2e:
name: "End-to-end - ${{ inputs.name }} (${{ matrix.browser }})"
runs-on: ubuntu-20.04
container:
image: gmmcal/gmmcal:cypress
env:
CYPRESS_BASE_URL: http://web:3000
CYPRESS_SPEC_PATTERN: ${{ inputs.pattern }}

strategy:
matrix:
browser: [chrome, firefox]

services:
postgres:
image: postgres:16
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: gmmcalcombr_test
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

web:
image: gmmcal/gmmcal:test
env:
DATABASE_URL: postgres://postgres:postgres@postgres:5432/gmmcalcombr_test
ON_CYPRESS: true
ports:
- 3000:3000

steps:
- name: Run tests on ${{ matrix.browser }}
run: cypress run --browser ${{ matrix.browser }}
working-directory: /rails
34 changes: 34 additions & 0 deletions .github/workflows/_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Deploy application

on:
workflow_call:
inputs:
name:
type: string
required: true
environment:
type: string
required: true
url:
type: string
required: true
params:
type: string
required: false
default: ""

jobs:
deploy:
name: ${{ inputs.name }}
runs-on: ubuntu-20.04
environment:
name: ${{ inputs.environment }}
url: ${{ inputs.url }}

steps:
- name: Deploy
env:
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
DEPLOY_SERVICE: ${{ secrets.DEPLOY_SERVICE }}
run: |
curl "https://api.render.com/deploy/srv-$DEPLOY_SERVICE?key=$DEPLOY_KEY&${{ inputs.params }}"
53 changes: 53 additions & 0 deletions .github/workflows/_docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Build

on:
workflow_call:
inputs:
name:
type: string
required: true
tag-name:
type: string
required: false
default: "gmmcal/gmmcal:test"
target:
type: string
required: false
default: test
reference:
type: string
required: false
publish:
type: boolean
required: false
default: true

jobs:
build:
name: ${{ inputs.name }}
runs-on: ubuntu-20.04

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ inputs.reference }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build image
uses: docker/build-push-action@v5
with:
push: ${{ inputs.publish }}
context: .
target: ${{ inputs.target }}
tags: ${{ inputs.tag-name }}
cache-from: type=registry,ref=gmmcal/gmmcal:buildcache${{ inputs.target }}
cache-to: type=registry,ref=gmmcal/gmmcal:buildcache${{ inputs.target }},mode=max
28 changes: 28 additions & 0 deletions .github/workflows/_lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Lint

on:
workflow_call:
inputs:
name:
type: string
required: true
command:
type: string
required: true
image:
type: string
required: false
default: gmmcal/gmmcal:test

jobs:
lint:
name: ${{ inputs.name }}
runs-on: ubuntu-20.04
container:
image: ${{ inputs.image }}
options: "--user=root:root"

steps:
- name: Execute ${{ inputs.command }}
run: ${{ inputs.command }}
working-directory: /rails
22 changes: 22 additions & 0 deletions .github/workflows/_preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Deploy preview image

on:
workflow_call:
inputs:
tag-name:
type: string
required: true

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment:
name: preview
url: ${{ steps.result.outputs.url }}
steps:
- name: Create Render service preview
id: result
run: |
curl -X POST https://api.render.com/v1/services/srv-${{ secrets.DEPLOY_SERVICE }}/preview -H 'Authorization: Bearer ${{ secrets.RENDER_API_KEY }}' -H 'Accept: application/json' -d '{"imagePath": "docker.io/${{ inputs.tag-name }}", "name": "gustavocunha-preview-pr-${{ github.event.number }}-${{ github.run_number }}"}' > result.json
echo "url=$(jq -r '.service.serviceDetails.url' result.json)" >> "$GITHUB_OUTPUT"
24 changes: 24 additions & 0 deletions .github/workflows/_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Release

on:
workflow_call:
inputs:
tag:
type: string
required: true

jobs:
release:
name: Create release page
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Create release
uses: ncipollo/release-action@v1
with:
generateReleaseNotes: true
tag: ${{ inputs.tag }}
27 changes: 27 additions & 0 deletions .github/workflows/_tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Tag application

on:
workflow_call:
outputs:
version:
description: Prefix of image name
value: ${{ jobs.tag.outputs.version }}

jobs:
tag:
name: Determine tag number
runs-on: ubuntu-latest
outputs:
version: ${{ steps.semver.outputs.next }}

steps:
- name: Get Next Version
id: semver
uses: ietf-tools/semver-action@v1
with:
token: ${{ github.token }}
noVersionBumpBehavior: patch
branch: main
majorList: "BREAK"
minorList: "NEW"
patchList: "FIX,OPT"
38 changes: 38 additions & 0 deletions .github/workflows/_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Backend Tests

on:
workflow_call:
inputs:
command:
type: string
required: true

jobs:
tests:
name: Backend
runs-on: ubuntu-20.04
container:
image: gmmcal/gmmcal:test
env:
DATABASE_URL: postgres://postgres:postgres@postgres:5432/gmmcalcombr_test
DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL: true

services:
postgres:
image: postgres:16
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: gmmcalcombr_test
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- name: Migrate database
run: bundle exec rails db:migrate
working-directory: /rails

- name: Execute tests
run: ${{ inputs.command }}
working-directory: /rails
53 changes: 53 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Tag Release

on:
push:
branches:
- main

jobs:
tag:
runs-on: ubuntu-20.04
permissions:
contents: write

steps:
- name: Get Next Version
id: semver
uses: ietf-tools/semver-action@v1
with:
token: ${{ github.token }}
branch: main
majorList: "BREAK"
minorList: "NEW"
patchList: "FIX,OPT"

- name: 🏷️ Create tag ${{ steps.semver.outputs.next }}
uses: actions/github-script@v7
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/${{ steps.semver.outputs.next }}',
sha: context.sha
})
- name: 🏷️ Create/update tag ${{ steps.semver.outputs.nextMajor }}
uses: actions/github-script@v7
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'tags/${{ steps.semver.outputs.nextMajor }}',
sha: context.payload.after
}).catch(err => {
if (err.status !== 422) throw err;
github.rest.git.updateRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'tags/${{ steps.semver.outputs.nextMajor }}',
sha: context.payload.after
});
})

0 comments on commit 175c453

Please sign in to comment.