Skip to content

Attempt to show test results #35

Attempt to show test results

Attempt to show test results #35

Workflow file for this run

name: Docker
on:
push:
branches: [ main, master, develop ]
paths-ignore:
- 'k8s/**'
workflow_run:
workflows: ["Sync"]
types:
- completed
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
TEST_TAG: unittests
jobs:
build-push:
name: Build and Deploy to Github Registry
runs-on: ubuntu-latest
outputs:
image_tag: ${{ steps.prep.outputs.BUILD_ID }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Generate build ID
id: prep
run: |
branch=${GITHUB_REF##*/}
sha=${GITHUB_SHA::8}
ts=$(date +%s)
echo "BUILD_ID=${branch}-${ts}-${sha}" >> $GITHUB_OUTPUT
# These are prerequisites for the docker build step
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build test
uses: docker/build-push-action@v4
with:
context: .
file: ./BrotatoServer/Dockerfile
cache-from: type=gha
cache-to: type=gha,mode=max
target: test
load: true
tags: ${{ env.TEST_TAG }}
- name: Test
run: |
mkdir TestResults
docker run --rm -v $(pwd)/TestResults:/src/BrotatoServer.Tests/TestResults ${{ env.TEST_TAG }}
- uses: dorny/test-reporter@v1
if: success() || failure()
with:
name: .NET Tests
path: TestResults/*.trx
reporter: dotnet-trx
- name: Ensure Lowercase Imagename
run: |
echo "IMAGE_NAME=${IMAGE_NAME,,}" >> $GITHUB_ENV
- name: Build and publish container image with tag
uses: docker/build-push-action@v3
id: build_and_publish
with:
push: true
context: .
file: ./BrotatoServer/Dockerfile
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.prep.outputs.BUILD_ID }}
update_k8s:
runs-on: ubuntu-latest
needs: build-push
steps:
- name: Check if main/master branch
run: |
if [[ ${{ github.ref }} != "refs/heads/main" && ${{ github.ref }} != "refs/heads/master" && ${{ github.ref }} != "refs/heads/develop" ]]; then exit 0; fi
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Kubectl
uses: azure/k8s-set-context@v3
with:
kubeconfig: ${{ secrets.KUBE_CONFIG_DATA }}
- name: Install Kustomize
run: |
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
sudo mv kustomize /usr/local/bin
- name: Update Kubernetes manifests
run: |
cd k8s/
kustomize create --autodetect
kustomize edit set image ghcr.io/danbopes/brotatoserver:${{ needs.build-push.outputs.image_tag }}
if [[ ${{ github.ref }} == "refs/heads/main" || ${{ github.ref }} == "refs/heads/master" ]]; then
kustomize edit set namespace brotato
else
kustomize edit set namespace brotato-dev
fi
kustomize build . > deploy.yaml
kubectl apply -f deploy.yaml
# - name: Commit and Push changes
# run: |
# git config --local user.email "[email protected]"
# git config --local user.name "GitHub Action"
# git add .
# git commit -m "Update image to latest"
# git push