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

reuse github workflows #163

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
134 changes: 18 additions & 116 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,137 +1,39 @@
name: "Test & Build"
name: test and build

on:
push:
pull_request:

- push
- pull_request
- workflow_dispatch

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
app: [fairdatapoint-index, fairdatapoint]
node-version: [16]

env:
PUBLIC_IMAGE: fairdata/${{ matrix.app }}-client
PRIVATE_IMAGE: ${{ secrets.PRIVATE_REGISTRY_URL }}/${{ matrix.app }}-client
# https://nodejs.org/en/about/previous-releases#release-schedule
node: [16, 22]

steps:
# (1) -> Preparations
- name: Checkout repo
uses: actions/checkout@v3
with:
fetch-depth: 0
- # https://github.com/actions/checkout
name: Checkout repo
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

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

- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
- # https://github.com/actions/setup-node
name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
node-version: ${{ matrix.node }}
cache: 'npm'

- name: Install dependencies
run: npm ci
- name: Install dependencies from package-lock.json
run: npm clean-install

- name: Lint
run: npm run lint

# (2) -> Build app and Docker image
- name: Build
run: npm run build

- name: Create build info
run: ./scripts/build_info.sh

# (3) -> Docker [test build]
- name: Docker meta [test]
id: meta-test
uses: docker/metadata-action@v4
with:
images: |
${{ env.PUBLIC_IMAGE }}
tags: |
type=sha

- name: Docker build+push [test]
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
build-args: fdp_app=${{ matrix.app }}
platforms: linux/amd64,linux/arm64
push: false
tags: ${{ steps.meta-test.outputs.tags }}
labels: ${{ steps.meta-test.outputs.labels }}

# (4) -> Docker [private registry]
- name: Docker login [private]
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ${{ secrets.PRIVATE_REGISTRY_URL }}
username: ${{ secrets.PRIVATE_REGISTRY_USERNAME }}
password: ${{ secrets.PRIVATE_REGISTRY_PASSWORD }}

- name: Docker meta [private]
id: meta-private
if: github.event_name != 'pull_request'
uses: docker/metadata-action@v4
with:
images: |
${{ env.PRIVATE_IMAGE }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}

- name: Docker build+push [private]
uses: docker/build-push-action@v3
if: github.event_name != 'pull_request' && steps.meta-private.outputs.tags != ''
with:
context: .
file: ./Dockerfile
build-args: fdp_app=${{ matrix.app }}
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta-private.outputs.tags }}
labels: ${{ steps.meta-private.outputs.labels }}

# (5) -> Docker [Docker Hub]
- name: Docker login [public]
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}

- name: Docker meta [public]
id: meta-public
if: github.event_name != 'pull_request'
uses: docker/metadata-action@v4
with:
images: |
${{ env.PUBLIC_IMAGE }}
tags: |
type=raw,value=develop,enable=${{ github.ref == format('refs/heads/{0}', 'develop') }}
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}

- name: Docker build+push [public]
uses: docker/build-push-action@v3
if: github.event_name != 'pull_request' && steps.meta-public.outputs.tags != ''
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
build-args: fdp_app=${{ matrix.app }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta-public.outputs.tags }}
labels: ${{ steps.meta-public.outputs.labels }}


16 changes: 16 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Docker publish

on:
push:
branches:
- develop
pull_request:

jobs:
build:
# todo: create this reusable workflow...
uses: FAIRDataTeam/github-workflows/.github/workflows/npm-build.yml@v1
publish:
needs: build
uses: FAIRDataTeam/github-workflows/.github/workflows/docker-publish.yml@v1
secrets: inherit
Loading