Skip to content

Commit

Permalink
Publish v0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasodonnell committed Jul 25, 2024
1 parent 92de239 commit b3850f1
Show file tree
Hide file tree
Showing 12 changed files with 980 additions and 6 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Build

on:
workflow_call:

permissions:
checks: write
contents: write

jobs:

build:
name: Build
runs-on: ubuntu-latest

steps:

- name: Checkout
id: checkout
uses: actions/checkout@v3

- name: Set up Node.js
id: setup
uses: actions/setup-node@v3
with:
node-version: 20

- name: Install dependencies
id: dependencies
run: npm ci

- id: build
name: Build
run: npm run build
34 changes: 34 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: 'Lint'

on:
workflow_call:

permissions:
checks: write
contents: write

jobs:

lint:
name: Lint
runs-on: ubuntu-latest

steps:

- name: Checkout
id: checkout
uses: actions/checkout@v3

- name: Set up Node.js
id: setup
uses: actions/setup-node@v3
with:
node-version: 20

- name: Install dependencies
id: dependencies
run: npm ci

- name: Lint
id: lint
run: npm run lint
18 changes: 18 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: 'PR'

on:
pull_request:

permissions:
checks: write
contents: write

jobs:

lint:
name: Lint
uses: ./.github/workflows/lint.yml

build:
name: Build
uses: ./.github/workflows/build.yml
64 changes: 64 additions & 0 deletions .github/workflows/publish-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: 'Publish to Docker Hub'

on:
workflow_call:
inputs:
version:
type: string
description: 'The version to publish'
required: true

secrets:
DOCKER_USERNAME:
required: true
DOCKERHUB_TOKEN:
required: true

workflow_dispatch:
inputs:
version:
type: string
description: 'The version to publish'
required: true

permissions:
checks: write
contents: write

jobs:

publish_docker:
name: Publish to Docker Hub
runs-on: ubuntu-latest

steps:

- name: Checkout
id: checkout
uses: actions/checkout@v3

- name: Log in to Docker Hub
id: login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ github.repository }}
tags: |
type=raw,value=${{ inputs.version }},priority=1000
type=raw,value=latest,enable=${{ !contains(inputs.version, 'beta') }}
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
40 changes: 40 additions & 0 deletions .github/workflows/publish-github.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: 'Publish GitHub Tag and Release'

on:
workflow_call:
inputs:
version:
type: string
description: 'The version to publish'
required: true

permissions:
checks: write
contents: write

jobs:

publish_tag:
name: Publish GitHub Tag and Release
runs-on: ubuntu-latest

steps:

- name: Checkout
id: checkout
uses: actions/checkout@v3

- name: Create Tag
id: tag
uses: mathieudutour/github-tag-action@v6.1
with:
custom_tag: ${{ inputs.version }}
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Create release
id: release
uses: ncipollo/release-action@v1
with:
generateReleaseNotes: true
name: ${{ steps.tag.outputs.new_tag }}
tag: ${{ steps.tag.outputs.new_tag }}
50 changes: 50 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: 'Publish'

on:
push:
branches:
- main

workflow_dispatch:
inputs:
version:
description: 'Version to publish'
required: false

permissions:
checks: write
contents: write

jobs:

lint:
name: Lint
uses: ./.github/workflows/lint.yml

build:
name: Build
uses: ./.github/workflows/build.yml

version:
name: Version
uses: ./.github/workflows/version.yml
with:
version: ${{ inputs.version }}

publish_github:
name: Publish to GitHub
uses: ./.github/workflows/publish-github.yml
needs: [version]
if: ${{ (needs.version.outputs.next_version != needs.version.outputs.previous_version) && (github.ref == 'refs/heads/main') }}
secrets: inherit
with:
version: ${{ needs.version.outputs.next_version }}

publish_docker:
name: Publish to Docker Hub
uses: ./.github/workflows/publish-docker.yml
needs: [version]
if: ${{ needs.version.outputs.next_version != needs.version.outputs.previous_version }}
secrets: inherit
with:
version: ${{ needs.version.outputs.next_version }}
57 changes: 57 additions & 0 deletions .github/workflows/version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Version

on:
workflow_call:
inputs:
version:
type: string
description: 'Next version (manually set)'
required: false

outputs:
next_version:
description: 'Next version'
value: ${{ jobs.version.outputs.next_version }}

previous_version:
description: 'Previous version'
value: ${{ jobs.version.outputs.previous_version }}

permissions:
checks: write
contents: write

jobs:

version:
name: Version
runs-on: ubuntu-latest

outputs:
next_version: ${{ steps.next_version.outputs.value }}
previous_version: ${{ steps.previous_version.outputs.value }}

steps:

- name: Checkout
id: checkout
uses: actions/checkout@v3

- name: Get current version
id: next_version
run: |
if [ -n "${{ inputs.version }}" ]; then
value=${{ inputs.version }}
else
value=$(node -p "require('./package.json').version")
fi
echo "next_version=$value"
echo "value=$value" >> $GITHUB_OUTPUT
- name: Get previous version
id: previous_version
run: |
git fetch --tags origin
value=$(git tag --sort=committerdate | sed 's/^v//' | tail -1)
echo "previous_version=$value"
echo "value=$value" >> $GITHUB_OUTPUT
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,14 @@ FROM base AS production

ENV NODE_ENV=production

RUN mkdir -p /app/config && chown app:app /app/config

COPY --from=build --chown=app:app /app/package.json ./package.json
COPY --from=build --chown=app:app /app/node_modules ./node_modules
COPY --from=build --chown=app:app /app/dist ./dist
COPY --from=build --chown=app:app /app/knexfile.ts ./knexfile.ts
COPY --from=build --chown=app:app /app/tsconfig.json ./tsconfig.json
COPY --from=build --chown=app:app /app/migrations ./migrations
COPY --from=build --chown=app:app /app/knexfile.ts ./knexfile.ts
COPY --from=build --chown=app:app /app/dist ./dist
COPY --from=build --chown=app:app /app/public ./public
COPY --from=build --chown=app:app /app/views ./views

Expand Down
Loading

0 comments on commit b3850f1

Please sign in to comment.