-
Notifications
You must be signed in to change notification settings - Fork 4
67 lines (56 loc) · 1.92 KB
/
tests.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
name: tests
on:
workflow_run:
workflows: ["docker"]
types:
- completed
- success
- failure
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
IMAGE_TAG: master
jobs:
build-and-test:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Convert repository name to lowercase
id: lowercase_repo_name
uses: ASzc/change-string-case-action@v6
with:
string: ${{ env.IMAGE_NAME }}
# Store lowercase image name in an environment variable
- name: Set lowercase image name
run: echo "LOWERCASE_IMAGE_NAME=${{ steps.lowercase_repo_name.outputs.lowercase }}" >> $GITHUB_ENV
# Create environment variable for Docker image name
- name: Set image repository name
run: echo "IMAGE_REPO_NAME=${{ env.REGISTRY }}/${{ env.LOWERCASE_IMAGE_NAME }}:${{ env.IMAGE_TAG }}" >> $GITHUB_ENV
# Check if Docker image exists
- name: Check if Docker image exists
run: |
set -e
if docker pull "${{ env.IMAGE_REPO_NAME }}"; then
echo "Image successfully pulled!"
echo "IMAGE_EXISTS=true" >> $GITHUB_ENV
else
echo "::error::Failed to pull the image"
echo "IMAGE_EXISTS=false" >> $GITHUB_ENV
fi
continue-on-error: true
# Build Docker image if it doesn't exist
- name: Build Docker image if it doesn't exist
if: env.IMAGE_EXISTS != 'true'
run: |
docker build -t ${{ env.IMAGE_REPO_NAME }} .
# Run pytest tests within the Docker container
- name: Run pytest in Docker container
run: |
docker run ${{ env.IMAGE_REPO_NAME }} pytest