Skip to content

Publish docker image #29

Publish docker image

Publish docker image #29

Workflow file for this run

name: Build Project
on:
push:
branches:
- master
pull_request:
branches:
- master
workflow_dispatch: ## turn available trigger manually the workflow
# validate all workflows in the same branch, if any job fails, the others will be canceled
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
versioning:
runs-on: ubuntu-latest
name: Versioning
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
- uses: codacy/git-version@2.8.0
id: version
with:
release-branch: master
prefix: v
## prefix to version
- name: Tag do repositorio
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "::notice:: ${{ steps.version.outputs.version }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git config --global user.name "${{ github.actor }}"
git tag -a ${{ steps.version.outputs.version }} -m "Release ${{ steps.version.outputs.version }}"
git push --tags
if: github.ref == 'refs/heads/master'
build-and-tests:
needs: versioning # dependency between jobs
runs-on: ubuntu-latest
name: Build Project
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x' # Adjust the version as needed
cache: true
cache-dependency-path: ./src/**/packages.lock.json # Needs to enable cache directly in the main project first, adding that flag as true RestorePackagesWithLockFile
- uses: github/super-linter@v6
env:
DEFAULT_BRANCH: "master"
VALIDATE_ALL_CODEBASE: "false"
VALIDATE_YAML: "true"
VALIDATE_CSHARP: "true"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Restore dependencies
run: dotnet restore
- name: Build the project
run: dotnet build --configuration Release --no-restore
# Do the tests and generate the file
- name: Test
run: |
dotnet test --no-build --no-restore ./AspirePoc.sln --configuration Release --logger trx --results-directory "TestResults"
- uses: actions/upload-artifact@v4 # generate artifacts that turn available to download
with:
name: dotnet-test-results
path: TestResults
- name: Publish
run: dotnet publish ./src/AspirePoc.UI.Api/AspirePoc.UI.Api.csproj --no-restore --no-build --configuration Release --output ./publish
- name: Tag published version
uses: restackio/update-json-file-action@2.1
with:
file: ./publish/appsettings.json
fields: "{\"MY_APP_VERSION\": \"${{ needs.versioning.outputs.version }}\"}"
- name: Upload dotnet artifacts
uses: actions/upload-artifact@v4
with:
name: api
path: ./publish
dependency-check:
# validate if the code has any vulnerability
name: Dependency Check
needs: versioning
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: actions/dependency-review-action@v4
with:
comment-summary-in-pr: always
if: github.ref != 'refs/heads/master'
code-security-check:
name: Code Security Check
needs: versioning
runs-on: ubuntu-latest
permissions:
security-events: write
packages: read
actions: read
contents: read
strategy:
matrix:
include:
- name: Backend
language: csharp
build-mode: manual
steps:
- name: Checkout repository
uses: actions/checkout@v4
# needed add the setup of .NET because the version is not long term
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x' # Adjust the version as needed
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
- if: ${{ matrix.build-mode == 'manual' }}
name: Build C# code manually
run: |
echo 'Starting manual build for C# code...'
dotnet restore
dotnet build --configuration Release
echo 'Manual build complete.'
- uses: github/codeql-action/analyze@v3
name: Analyze code - ${{ matrix.name }}
with:
category: "/language:${{ matrix.language }}"
build-docker-image:
name: Packing and Publish
needs: [versioning, build-and-tests]
runs-on: ubuntu-latest
env:
version: ${{ needs.versioning.outputs.version }}
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
path: app
merge-multiple: false
- name: Build Docker image
run: |
docker build -t aspire-poc:${{ vars.DOCKERHUB_REPOSITORY }}:${{ env.version }} .
# - name: Tag Docker image as Latest
# run: |
# docker tag ${{ vars.DOCKERHUB_REPOSITORY }}:${{ env.version }} ${{ vars.DOCKERHUB_REPOSITORY }}:latest
# if: github.ref == 'refs/heads/master'
# - name: Docker Login
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}
# - name: Docker Push
# run: |
# docker push --all-tags thiagolunardi/todo-app