Merge pull request #40 from paulopiriquito/patch-container-registry #110
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: CI - CD | |
permissions: | |
contents: write | |
id-token: write | |
pull-requests: write | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- master | |
pull_request: | |
branches: | |
- master | |
release: | |
types: | |
- prereleased | |
- released | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repo | |
uses: actions/checkout@v3 | |
- name: Dockerhub Login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Set Docker Builder | |
uses: docker/setup-buildx-action@v2 | |
- name: Build and Push | |
id: docker_build | |
uses: docker/build-push-action@v4 | |
with: | |
context: ./src | |
file: ./docker/Dockerfile | |
push: true | |
tags: piriquito/k8s-from-secrets-vault:develop | |
- name: Image digest | |
run: echo ${{ steps.docker_build.outputs.digest }} | |
test: | |
name: Test | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Checkout Repo | |
uses: actions/checkout@v3 | |
- name: Setup Go | |
uses: actions/setup-go@v3 | |
with: | |
go-version: '1.21.3' | |
- name: Install dependencies | |
run : go mod download | |
working-directory: ./src | |
- name: Install go-junit-report | |
run: | | |
go install github.com/jstemmer/go-junit-report/v2@latest | |
working-directory: ./src | |
- name: Run tests and generate report | |
run: | | |
go test -v -coverprofile=coverage.out ./... 2>&1 | go-junit-report > ./test_report.xml | |
working-directory: ./src | |
- name: Test Summary | |
uses: test-summary/action@v2 | |
with: | |
paths: "./src/test_report.xml" | |
output: "./src/test-summary.md" | |
show: "all" | |
if: always() | |
- name: Comment on pull request | |
uses: mshick/add-pr-comment@v2 | |
if: always() | |
continue-on-error: true | |
with: | |
message-path: ./src/test-summary.md | |
- name: Fail on test failure | |
run: | | |
if [ -f ./src/test-summary.md ]; then | |
if grep -q "f=0&s=0" "./src/test-summary.md"; then | |
echo "All tests passed" | |
else | |
echo "Some tests failed" | |
exit 1 | |
fi | |
else | |
echo "No test report found" | |
exit 1 | |
fi | |
pre-release: | |
name: Pre-Release | |
runs-on: ubuntu-latest | |
needs: test | |
if: github.event_name == 'release' | |
steps: | |
- name: Dockerhub Login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Add tag to docker image | |
run: | | |
docker pull piriquito/k8s-from-secrets-vault:develop | |
docker tag piriquito/k8s-from-secrets-vault:develop piriquito/k8s-from-secrets-vault:${{ github.event.release.tag_name }} | |
- name: Push docker image | |
run: docker push piriquito/k8s-from-secrets-vault:${{ github.event.release.tag_name }} | |
release: | |
name: Release | |
runs-on: ubuntu-latest | |
needs: | |
- pre-release | |
environment: production | |
if: github.event_name == 'release' && github.event.release.draft == false && github.event.release.prerelease == false | |
steps: | |
- name: Dockerhub Login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Add latest tag to docker image | |
run: | | |
docker pull piriquito/k8s-from-secrets-vault:${{ github.event.release.tag_name }} | |
docker tag piriquito/k8s-from-secrets-vault:${{ github.event.release.tag_name }} piriquito/k8s-from-secrets-vault:latest | |
- name: Push docker images | |
run: | | |
docker push piriquito/k8s-from-secrets-vault:latest |