Docker Publish from Develop #31
This file contains hidden or 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: Docker Publish from Develop | |
on: | |
workflow_dispatch: | |
inputs: | |
run_tests: | |
description: 'Run Tests' | |
required: false | |
default: true | |
type: boolean | |
version: | |
description: 'Release Version' | |
required: true | |
type: string | |
jobs: | |
build: | |
name: Build, Test & Publish to Docker Hub | |
runs-on: ubuntu-latest | |
permissions: | |
checks: write | |
contents: read | |
env: | |
BUILD_CONFIG: 'Release' | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: 'develop' | |
# Checkout and build frontend from leadcms.admin (develop branch) | |
- name: Checkout frontend (leadcms.admin) | |
uses: actions/checkout@v3 | |
with: | |
repository: LeadCMS/leadcms.admin | |
ref: develop | |
path: leadcms.admin | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20.19.0' | |
cache: 'npm' | |
cache-dependency-path: leadcms.admin/package-lock.json | |
- name: Set frontend environment variables | |
run: | | |
echo "TINYMCE_API_KEY=${{ secrets.TINYMCE_API_KEY }}" > ./leadcms.admin/.env | |
echo "VERSION=${{ github.event.inputs.version }}" >> ./leadcms.admin/.env | |
- name: Install frontend dependencies | |
working-directory: ./leadcms.admin | |
run: npm ci | |
- name: Build frontend | |
working-directory: ./leadcms.admin | |
run: npm run build | |
- name: Copy frontend build to backend wwwroot | |
run: | | |
mkdir -p ./src/LeadCMS/wwwroot | |
rm -rf ./src/LeadCMS/wwwroot/* | |
cp -r ./leadcms.admin/dist/* ./src/LeadCMS/wwwroot/ | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: 8.0.x | |
- name: Setup NuGet | |
uses: nuget/setup-nuget@v1 | |
with: | |
nuget-version: 'latest' | |
- name: Docker Compose Setup | |
if: ${{ github.event.inputs.run_tests == 'true' }} | |
run: docker compose -f ./docker-compose/docker-compose.tests.yml up -d | |
- name: Restore dependencies | |
run: dotnet restore | |
- name: Build | |
run: dotnet build --configuration $BUILD_CONFIG -p:Version=${{ github.event.inputs.version }} --no-restore | |
- name: Test | |
if: ${{ github.event.inputs.run_tests == 'true' }} | |
run: dotnet test --no-build --configuration $BUILD_CONFIG --logger "trx" --verbosity d --results-directory "./" | |
- name: Upload test results | |
if: ${{ github.event.inputs.run_tests == 'true' }} && (success() || failure()) | |
uses: actions/upload-artifact@v4 | |
with: | |
name: test-results | |
path: ./*.trx | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_API_USERNAME }} | |
password: ${{ secrets.DOCKER_API_KEY }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Build & Push Docker image | |
uses: docker/build-push-action@v3 | |
with: | |
context: ./ | |
file: src/LeadCMS/Dockerfile | |
push: true | |
tags: | | |
leadcms/core:develop | |
leadcms/core:${{ github.event.inputs.version }} | |
- name: Publish to NuGet | |
if: success() | |
run: dotnet nuget push **/*.nupkg --source 'https://api.nuget.org/v3/index.json' --api-key ${{secrets.NUGET_API_KEY}} |