This repository has been archived by the owner on Oct 28, 2024. It is now read-only.
Merge pull request #399 from communitiesuk/BAU_fix_spacing_issues #1281
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: DLUHC Build and Publish | |
permissions: | |
packages: write | |
contents: write | |
on: | |
workflow_dispatch: | |
push: | |
paths-ignore: | |
[ | |
"**/README.md", | |
"fsd_config/**", | |
".github/workflows/dluhc-build-and-deploy-with-forms.yml", | |
".github/workflows/increment-version.yml", | |
"version", | |
] | |
env: | |
IMAGE_NAME_STUB: "digital-form-builder-dluhc-" | |
DOCKER_REGISTRY: ghcr.io | |
IMAGE_REPO_PATH: "ghcr.io/${{github.repository_owner}}" | |
jobs: | |
check-tag-before-build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: "Set version in env" | |
id: set-version | |
run: | | |
source version | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
- name: Check if tag exists | |
uses: mukunku/tag-exists-action@v1.0.0 | |
id: check_tag | |
with: | |
tag: ${{ env.VERSION }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Fail job if tag exists | |
if: ${{ steps.check_tag.outputs.exists == 'true' }} | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
core.setFailed('Tag already exists. Increment version file and retry') | |
lint-and-test: | |
needs: check-tag-before-build | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
app: [designer, runner, model] | |
name: lint-and-test-${{matrix.app}} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Use Node.js | |
uses: actions/setup-node@v1 | |
with: | |
node-version: "12.x" | |
- name: Get yarn cache directory path | |
id: yarn-cache-dir-path | |
run: echo "::set-output name=dir::$(yarn config get cacheFolder)" | |
- name: Configure yarn caching | |
uses: actions/cache@v2 | |
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) | |
with: | |
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- name: Install dependencies | |
run: yarn install | |
- name: Build dependencies | |
run: yarn build:dependencies | |
- name: Lint | |
run: yarn ${{matrix.app}} lint | |
- name: Test | |
run: yarn ${{matrix.app}} test-cov | |
- name: Upload test results artifacts | |
uses: actions/upload-artifact@v2 | |
if: ${{ success() || failure() }} | |
with: | |
name: test-results-${{matrix.app}} | |
path: ${{matrix.app}}/test-results | |
retention-days: 14 | |
- name: Upload test coverage artifacts | |
uses: actions/upload-artifact@v2 | |
if: ${{ success() || failure() }} | |
with: | |
name: test-coverage-${{matrix.app}} | |
path: ${{matrix.app}}/test-coverage | |
retention-days: 14 | |
build-and-push-images: | |
needs: [lint-and-test] | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
app: [designer, runner] | |
name: build-and-push-${{matrix.app}}-image | |
steps: | |
- uses: actions/checkout@v2 | |
- name: "Set version in env" | |
id: set-version | |
run: | | |
source version | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
- name: Use Node.js | |
uses: actions/setup-node@v1 | |
with: | |
node-version: "12.x" | |
- name: Docker compose pull | |
run: docker-compose pull | |
- name: Create .env for ${{ matrix.app }} workspace | |
run: | | |
touch ./${{ matrix.app }}/.env | |
echo LAST_TAG_GH=${{env.VERSION}} >> ./${{ matrix.app }}/.env | |
echo LAST_COMMIT_GH=${{ github.sha }} >> ./${{ matrix.app }}/.env | |
cat ./${{ matrix.app }}/.env | |
- name: Docker metadata | |
id: metadata | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{env.IMAGE_REPO_PATH}}/${{env.IMAGE_NAME_STUB}}${{ matrix.app }} | |
tags: | | |
type=sha,format=long | |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} | |
type=raw,value=${{env.VERSION}},enable=${{ github.ref == format('refs/heads/{0}', 'main') }} | |
type=ref,event=branch | |
- name: Log in to the Container registry | |
uses: docker/login-action@v1 | |
with: | |
registry: ${{ env.DOCKER_REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push docker image | |
uses: docker/build-push-action@v3 | |
with: | |
context: "{{defaultContext}}" | |
tags: ${{ steps.metadata.outputs.tags}} | |
labels: ${{ steps.metadata.outputs.labels }} | |
push: true | |
file: ${{matrix.app}}/Dockerfile | |
build-args: | | |
LAST_TAG='${{env.VERSION}}' | |
LAST_COMMIT='${{ github.sha }}' | |
tag-repo: | |
name: Tag repo (if main) | |
runs-on: ubuntu-latest | |
needs: [build-and-push-images] | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v2 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: "Set version in env" | |
id: set-version | |
run: | | |
source version | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
- name: Tag repo with version | |
run: | | |
git tag ${{env.VERSION}} | |
git push --tags origin HEAD |