Skip to content

Instantly share code, notes, and snippets.

@guibranco
Last active December 15, 2023 15:39
Show Gist options
  • Save guibranco/9e7f8512cacf768b3cd3382fbbee8cd4 to your computer and use it in GitHub Desktop.
Save guibranco/9e7f8512cacf768b3cd3382fbbee8cd4 to your computer and use it in GitHub Desktop.
Sample CI GitHub Action file for .NET Framework (MSBuild)
name: CI
on:
push:
branches: [ main ]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
name: Build
runs-on: windows-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Set solution name
run: |
echo "solution=$(([io.fileinfo]$(Get-ChildItem -Path .\* -Include *.sln)).name)" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Setup MSBuild Path
uses: microsoft/[email protected]
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
- name: Setup Nuget
uses: NuGet/setup-nuget@v1
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
- name: Restore NuGet Packages
run: nuget restore "${{ env.solution }}"
- name: Build Release
run: msbuild "${{ env.solution }}" -m /p:Configuration=Release /p:DeployOnBuild=true /p:PublishProfile=FolderPublish /p:RestoreLockedMode=true
- name: Upload Core artifacts
uses: actions/upload-artifact@v3
with:
name: Core
path: Publish\Core
deploy_core:
name: Deploy Core
needs: build
runs-on: ubuntu-latest
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: Core
- name: Upload to ftp
uses: sebastianpopp/ftp-action@releases/v2
with:
host: ${{ secrets.FTP_SERVER }}
user: ${{ secrets.FTP_USERNAME }}
password: ${{ secrets.FTP_PASSWORD }}
remoteDir: Core
forceSsl: true
create_release:
name: Create Release
needs: [deploy_core]
runs-on: ubuntu-latest
steps:
- name: Download artifact Core
uses: actions/download-artifact@v3
with:
name: Core
path: Core
- name: Zip artifact
run: |
zip -r Core.zip ./Core/*
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.run_number }}
release_name: Release ${{ github.run_number }}
body: New release of ${{ env.solution }}
draft: false
prerelease: false
- name: Upload Core
id: upload_core
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./Core.zip
asset_name: Core.zip
asset_content_type: application/zip
- name: Send Webhook
uses: distributhor/workflow-webhook@v3
env:
webhook_type: 'json-extended'
event_name: 'release'
webhook_url: ${{ secrets.RELEASE_WEBHOOK_URL }}
webhook_secret: '{"x-github-release-token": "${{ secrets.RELEASE_WEBHOOK_TOKEN }}"}'
data: '{ "tag_name": "${{ github.run_number }}", "assets": [{ "name" : "Core.zip", "browser_download_url": "${{ steps.upload_core.outputs.browser_download_url }}" } ] }'
cleanup:
name: Cleanup
needs: create_release
runs-on: ubuntu-latest
steps:
- name: Remove artifacts
uses: geekyeggo/delete-artifact@v2
with:
name: "*"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment