Skip to content

Commit

Permalink
WIP: add composite actions
Browse files Browse the repository at this point in the history
  • Loading branch information
beuluis committed Dec 17, 2024
1 parent 16b579b commit 7e2f045
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 53 deletions.
6 changes: 3 additions & 3 deletions .github/actions/bun-environment-setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ description: 'Setup bun and install dependencies'
# TODO: add build action with cache
inputs:
dependencies_type:
description: 'Dependencies type to install. Can be "production" or "development"'
description: 'Specifies the type of dependencies to install. Choose "production" to install only production dependencies, or "development" to include development dependencies as well.'
default: 'production'
required: false
bun_version:
description: 'Bun version to setup'
description: 'The version of Bun to set up in the environment. Use "latest" to get the most recent version.'
default: 'latest'
required: false
registry_url:
description: 'Registry url to use'
description: 'The URL of the npm registry to use for installing packages. Defaults to the official npm registry.'
default: 'https://registry.npmjs.org'
required: false

Expand Down
29 changes: 29 additions & 0 deletions .github/actions/eslint-runner/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: 'ESLint Runner'

Check warning on line 1 in .github/actions/eslint-runner/action.yml

View workflow job for this annotation

GitHub Actions / yamllint

1:1 [document-start] missing document start "---"
description: 'Runs ESLint on the codebase'

inputs:
package_manager:
description: 'The package manager to use for running scripts. Options are "npm" or "bun".'
default: 'npm'
required: false

runs:
using: "composite"
steps:
- name: Run tests (bun)
if: inputs.package_manager == 'bun'
shell: bash
run: bunx eslint . --output-file eslint_report.json --format json

- name: Run tests (npm)
if: inputs.package_manager == 'npm'
shell: bash
run: npx eslint . --output-file eslint_report.json --format json

- name: Annotate Code Linting Results
if: always()
continue-on-error: true
uses: ataylorme/eslint-annotate-action@v3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
report-json: "eslint_report.json"
22 changes: 22 additions & 0 deletions .github/actions/jest-test-runner/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: 'Jest Test Runner'

Check warning on line 1 in .github/actions/jest-test-runner/action.yml

View workflow job for this annotation

GitHub Actions / yamllint

1:1 [document-start] missing document start "---"
description: 'Runs Jest tests, with coverage reporting'

# TODO: Add junit reporting
inputs:
package_manager:
description: 'The package manager to use for running scripts. Options are "npm" or "bun".'
default: 'npm'
required: false

runs:
using: "composite"
steps:
- name: Run tests (bun)
if: inputs.package_manager == 'bun'
shell: bash
run: bunx jest --ci --coverage

- name: Run tests (npm)
if: inputs.package_manager == 'npm'
shell: bash
run: npx jest --ci --coverage
41 changes: 0 additions & 41 deletions .github/actions/node-qa-testing/action.yml

This file was deleted.

6 changes: 3 additions & 3 deletions .github/actions/npm-environment-setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ description: 'Setup node and install dependencies'

inputs:
dependencies_type:
description: 'Dependencies type to install. Can be "production" or "development"'
description: 'Specifies the type of dependencies to install. Choose "production" to install only production dependencies, or "development" to include development dependencies as well.'
default: 'production'
required: false
node_version:
description: 'Node version to setup'
description: 'The version of Node.js to set up in the environment. This ensures compatibility with your project requirements.'
default: '22.12'
required: false
registry_url:
description: 'Registry url to use'
description: 'The URL of the npm registry to use for installing packages. Defaults to the official npm registry.'
default: 'https://registry.npmjs.org'
required: false

Expand Down
12 changes: 6 additions & 6 deletions .github/actions/upload-to-s3/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ description: 'Uploads files to S3'

inputs:
access_key:
description: 'AWS Access Key ID'
description: 'AWS access key for authentication.'

Check failure on line 6 in .github/actions/upload-to-s3/action.yml

View workflow job for this annotation

GitHub Actions / yamllint

6:18 [quoted-strings] string value is redundantly quoted with double quotes
required: true
secret_key:
description: 'AWS Secret Access Key'
description: 'AWS secret key for authentication.'

Check failure on line 9 in .github/actions/upload-to-s3/action.yml

View workflow job for this annotation

GitHub Actions / yamllint

9:18 [quoted-strings] string value is redundantly quoted with double quotes
required: true
endpoint:
description: 'AWS endpoint URL'
description: 'Custom endpoint for S3-compatible storage. Use this if you are not using AWS S3, but a compatible service.'

Check failure on line 12 in .github/actions/upload-to-s3/action.yml

View workflow job for this annotation

GitHub Actions / yamllint

12:18 [quoted-strings] string value is redundantly quoted with double quotes
required: false
default: ''
source_path:
description: 'Path to the files to upload'
description: 'Local path to the files to upload. Ensure this path ends with a slash to correctly sync directories.'
required: true
bucket_name:
description: 'Bucket name'
description: 'Name of the S3 bucket where files will be uploaded.'
required: true
destination_path:
description: 'Target path within the S3 bucket'
description: 'Path within the S3 bucket where files will be stored. This should end with a slash to maintain directory structure.'
required: false
default: '${{ github.event.repository.name }}/'

Expand Down
101 changes: 101 additions & 0 deletions .github/workflows/deploy-static-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Build and Deploy a static app

Check warning on line 1 in .github/workflows/deploy-static-app.yml

View workflow job for this annotation

GitHub Actions / yamllint

1:1 [document-start] missing document start "---"

# TODO: Handle different package managers
on:

Check warning on line 4 in .github/workflows/deploy-static-app.yml

View workflow job for this annotation

GitHub Actions / yamllint

4:1 [truthy] truthy value should be one of [false, true]
workflow_call:
inputs:
bucket_name:
required: true
type: string
description: 'Name of the S3 bucket where files will be uploaded.'

Check failure on line 10 in .github/workflows/deploy-static-app.yml

View workflow job for this annotation

GitHub Actions / yamllint

10:22 [quoted-strings] string value is redundantly quoted with double quotes
endpoint:
required: false
type: string
description: 'Custom endpoint for S3-compatible storage. Use this if you are not using AWS S3, but a compatible service.'

Check failure on line 14 in .github/workflows/deploy-static-app.yml

View workflow job for this annotation

GitHub Actions / yamllint

14:22 [quoted-strings] string value is redundantly quoted with double quotes
ref:
required: false
type: string
description: 'The branch or tag to deploy. Defaults to the current branch.'

Check failure on line 18 in .github/workflows/deploy-static-app.yml

View workflow job for this annotation

GitHub Actions / yamllint

18:22 [quoted-strings] string value is redundantly quoted with double quotes
default: ${{ github.ref }}
secrets:
ACCESS_KEY:
required: true
description: 'AWS access key for authentication.'

Check failure on line 23 in .github/workflows/deploy-static-app.yml

View workflow job for this annotation

GitHub Actions / yamllint

23:22 [quoted-strings] string value is redundantly quoted with double quotes
SECRET_KEY:
required: true
description: 'AWS secret key for authentication.'

Check failure on line 26 in .github/workflows/deploy-static-app.yml

View workflow job for this annotation

GitHub Actions / yamllint

26:22 [quoted-strings] string value is redundantly quoted with double quotes

jobs:
setup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- uses: Beuterei/reusable-workflows/.github/actions/npm-environment-setup@main
with:
dependencies_type: development

build:
runs-on: ubuntu-latest
needs: setup
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- uses: Beuterei/reusable-workflows/.github/actions/restore-dependency-cache@main
- name: Restore cached build
id: restore-build-cache
uses: actions/cache/restore@v4
with:
path: dist
key: build-${{ runner.os }}-${{ github.sha }}
- name: Build
if: steps.restore-build-cache.outputs.cache-hit != 'true'
run: npm run build
- name: Cache build output
if: steps.restore-build-cache.outputs.cache-hit != 'true'
uses: actions/cache@v4
with:
path: dist
key: build-${{ runner.os }}-${{ github.sha }}

linting:
runs-on: ubuntu-latest
needs: setup
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- uses: Beuterei/reusable-workflows/.github/actions/restore-dependency-cache@main
- name:
uses: Beuterei/reusable-workflows/.github/actions/eslint-runner@main


testing:
runs-on: ubuntu-latest
needs: setup
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- uses: Beuterei/reusable-workflows/.github/actions/restore-dependency-cache@main
- name:
uses: Beuterei/reusable-workflows/.github/actions/jest-test-runner@main

deploy:
runs-on: ubuntu-latest
needs: [build, linting, testing]
steps:
- uses: actions/cache/restore@v4
with:
path: dist
key: build-${{ runner.os }}-${{ github.sha }}
- name: Deploy
uses: Beuterei/reusable-workflows/.github/actions/upload-to-s3@main
with:
access_key: ${{ secrets.ACCESS_KEY }}
secret_key: ${{ secrets.SECRET_KEY }}
bucket_name: ${{ inputs.bucket_name }}
endpoint: ${{ inputs.endpoint }}
source_path: dist/

0 comments on commit 7e2f045

Please sign in to comment.