-
Notifications
You must be signed in to change notification settings - Fork 1
40 lines (38 loc) · 1.53 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
name: Validate Configuration and Build Docker image
on:
push:
tags:
- '*'
jobs:
build_docker_image_and_validate:
runs-on: ubuntu-latest
container:
image: docker:20
permissions:
packages: write
contents: read
env:
CI_REGISTRY_USER: ${{ github.actor }}
CI_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
CI_REGISTRY: ghcr.io
CI_REGISTRY_IMAGE: ghcr.io/${{ github.repository }}
steps:
- uses: actions/checkout@v3
- name: Verify Tag Format
run: |
echo $GITHUB_REF_NAME | grep -oE '^([0-9]+\.){2}[0-9]+$' || (echo "ERROR: Invalid tag format, should be a three part version number (e.g. 1.2.3)" && exit 1)
- name: Build Docker Image
run: |
IMAGE_TAG=$(echo "$CI_REGISTRY_IMAGE:$GITHUB_REF_NAME" | tr [:upper:] [:lower:])
docker build . -t $IMAGE_TAG
- name: Validate Configuration
run: |
IMAGE_TAG=$(echo "$CI_REGISTRY_IMAGE:$GITHUB_REF_NAME" | tr [:upper:] [:lower:])
docker run --rm $IMAGE_TAG python validate.py
- name: Push Docker Image
run: |
IMAGE_TAG=$(echo "$CI_REGISTRY_IMAGE:$GITHUB_REF_NAME" | tr [:upper:] [:lower:])
echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --password-stdin
if docker pull $IMAGE_TAG > /dev/null 2>&1; then echo "ERROR: An image with the given tag already exists. Please increment the contents of the VERSION file" && exit 1; fi
docker push $IMAGE_TAG
timeout-minutes: 5