Skip to content

Commit

Permalink
added publish and build-and-test workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
AntFMoJ committed Feb 20, 2024
1 parent d760356 commit 043c17d
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
name: Test and Build

on:

Check warning on line 4 in .github/workflows/build-and-test.yml

View workflow job for this annotation

GitHub Actions / YAML Lint

4:1 [truthy] truthy value should be one of [false, true]
pull_request:
branches:
- main

permissions: {} # yamllint disable-line

jobs:
yamllint:
name: YAML Lint
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
id: checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

Check warning on line 20 in .github/workflows/build-and-test.yml

View workflow job for this annotation

GitHub Actions / YAML Lint

20:73 [comments] too few spaces before comment

- name: Run yamllint
id: run_yamllint
uses: actionshub/yamllint@b772a30c3ba90c5f5aadfe94d8f3599e3a7099c8 # v1.8.2

Check warning on line 24 in .github/workflows/build-and-test.yml

View workflow job for this annotation

GitHub Actions / YAML Lint

24:76 [comments] too few spaces before comment

Check failure on line 24 in .github/workflows/build-and-test.yml

View workflow job for this annotation

GitHub Actions / YAML Lint

24:81 [line-length] line too long (83 > 80 characters)

markdownlint:
name: Markdown Lint
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
id: checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

Check warning on line 34 in .github/workflows/build-and-test.yml

View workflow job for this annotation

GitHub Actions / YAML Lint

34:73 [comments] too few spaces before comment

- name: Run mdl
id: run_mdl
uses: actionshub/markdownlint@6c82ff529253530dfbf75c37570876c52692835f # v3.1.4

Check warning on line 38 in .github/workflows/build-and-test.yml

View workflow job for this annotation

GitHub Actions / YAML Lint

38:80 [comments] too few spaces before comment

Check failure on line 38 in .github/workflows/build-and-test.yml

View workflow job for this annotation

GitHub Actions / YAML Lint

38:81 [line-length] line too long (87 > 80 characters)

build-and-test:
if: github.ref != 'main'
name: Build and Test
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
fail-fast: false
max-parallel: 3
matrix:
flavour:
- "visual-studio-code"
steps:
- name: Checkout
id: checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

Check warning on line 55 in .github/workflows/build-and-test.yml

View workflow job for this annotation

GitHub Actions / YAML Lint

55:73 [comments] too few spaces before comment

- name: Build and Test
id: build_and_test
shell: bash
run: |
bash scripts/build-and-test.sh "${{ matrix.flavour }}"

Check failure on line 61 in .github/workflows/build-and-test.yml

View workflow job for this annotation

GitHub Actions / YAML Lint

61:65 [new-line-at-end-of-file] no new line character at the end of file
45 changes: 45 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
name: Publish

on:

Check warning on line 4 in .github/workflows/publish.yml

View workflow job for this annotation

GitHub Actions / YAML Lint

4:1 [truthy] truthy value should be one of [false, true]
push:
tags:
- "v*"

permissions: {} # yamllint disable-line

jobs:
publish:
name: Publish
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
packages: write
strategy:
fail-fast: false
max-parallel: 3
matrix:
flavour:
- "visual-studio-code"
steps:
- name: Checkout
id: checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Log in to GitHub Container Registry
id: login_ghcr
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0

Check failure on line 32 in .github/workflows/publish.yml

View workflow job for this annotation

GitHub Actions / YAML Lint

32:81 [line-length] line too long (83 > 80 characters)
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Push
id: build_and_push
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0

Check failure on line 40 in .github/workflows/publish.yml

View workflow job for this annotation

GitHub Actions / YAML Lint

40:81 [line-length] line too long (88 > 80 characters)
with:
context: ${{ matrix.flavour }}
file: Dockerfile
push: true
tags: ghcr.io/ministryofjustice/analytical-platform-${{ matrix.flavour }}:${{ github.ref_name }}

Check failure on line 45 in .github/workflows/publish.yml

View workflow job for this annotation

GitHub Actions / YAML Lint

45:81 [line-length] line too long (106 > 80 characters)

Check failure on line 45 in .github/workflows/publish.yml

View workflow job for this annotation

GitHub Actions / YAML Lint

45:107 [new-line-at-end-of-file] no new line character at the end of file
26 changes: 26 additions & 0 deletions scripts/build-and-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

IMAGE="${1}"
IMAGE_TAG="analytical-platform.service.justice.gov.uk/${IMAGE}:local"
CONTAINER_STRUCTURE_TEST_IMAGE="gcr.io/gcp-runtimes/container-structure-test:latest"

if [[ "${REMOTE_CONTAINERS}" ]] && [[ "$(uname -m)" == "aarch64" ]]; then
echo "(⚠) Looks like you're running in a dev container on Apple Silicon."
echo "(⚠) This script builds linux/amd64 images which might take a long time or even fail."
export PLATFORM_FLAG="--platform linux/amd64"
fi

echo "Building [ ${IMAGE} ] as [ ${IMAGE_TAG} ]"

docker build ${PLATFORM_FLAG} --file "${IMAGE}/Dockerfile" --tag "${IMAGE_TAG}" "${IMAGE}"

if [[ -f "${IMAGE}/test/container-structure-test.yml" ]]; then
echo "Running container structure test for [ ${IMAGE_TAG} ]"

docker run --rm ${PLATFORM_FLAG} \
--volume /var/run/docker.sock:/var/run/docker.sock \
--volume "${PWD}:/workspace" \
--workdir /workspace \
"${CONTAINER_STRUCTURE_TEST_IMAGE}" \
test --image "${IMAGE_TAG}" --config "/workspace/${IMAGE}/test/container-structure-test.yml"
fi

0 comments on commit 043c17d

Please sign in to comment.