DEV Community

Thomas Morris
Thomas Morris

Posted on • Originally published at mozzy.dev on

2 2

GitHub Actions: an intro

There are quite a few build and deploy options available to developers these days. Previously, I have wrote about using a combination of Team City and Octopus Deploy. These are still good tools, but will likely require a bit of setup and probably require a VM.

A more recent trend is to have your actions linked to your repository, where you can have it all self contained and in one place. There are pros and cons to both, but I'm gonna show you how you might do that with GitHub Actions.

dotnet

I work mostly with .NET, so lets take a look at the workflow for that. With .NET Core you can now use Linux (and macOS) as your build target. Here we're using ubuntu-latest.

We're also setting the relevant DOTNET_VERSION and running our commands, dotnet build and dotnet publish. Problems with the build will be visible within GitHub and you can follow along with the progress.

Finally, we're pushing our published version of the app to Azure Web Apps using a publish profile. You could also choose to generate a NuGet package and push to a feed for distribution.

name: Build and deploy to Azure
on: [push]
env:
PROJECT_DIR: yourapp/path
AZURE_WEBAPP_NAME: yourapp-name
DOTNET_VERSION: '2.2.402'
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# Checkout the repo
- uses: actions/checkout@master
# Setup .NET Core SDK
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
# Run dotnet build and publish
- name: dotnet build and publish
run: |
cd ${{ env.PROJECT_DIR }}
dotnet build --configuration Release
dotnet publish -c Release -o publish
# Deploy to Azure Web apps
- name: 'Run Azure webapp deploy action using publish profile'
uses: azure/webapps-deploy@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: '${{ env.PROJECT_DIR }}/publish'

Note, you can also build .NET Framework apps, that will look a little different but the concept is the same. You'll target windows-latest as that is a prerequisite for .NET Framework, and the commands will be msbuild.

node.js

If you've got a FE repo, then you'll likely want to use npm to compile some assets and package them up. Here's how you can do that.

We've set up our NODE_VERSION and then run the commands, npm install and npm build. At that point, we might want to package up the assets or deploy as an application.

name: Build node.js
on: [push]
env:
NODE_VERSION: '10.x'
jobs:
build-assets:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# Setup Node
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v1
with:
node-version: ${{ env.NODE_VERSION }}
# Run npm build
- name: npm install, build
run: |
npm install
npm run build
# Do something with assets

other

There are lots of other options available to you, without going into all of them here, I encourage you to take a look through the docs and see what you might want for your needs.

If you're interested in what's installed on the runners, then take a look at this repo which contains the full list of software and spec for each.

The approach here can also be used for similar tools such as Bitbucket Pipelines or Azure Pipelines. Choose what fits the bill for you.

Have fun!

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay