Skip to content

Commit

Permalink
Add neccessary github workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
Christdej committed Oct 23, 2024
1 parent c3f09fb commit a1cbbd5
Show file tree
Hide file tree
Showing 17 changed files with 706 additions and 58 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/backend_lint_and_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Api

on:
push:
branches:
- main
pull_request:
branches:
- main

defaults:
run:
working-directory: api

jobs:
build_api:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"
- name: Build project and dependencies
run: dotnet build

test_api:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"

- name: Build project and dependencies
run: dotnet build -warnaserror

- name: Run tests
run: dotnet test

check_formatting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"

# Dotnet format is included in the .NET8 SDK
# By default, the task ensures the exit code is 0
# If a file needs to be edited by dotnet format, the exit code will be a non-zero value
# We are using severity level 'info' here.
- name: Run dotnet format
run: dotnet format --severity info --verbosity diagnostic --verify-no-changes --exclude ./api/migrations

- name: Run csharpier format
run: |
dotnet tool restore
dotnet csharpier --check
47 changes: 0 additions & 47 deletions .github/workflows/deploy-example-function.yaml

This file was deleted.

60 changes: 60 additions & 0 deletions .github/workflows/deploy_to_development.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Deploy to Development

# Only one workflow in a concurrency group may run at a time
concurrency:
group: development-concurrency
cancel-in-progress: true

on:
push:
branches:
- "main"

jobs:
trigger-github-deployment:
name: Trigger GitHub Deployment
environment: Development
runs-on: ubuntu-latest
steps:
- name: Empty Step
run: echo "Hello World"

get-short-sha:
needs: trigger-github-deployment
outputs:
tag: ${{ steps.get-tag.outputs.tag }}
runs-on: ubuntu-latest
steps:
- id: get-tag
run: |
SHA_SHORT=$(echo ${{ github.sha }} | cut -c1-8)
echo "tag=$SHA_SHORT" >> "$GITHUB_OUTPUT"
build-and-push-components:
name: Build and push containers to acr for Development
needs: trigger-github-deployment
uses: ./.github/workflows/publish_component.yml
with:
Registry: auroradevacr.azurecr.io
ImageName: robotics/inspection-data-analyzer
Tag: ${{ needs.get-short-sha.outputs.tag }}
secrets:
RegistryUsername: ${{ secrets.ROBOTICS_AURORADEVACR_USERNAME }}
RegistryPassword: ${{ secrets.ROBOTICS_AURORADEVACR_PASSWORD }}

deploy:
name: Update deployment in Development
needs: [build-and-push-components, get-short-sha, trigger-github-deployment]
uses: ./.github/workflows/update_aurora_deployment.yml
with:
Environment: development
Registry: auroraprodacr.azurecr.io
ImageName: ${{ github.repository }}
# Add dev. prefix for the tags used in dev environment,
# due to the commit hash can be interpreted as an integer if only numbers
# PS: Needs to match build-and-push-components.with.Tag
Tag: "dev.${{ needs.get-short-sha.outputs.tag }}"
AuthorEmail: ${{ github.event.head_commit.author.email }}
AuthorName: ${{ github.event.head_commit.author.name }}
secrets:
DeployKey: ${{ secrets.ANALYTICS_INFRASTRUCTURE_DEPLOY_KEY }}
40 changes: 40 additions & 0 deletions .github/workflows/notifyMigrationChanges.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Notify migration changes

on:
pull_request_target:
branches: [main]
paths: [api/Migrations/**]

env:
message: |
:bell: Migrations changes detected :bell:
:mega: Remember to comment "/UpdateDatabase" after review approval for migrations to take effect!
jobs:
Notify_Migration:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Check for previous comment
id: notify_comment_search
uses: peter-evans/find-comment@v3
with:
issue-number: ${{ github.event.number }}
body-includes: ${{ env.message }}

- name: Add comment if no comment exists
if: ${{ !steps.notify_comment_search.outputs.comment-body }}
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.number }}
body: ${{ env.message }}

- name: Add label
uses: actions-ecosystem/action-add-labels@v1
with:
labels: database-change
46 changes: 46 additions & 0 deletions .github/workflows/notifyPossibleMigrationUpdate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Notify possible migration changes

on:
pull_request_target:
branches: [main]
paths: [api/Models/**]

env:
message: |
:bell: Changes in database folder detected :bell:
Do these changes require **adding new migrations**? :thinking: In that case follow [these steps](https://github.com/equinor/inspection-data-analyzer/tree/main/api#Database-model-and-EF-Core).
If you are uncertain, ask a database admin on the team :smile:
jobs:
Notify_Possible_Migration:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Get changed files in the migrations folder
id: changed_files
uses: tj-actions/changed-files@v45
with:
files: api/Migrations/**
sha: ${{ github.event.pull_request.head.sha }}

- name: If no migrations, check for previous comment
if: ${{ steps.changed_files.outputs.any_changed != 'true' }}
id: notify_comment_search
uses: peter-evans/find-comment@v3
with:
issue-number: ${{ github.event.number }}
body-includes: ${{ env.message }}

- name: Add comment if no migrations and no comment exists
if: |
!steps.notify_comment_search.outputs.comment-body &&
steps.changed_files.outputs.any_changed != 'true'
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.number }}
body: ${{ env.message }}
56 changes: 56 additions & 0 deletions .github/workflows/publish_component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Build and publish component

on:
workflow_call:
inputs:
ComponentName:
required: true
type: string
Registry:
required: true
type: string
Tag:
required: true
type: string
ImageName:
required: true
type: string
secrets:
RegistryUsername:
required: true
RegistryPassword:
required: true

jobs:
build-and-push-container:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Github Container registry
uses: docker/login-action@v3
with:
registry: ${{ inputs.Registry }}
username: ${{ secrets.RegistryUsername }}
password: ${{ secrets.RegistryPassword }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ inputs.Registry }}/${{ inputs.ImageName }}-${{ inputs.ComponentName }}

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: ./${{ inputs.ComponentName }}
push: true
tags: |
${{ inputs.Registry }}/${{ inputs.ImageName }}-${{ inputs.ComponentName }}:${{ inputs.Tag }}
${{ inputs.Registry }}/${{ inputs.ImageName }}-${{ inputs.ComponentName }}:latest
labels: ${{ steps.meta.outputs.labels }}
61 changes: 61 additions & 0 deletions .github/workflows/runMigrations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Run migrations

on:
workflow_call:
inputs:
PullRequestCheckout:
required: false
type: boolean
Environment:
required: true
type: string
CheckoutRef:
required: false
type: string
default: "main"
secrets:
ClientId:
required: true
ClientSecret:
required: true

defaults:
run:
working-directory: api

jobs:
run_migrations:
environment: ${{ inputs.Environment }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.CheckoutRef }}

# Checks out to main branch by default, so we need to manually checkout to the PR the comment was made on
# in order to do the update database on the new migrations.
# We don't have the ref in the IssueComment trigger so we need to check out the pr number
- name: Checkout Pull Request
if: ${{ inputs.PullRequestCheckout }}
run: gh pr checkout ${{ github.event.issue.number }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"

- name: Build project and dependencies
run: dotnet build

- name: Install dotnet ef tool
run: dotnet tool install -g dotnet-ef --version 8.0.0

- name: Update database
run: dotnet ef database update --no-build --verbose
env:
AZURE_CLIENT_ID: ${{ secrets.ClientId }}
AZURE_CLIENT_SECRET: ${{ secrets.ClientSecret }}
ASPNETCORE_ENVIRONMENT: ${{ vars.AspNetEnvironment }}
Loading

0 comments on commit a1cbbd5

Please sign in to comment.