CI/CD with GitHub and Plesk - github-actions

We succesfully use the Plesk / Github integration that deploys our developers pushes from github to our plesk stage web server using the Webhooks to have Pleask get the latest version. That works splendidly. What we try to establish additionally is auto compile the SCSS source and submit the resulting css as well to our stage web server. We have added an action to the workflow but how would the compiled products end up on our stage webserver. I'm unsure if the timing is right. Will the actinos be performed before deployment?
This is the yaml:
on:
push:
branches:
- stage
jobs:
build_css:
runs-on: ubuntu-latest
steps:
- name: Checkout source Git branch
uses: actions/checkout#v2
with:
ref: stage
fetch-depth: 10
submodules: true
- name: Make destination directory for compiled CSS
run: mkdir -vp /tmp/theme/assets/
- name: Compile CSS from SCSS files
uses: gha-utilities/sass-build#v0.4.11
with:
source: assets/src/main.scss
destination: /tmp/theme/assets/
- name: Move compiled CSS to path within stage branch
run: mv /tmp/theme/assets assets/

Related

How to make a job that doesn't depend on a matrix only run once

I have a GitHub Actions workflow containing a setup job:
setup:
runs-on: windows-latest
steps:
- name: Checkout Repository
uses: actions/checkout#v2.4.0
- name: Install .NET
uses: actions/setup-dotnet#v1.8.2
with:
dotnet-version: 6.0.x
and once setup is complete, I build for my for target platforms:
build:
needs:
- setup
runs-on: windows-latest
strategy:
matrix:
target:
- win-x64
- linux-x64
- linux-arm64
- osx-x64
self-contained:
- self-contained
- framework-dependent
steps:
- name: Checkout Repository
uses: actions/checkout#v2.4.0
- name: Install .NET
uses: actions/setup-dotnet#v1.8.2
with:
dotnet-version: 6.0.x
- name: Build
run: >-
dotnet publish -r ${{matrix.target}} --self-contained ${{
matrix.self-contained == 'self-contained' }} ${{ matrix.self-contained
&& '' || '/p:DisablePatch="--nopatch"' }}
In build, I end up duplicating the work done by setup—8 times. Is there a way to avoid this, and perhaps just copy the machine state from setup into the build job?
When you run an action (in your job steps), it will only apply to the runner used to execute the job steps.
According to the Github documentation about matrix, each matrix job runs in parallel. Therefore they will all need the setup to be executed as each provided runner starts without the Checkout Repository and Install .NET steps configured.
You can't share those setup between the runners provided by Github, because each job will use a new (and different) runner.
Which means your setup job here won't do anything that requires the needs configuration on the build job, as what it does will only applies to itself.
Therefore, removing the needs: setup on the build job would be the same as what you did.
What you could do instead for example, is using self-hosted runners with dotnet already installed, or a docker image. In that case you wouldn't need to setup dotnet every time, but is it worth the cost? (as building a docker image can take more time that doing the setup, so you should evaluate this first).

Using github actions to create a folder and upload it to a destination

Im running a job that creates a folder dist and another job that depends on the first one to be completed successfully to upload the dist folder. However I'm getting an error when uploading saying the directory doesn't exist, while it works to create the folder locally and push it to github. I don't want to push the folder to my repo is there a way to work?
name: Build Artifcats and Upload To Azure Blob Storage
on:
push:
branches:
- main
jobs:
build_on_win:
runs-on: windows-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#master
with:
node-version: 14.2.0
Running Scripts**.........
upload:
runs-on: ubuntu-latest
needs: build_on_win (Notice here I'm waiting for the artifacts to be built)
steps:
- uses: actions/checkout#v2
- uses: bacongobbler/azure-blob-storage-upload#v1.2.0
with:
source_dir: ./solutions/app/dist
container_name: 'app/latest'
connection_string: .......
sync: true
Folders (and files) aren't shared between jobs.
To achieve what you want, you will need to upload the dist directory as an artifact (using the upload action then download this artifact on the second job with the download action before performing the action you want on the second job.
You can find more information on the GHA official documentation.

Github action to lint after commit in previous step

I'm setting up Github action to lint the OpenAPI Spec using Spectral. Before linting, I would like to generate the single file spec and commit it.
I have set up a workflow that will first build and then lint. But the problem is, the lint is not considering the commit made by Github action in the previous step. It always lint for the commit that triggered this action. Is there any way to lint with the commit made as part of Github action?
You can see from the above image that Github workflow didn't run for the commit made by Github action.
Workflow file:
name: Run Spectral
on:
- pull_request
jobs:
build:
name: Build Spec
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout#v2
- name: Set up Node.js
uses: actions/setup-node#v1
with:
node-version: 12.x
- name: Install dependencies
run: npm install
- name: Build spec file
run: npm run build
- name: Commit build changes
uses: EndBug/add-and-commit#v7
with:
default_author: github_actions
message: 'Compiled spec file'
add: '_build/oas.yaml'
lint:
name: Lint
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout Repository
uses: actions/checkout#v2
- name: Spectral Linting
uses: stoplightio/spectral-action#v0.7.3
with:
file_glob: '_build/oas.yaml'
That's because commits made using the standard GITHUB_TOKEN aren't triggering workflows; you have to use a personal access token for an automated workflow that's supposed to kick off another workflow.
Quoting from the docs (linked above):
When you use the repository's GITHUB_TOKEN to perform tasks on behalf of the GitHub Actions app, events triggered by the GITHUB_TOKEN will not create a new workflow run. This prevents you from accidentally creating recursive workflow runs. [...]
If you would like to trigger a workflow from a workflow run, you can trigger the event using a personal access token. [...]

Github Action on NET.Framework project fails

I am trying to implement github actions on a .NET Framework project (v4.7.2).
Everything works until the Build step, where some references are missing. Those references haven`t been added on the project using nuGet. They are local references that were added from other directories.
This is my code:
# This is a basic workflow to help you get started with Actions
name: mySolution.CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
Build:
# The type of runner that the job will run on
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild#v1.0.2
- name: Setup NuGet
uses: NuGet/setup-nuget#v1.0.5
- name: Restore nuGet packages
run: nuget restore mySolution.sln
- name: Run MSBuild
run: msbuild mySolution.sln /t:Clean,Build /p:platform="Any CPU" /p:Configuration=R2020
So, my question is how to find these references? (assuming that is the problem) any other suggestion?
Thanks.
You have to be sure that files which are references by your project are available on build agent. So if you didn't add them to the repo please add them or make them available on build agent in another way.

##[error]No file matched with specific pattern: /appsettings.json

After reading this answer:this
I tried to do the same.
I have a .net core project and in my case, I am using a repo with a publish version so my appsettings.json is in the root of the repo.
# This is a basic workflow to help you get started with Actions
name: DeployToStaging
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
pull_request:
types: [assigned, opened, synchronize, reopened]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
FTP-Deploy-Action:
name: FTP-Deploy-Action
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2.1.0
with:
fetch-depth: 2
- uses: microsoft/variable-substitution#v1
with:
files: '${{env.DOTNET_ROOT}}/appsettings.json'
env:
ConnectionStrings.ToBudget: 'This is just a test'
- name: FTP Deploy
uses: SamKirkland/FTP-Deploy-Action#3.1.0
with:
ftp-server: <MyServer>
# FTP account username
ftp-username: <MyUsername>
ftp-password: ${{ secrets.FtpPassword }}
So basically I want to transform my connection string (for now it is just a test, in the future I will create a secret) and then push it to the server through FTP.
Everything is working except the variable substitution. The error is: No file matched with specific pattern: /appsettings.json
Any help would be much appreciated
Just found the issue.
instead of files: '${{env.DOTNET_ROOT}}/appsettings.json' I just need to do files: 'appsettings.json'
Now I am having a second issue. SamKirkland/FTP-Deploy-Action#3.1.0 doesn't like the change. It is avoiding uploading because the repo is dirty.
EDIT: regarding the second issue I moved to sebastionpopp/ftpaction