|
| 1 | +name: CI/CD Pipeline |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "**" ] |
| 6 | + tags: [ "*" ] |
| 7 | + pull_request: |
| 8 | + branches: [ main ] |
| 9 | + |
| 10 | +env: |
| 11 | + DOCKER_IMAGE_NAME: ghcr.io/${{ github.repository }} |
| 12 | + DOCKER_IMAGE_TAG: ${{ github.ref_name }} |
| 13 | + |
| 14 | +jobs: |
| 15 | + test: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + - name: Run placeholder tests |
| 20 | + run: echo "No unit tests / coverage defined yet — please add tests." |
| 21 | + |
| 22 | + build: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + needs: test |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Normalize DOCKER_IMAGE_NAME to lowercase (fix for capitalized org) |
| 29 | + run: echo "DOCKER_IMAGE_NAME=${DOCKER_IMAGE_NAME,,}" >> $GITHUB_ENV |
| 30 | + |
| 31 | + - name: Log in to GitHub Container Registry |
| 32 | + uses: docker/login-action@v3 |
| 33 | + with: |
| 34 | + registry: ghcr.io |
| 35 | + username: ${{ github.actor }} |
| 36 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 37 | + |
| 38 | + - name: Build and Push Docker Image |
| 39 | + shell: bash |
| 40 | + run: | |
| 41 | + DOCKER_ARG_PARAM="latest" |
| 42 | + if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then |
| 43 | + DOCKER_ARG_PARAM="${GITHUB_REF_NAME}" |
| 44 | + fi |
| 45 | + if [[ "${GITHUB_REF_NAME}" == "release-candidate" || "${GITHUB_REF_NAME}" == "master" ]]; then |
| 46 | + DOCKER_ARG_PARAM="${GITHUB_REF_NAME}" |
| 47 | + fi |
| 48 | +
|
| 49 | + BASE_IMAGE="ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/ngen:${DOCKER_ARG_PARAM}" |
| 50 | +
|
| 51 | + echo "Building with BASE_IMAGE=$BASE_IMAGE" |
| 52 | +
|
| 53 | + docker build \ |
| 54 | + --build-arg BASE_IMAGE=$BASE_IMAGE \ |
| 55 | + --build-arg CI_COMMIT_REF_NAME=${GITHUB_REF_NAME} \ |
| 56 | + --tag $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG . |
| 57 | +
|
| 58 | + docker push $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG |
| 59 | +
|
| 60 | + deploy: |
| 61 | + runs-on: ubuntu-latest |
| 62 | + needs: build |
| 63 | + if: github.ref_name == 'development' |
| 64 | + steps: |
| 65 | + - name: Log in to GitHub Container Registry |
| 66 | + uses: docker/login-action@v3 |
| 67 | + with: |
| 68 | + registry: ghcr.io |
| 69 | + username: ${{ github.actor }} |
| 70 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 71 | + - name: Push :latest tag |
| 72 | + run: | |
| 73 | + docker pull $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG |
| 74 | + docker tag $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG $DOCKER_IMAGE_NAME:latest |
| 75 | + docker push $DOCKER_IMAGE_NAME:latest |
| 76 | +
|
| 77 | + release: |
| 78 | + runs-on: ubuntu-latest |
| 79 | + needs: build |
| 80 | + if: startsWith(github.ref, 'refs/tags/') |
| 81 | + steps: |
| 82 | + - name: Log in to GitHub Container Registry |
| 83 | + uses: docker/login-action@v3 |
| 84 | + with: |
| 85 | + registry: ghcr.io |
| 86 | + username: ${{ github.actor }} |
| 87 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 88 | + - name: Push tag version |
| 89 | + run: | |
| 90 | + docker pull $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG |
| 91 | + docker tag $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG $DOCKER_IMAGE_NAME:${GITHUB_REF_NAME} |
| 92 | + docker push $DOCKER_IMAGE_NAME:${GITHUB_REF_NAME} |
0 commit comments