chore(deps): update dependency eslint to v9.20.0 (#977) #1913
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 | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
concurrency: | |
group: ci-cd-${{ github.ref }} | |
cancel-in-progress: true | |
env: | |
DOCKER_REGISTRY: ghcr.io/patmoreau/holefeeder | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
IS_PULL_REQUEST: ${{ github.event_name == 'pull_request' }} | |
IS_PUSH_TO_MAIN: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} | |
jobs: | |
debug: | |
name: Debug | |
runs-on: ubuntu-latest | |
steps: | |
- name: Debug Action | |
uses: hmarr/debug-action@v3 | |
check_changes: | |
uses: patmoreau/workflow-config/.github/workflows/check-changes-action.yml@main | |
with: | |
file_patterns: ${{ vars.CICD_CODE_FILE_PATTERNS }} | |
set-version: | |
name: Set version | |
runs-on: ubuntu-latest | |
needs: check_changes | |
if: needs.check_changes.outputs.code_was_changed == 'true' | |
outputs: | |
version: ${{ steps.gitversion.outputs.majorMinorPatch }} | |
assembly-version: ${{ steps.gitversion.outputs.semVer }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Disable workflow commands | |
run: | | |
echo "::stop-commands::`echo -n ${{ github.token }} | sha256sum | head -c 64`" | |
- name: Ensure .NET Installed | |
uses: actions/setup-dotnet@v4 | |
with: | |
global-json-file: ./global.json | |
- name: Install GitVersion | |
uses: gittools/actions/gitversion/[email protected] | |
with: | |
versionSpec: '5.x' | |
- name: Determine Version | |
id: gitversion | |
uses: gittools/actions/gitversion/[email protected] | |
with: | |
useConfigFile: true | |
configFilePath: GitVersion.yml | |
- name: Display GitVersion outputs | |
run: | | |
echo "MajorMinorPatch: ${{ steps.gitversion.outputs.majorMinorPatch }}" | |
echo "SemVer: ${{ steps.gitversion.outputs.semVer }}" | |
- name: Enable workflow commands | |
run: | | |
echo "::`echo -n ${{ github.token }} | sha256sum | head -c 64`::" | |
build: | |
name: Build | |
needs: set-version | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
target: [api, web] | |
env: | |
VERSION: ${{ needs.set-version.outputs.version }} | |
ASSEMBLY_VERSION: ${{ needs.set-version.outputs.assembly-version }} | |
DOCKERFILE_PATH: '' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v3 | |
with: | |
install: true | |
- name: Set Dockerfile path | |
id: dockerfile-path | |
run: echo "DOCKERFILE_PATH=./src/Holefeeder.${{ matrix.target == 'api' && 'Api' || 'Web' }}/Dockerfile" >> $GITHUB_ENV | |
- name: Restore Docker cache for ${{ matrix.target }} | |
uses: actions/cache@v4 | |
with: | |
path: /tmp/.buildx-${{ matrix.target }}-cache | |
key: ${{ runner.os }}-${{ matrix.target }}-${{ hashFiles(env.DOCKERFILE_PATH) }} | |
restore-keys: | | |
${{ runner.os }}-${{ matrix.target }}- | |
- name: Build ${{ matrix.target }} container | |
uses: docker/build-push-action@v6 | |
with: | |
load: true | |
context: . | |
file: ${{ env.DOCKERFILE_PATH }} | |
build-args: BUILD_VERSION=${{ env.VERSION }} | |
push: false | |
tags: holefeeder/holefeeder-${{ matrix.target }}:${{ env.VERSION }} | |
cache-from: type=local,src=/tmp/.buildx-${{ matrix.target }}-cache | |
cache-to: type=local,mode=max,dest=/tmp/.buildx-${{ matrix.target }}-cache-new | |
# Temp fix | |
# https://github.com/docker/build-push-action/issues/252 | |
# https://github.com/moby/buildkit/issues/1896 | |
- name: Move cache | |
run: | | |
rm -rf /tmp/.buildx-${{ matrix.target }}-cache | |
mv /tmp/.buildx-${{ matrix.target }}-cache-new /tmp/.buildx-${{ matrix.target }}-cache | |
- name: Save Docker cache for ${{ matrix.target }} | |
uses: actions/cache@v4 | |
with: | |
path: /tmp/.buildx-${{ matrix.target }}-cache | |
key: ${{ runner.os }}-${{ matrix.target }}-${{ hashFiles(env.DOCKERFILE_PATH) }} | |
tests: | |
name: Tests | |
needs: [set-version, build] | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
target: [api-unit-tests, api-functional-tests] | |
env: | |
VERSION: ${{ needs.set-version.outputs.version }} | |
ASSEMBLY_VERSION: ${{ needs.set-version.outputs.assembly-version }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Setup docker compose .env | |
run: | | |
printf "COMPOSE_DOCKER_CLI_BUILD=1 | |
DOCKER_BUILDKIT=1" > .env | |
- name: Restore Docker cache for api | |
uses: actions/cache@v4 | |
with: | |
path: /tmp/.buildx-api-cache | |
key: ${{ runner.os }}-api-${{ hashFiles('./src/Holefeeder.Api/Dockerfile') }} | |
restore-keys: | | |
${{ runner.os }}-api- | |
- name: Restore Docker cache for web | |
uses: actions/cache@v4 | |
with: | |
path: /tmp/.buildx-web-cache | |
key: ${{ runner.os }}-web-${{ hashFiles('./src/Holefeeder.Web/Dockerfile') }} | |
restore-keys: | | |
${{ runner.os }}-web- | |
- name: Running ${{ matrix.target }} | |
run: | | |
docker compose --env-file .env -f docker-compose-tests.yaml -f docker-compose-tests.override.yaml run ${{ matrix.target }} | |
- name: Tests cleanup | |
run: | | |
docker compose --env-file .env -f docker-compose-tests.yaml -f docker-compose-tests.override.yaml down | |
docker compose --env-file .env -f docker-compose-tests.yaml -f docker-compose-tests.override.yaml rm --force --all | |
- name: Upload test results | |
uses: actions/upload-artifact@v4 | |
with: | |
name: test-results-${{ matrix.target }} | |
path: ./tests-results/**/*.trx | |
retention-days: 1 # Keep for 1 day | |
tests-reporter: | |
name: Tests reporter | |
needs: [tests] | |
runs-on: ubuntu-latest | |
env: | |
BADGE_COLOR: '' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Download test results | |
uses: actions/download-artifact@v4 | |
with: | |
path: ./tests-results | |
pattern: test-results-* | |
merge-multiple: true | |
- name: Test Report | |
uses: dorny/test-reporter@v1 | |
id: test-results | |
if: always() | |
with: | |
name: .Net Tests | |
path: ./tests-results/**/*.trx | |
reporter: dotnet-trx | |
- name: Set badge color | |
shell: bash | |
run: | | |
case ${{ steps.test-results.outputs.conclusion }} in | |
success) | |
echo "BADGE_COLOR=31c653" >> $GITHUB_ENV | |
;; | |
failure) | |
echo "BADGE_COLOR=800000" >> $GITHUB_ENV | |
;; | |
esac | |
- name: Create badge | |
uses: emibcn/[email protected] | |
with: | |
label: Tests | |
status: '${{ steps.test-results.outputs.passed }} passed, ${{ steps.test-results.outputs.failed }} failed, ${{ steps.test-results.outputs.skipped }} skipped: ${{ steps.test-results.outputs.conclusion }}' | |
color: ${{ env.BADGE_COLOR }} | |
path: holefeeder-tests-badge.svg | |
- name: Upload badge to artifacts | |
if: always() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: Test Results Badge | |
path: | | |
holefeeder-tests-badge.svg | |
- name: Upload badge to Gist | |
if: github.ref == 'refs/heads/main' | |
uses: exuanbo/actions-deploy-gist@v1 | |
with: | |
token: ${{ secrets.GIST_TOKEN }} | |
gist_id: 230a77d0ee69381bbe869c0fc62f9cc6 | |
file_path: holefeeder-tests-badge.svg | |
file_type: text | |
tagging: | |
needs: [set-version, tests] | |
uses: patmoreau/workflow-config/.github/workflows/tag-version.yml@main | |
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} | |
with: | |
version: ${{ needs.set-version.outputs.version }} | |
publish-docker-images: | |
name: Publish Docker Images | |
needs: [set-version, tests, tagging] | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
target: [api, web] | |
env: | |
VERSION: ${{ needs.set-version.outputs.version }} | |
ASSEMBLY_VERSION: ${{ needs.set-version.outputs.assembly-version }} | |
DOCKERFILE_PATH: '' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GHCR | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.DOCKER_REGISTRY }} | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set Dockerfile path | |
id: dockerfile-path | |
run: echo "DOCKERFILE_PATH=./src/Holefeeder.${{ matrix.target == 'api' && 'Api' || 'Web' }}/Dockerfile" >> $GITHUB_ENV | |
- name: Restore Docker cache for ${{ matrix.target }} | |
uses: actions/cache@v4 | |
with: | |
path: /tmp/.buildx-${{ matrix.target }}-cache | |
key: ${{ runner.os }}-${{ matrix.target }}-${{ hashFiles(env.DOCKERFILE_PATH) }} | |
restore-keys: | | |
${{ runner.os }}-${{ matrix.target }}- | |
- name: Publish ${{ matrix.target }} container | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
file: ${{ env.DOCKERFILE_PATH }} | |
target: final | |
build-args: BUILD_VERSION=${{ env.VERSION }} | |
push: true | |
tags: ${{ env.DOCKER_REGISTRY }}/holefeeder-${{ matrix.target }}:${{ env.VERSION }} | |
cache-from: type=local,src=/tmp/.buildx-${{ matrix.target }}-cache | |
deploy: | |
name: Deploy to DigitalOcean | |
needs: [set-version, tests, publish-docker-images] | |
runs-on: ubuntu-latest | |
env: | |
VERSION: ${{ needs.set-version.outputs.version }} | |
ENVIRONMENT: Production | |
environment: | |
name: production | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Create .env.secrets file | |
run: | | |
printf " | |
COMPOSE_PROJECT_NAME=holefeeder | |
COMPOSE_DOCKER_CLI_BUILD=1 | |
DOCKER_BUILDKIT=1 | |
DOCKER_REGISTRY=${{ env.DOCKER_REGISTRY }} | |
VERSION=${{ env.VERSION }} | |
ASSEMBLY_VERSION=${{ env.VERSION }} | |
ENV=${{ env.ENVIRONMENT }} | |
DOMAIN=drifterapps.app | |
SEQ_API_KEY=${{ secrets.SEQ_APIKEY }} | |
POSTGRES_DB=${{ vars.POSTGRES_DB }} | |
POSTGRES_USER=${{ vars.POSTGRES_USER }} | |
POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }} | |
POSTGRES_APP_DB=${{ vars.POSTGRES_APP_DB }} | |
POSTGRES_APP_USER=${{ vars.POSTGRES_APP_USER }} | |
POSTGRES_APP_PASSWORD=${{ secrets.POSTGRES_APP_PASSWORD }} | |
" > $GITHUB_WORKSPACE/.env | |
- name: Create Docker config | |
run: | | |
mkdir -p ~/.docker | |
auth_string="$(echo -n "${{ secrets.READ_PACKAGES_TOKEN }}" | base64)" | |
echo '{ | |
"auths": { | |
"ghcr.io": { | |
"auth": "'"$auth_string"'" | |
} | |
} | |
}' > $GITHUB_WORKSPACE/.docker/config.json | |
- name: Set up SSH | |
uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.DIGITALOCEAN_SSH_KEY }} | |
- name: Securely copy Docker config, Docker Compose file, and .env file to the remote server | |
run: | | |
scp -v -o StrictHostKeyChecking=no -r $GITHUB_WORKSPACE/.docker ${{ vars.DIGITALOCEAN_USER }}@${{ vars.DIGITALOCEAN_HOST }}:~/ | |
scp -v -o StrictHostKeyChecking=no $GITHUB_WORKSPACE/docker-compose.yaml $GITHUB_WORKSPACE/docker-compose.Production.yaml $GITHUB_WORKSPACE/.env ${{ vars.DIGITALOCEAN_USER }}@${{ vars.DIGITALOCEAN_HOST }}:~/ | |
- name: Deploy to server | |
run: | | |
ssh -o StrictHostKeyChecking=no ${{ vars.DIGITALOCEAN_USER }}@${{ vars.DIGITALOCEAN_HOST }} " | |
echo ${{ secrets.DOCKER_HUB_TOKEN }} | docker login -u ${{ secrets.DOCKER_HUB_USER }} --password-stdin && | |
docker compose -f ~/docker-compose.yaml -f ~/docker-compose.Production.yaml pull && | |
docker compose -f ~/docker-compose.yaml -f ~/docker-compose.Production.yaml up -d" | |
create_check: | |
needs: [check_changes, tests] | |
uses: patmoreau/workflow-config/.github/workflows/create-check.yml@main | |
if: always() && needs.check_changes.result == 'success' | |
with: | |
code_was_changed: ${{ needs.check_changes.outputs.code_was_changed }} | |
check_name: 'build-completed' | |
check_result: ${{ needs.tests.result }} |