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

Implements github actions #54

Merged
merged 25 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
57 changes: 57 additions & 0 deletions .github/actions-change-labeler/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Determine labels based on the paths of files being changed in the pull requests.

inputs:
configuration-path:
description: "The path for the label configurations"
default: ".github/labeler.yml"
required: false
dot:
description: "Whether or not to include paths starting with dot (e.g. `.github`) in glob matching"
default: true
required: false
repo-token:
description: "The GitHub token used to manage labels"
required: false
default: ${{ github.token }}

outputs:
changes:
description: A JSON encoded list of all changes detected. e.g. `["backend", "frontend"]`
value: ${{ steps.derive-changes.outputs.result }}

runs:
using: composite
steps:
- id: labler
if: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }}
# for PRs, use the actions/labeler action to determine change labels
uses: actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9 # v5.0.0
with:
repo-token: ${{ inputs.repo-token }}
configuration-path: ${{ inputs.configuration-path }}
dot: ${{ inputs.dot }}
sync-labels: "true"

# Read the configuration file and use that to filter out unrelated labels in the PR
# e.g. labels added manually, or added by other bots/actions
- id: read-config
shell: bash
run: |
echo "Reading configuration file into JSON"
config=$(yq -o=json -I=0 "$CONFIG_PATH")
echo "config=$config" >> "$GITHUB_OUTPUT"
env:
CONFIG_PATH: ${{ inputs.configuration-path }}

- id: derive-changes
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const labels = new Set((process.env.LABELS || '').split(','));
const config = JSON.parse(process.env.CONFIG);
const changes = Object.keys(config).filter(key => labels.has(key));
console.log('changes', changes);
return changes;
env:
CONFIG: ${{ steps.read-config.outputs.config }}
LABELS: ${{ steps.labler.outputs.all-labels || steps.get-labels-from-source-pr.outputs.labels }}
15 changes: 15 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
backend:
- changed-files:
- any-glob-to-any-file:
- '*gradle*'
- gradle/**
- openapi/**
- src/**
frontend:
- changed-files:
- any-glob-to-any-file:
- web/**
workflows:
- changed-files:
- any-glob-to-any-file:
- .github/**
52 changes: 52 additions & 0 deletions .github/workflows/backend-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Landonlite Backend Workflow

on:
pull_request:
branches:
- "master"

jobs:
Compare-changes:
uses: ./.github/workflows/compare-changes.yml

print-compare-changes-output:
runs-on: ubuntu-latest
needs: Compare-changes
steps:
- run: echo "BackendDisable ${{ needs.compare-changes.outputs.backendDisable }}"
- run: printf "backendDisable ${{ needs.Compare-changes.outputs.backendDisable == 'true' }}\n"
printf "playwrightDisable ${{ needs.Compare-changes.outputs.playwrightDisable == 'true' }}"

backend-tests:
needs:
- Compare-changes
if: ${{ needs.Compare-changes.outputs.backendDisable == 'false' }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: corretto
java-version: 17

- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-

- name: Grant execute permission for gradlew
run: chmod +x ./gradlew

# - name: Build with Gradle
# run: ./gradlew build

# - name: Run tests
# run: ./gradlew test
42 changes: 42 additions & 0 deletions .github/workflows/compare-changes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Compare changes
on:
workflow_call:
outputs:
backendDisable:
value: ${{ jobs.compare-changes.outputs.backendDisable && jobs.compare-changes.outputs.workflowsNotChanged }}
frontendDisable:
value: ${{ jobs.compare-changes.outputs.frontendDisable && jobs.compare-changes.outputs.workflowsNotChanged }}
playwrightDisable:
value: ${{ jobs.compare-changes.outputs.playwrightDisable && jobs.compare-changes.outputs.workflowsDisable && jobs.compare-changes.outputs.backendDisable && jobs.compare-changes.outputs.frontendDisable }}

jobs:
compare-changes:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
outputs:
backendDisable: ${{ !contains(fromJSON(steps.changed-files.outputs.changes), 'backend') }}
frontendDisable: ${{ !contains(fromJSON(steps.changed-files.outputs.changes), 'frontend') }}
playwrightDisable: ${{ !contains(fromJSON(steps.changed-files.outputs.changes), 'playwright') }}
workflowsNotChanged: ${{ !contains(fromJSON(steps.changed-files.outputs.changes), 'workflows') }}
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Get changed files
id: changed-files
uses: ./.github/actions-change-labeler

- run: echo "Changes detected ${{ steps.changed-files.outputs.changes }}"
echo "backend disabled ${{ !contains(fromJSON(steps.changed-files.outputs.changes), 'backend') }}\n"
echo "frontend disabled ${{ !contains(fromJSON(steps.changed-files.outputs.changes), 'frontend') }}"
echo "playwright disabled ${{ !contains(fromJSON(steps.changed-files.outputs.changes), 'playwright') }}"
echo "workflows changed ${{ contains(fromJSON(steps.changed-files.outputs.changes), 'workflows') }}"

- name: Check for both frontend and backend changes
if: ${{ contains(fromJSON(steps.changed-files.outputs.changes), 'backend') && contains(fromJSON(steps.changed-files.outputs.changes), 'frontend')}}
uses: actions/github-script@v7
with:
script: |
core.setFailed('PR has both FE and BE changes, please split your FE and BE changes into separate PRs')
47 changes: 47 additions & 0 deletions .github/workflows/frontend-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Landonlite Frontend Workflow
on:
pull_request:
branches:
- "master"

jobs:
compare-changes:
uses: ./.github/workflows/compare-changes.yml

print-compare-changes-output:
runs-on: ubuntu-latest
needs: compare-changes
steps:
- run: echo "FrontendDisable ${{ needs.compare-changes.outputs.frontendDisable }}"
- run: printf "should run frontend CI ${{ needs.compare-changes.outputs.frontendDisable == 'false' }}\n"

frontend-test:
needs:
- Compare-changes
if: ${{ needs.Compare-changes.outputs.backendDisable == 'false' }}
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./web
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '16'

- name: Cache npm packages
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-

- name: Install dependencies
run: npm install

- name: Run tests
run: npm test
Loading