Easy CD with GitHub Workflows

When working on small utilities / tools kind of projects that you upload somewhere for others to be able to quickly get them, more often than not it becomes difficult to re-upload after you add a new feature, especially if some time has passed by since the last upload.

Here GitHub workflows come to help. Every time you push something to a specific branch, GitHub can trigger an action to run a small script that can compile your application, run unit tests, publish it and upload it to the desired download site.

One of my simplest workflows looks like this:

name: .NET Core
      - master
    runs-on: windows-latest
    - name: Display the path
      run: echo $PWD
      shell: bash
    - uses: actions/checkout@v2
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
        dotnet-version: '3.1.100'
    - name: Publishing
      run: dotnet publish --configuration Release --self-contained:false
    - name: Installing lftp
      run: choco install lftp
    - name: Uploading to ftp
      run: lftp ${{ secrets.FTP_SERVER }} -u ${{ secrets.FTP_USERNAME }},${{ secrets.FTP_PASSWORD }} -e "set ftp:ssl-allow no; set ssl:verify-certificate no; mirror --reverse --continue --dereference -x ^\.git/$ ScreenZoomPlus\\bin\\Release\\netcoreapp3.1\\win-x86\\publish ScreenZoomPlus; quit"

(the file goes inside the repository, in the .github\workflows\name-of-the-file.yaml)

The file is kind of self descriptive (but there is also plenty of documentation):

The workflow is triggered every time something is pushed on the master branch. Usually, on my hobby-projects, I work on a dev branch and when I’m happy with what I did, I push everything to the master branch. Then the GitHub action kicks in.

Everything is run in like a VM environment, nothing is preinstalled, so first step is to make sure .Net core is there. Then dotnet publish is called to build and create the final executable with all the dependencies.

The tricky part was to upload the exe file to FTP. For that I install lftp (through Chocolatey) and lftp is able to upload to a FTP server.

Some variables (secrets.FTP_SERVER, FTP_USERNAME and FTP_PASSWORD) are then used in order not to keep the sensitive data in plain text in the repositories (modern CI/CD). These variables are defined in the Settings > Secrets section of the GitHub repository.

Leave a Reply

Your email address will not be published. Required fields are marked *