I have the following GitHub actions workflow for a C# (.net 6) project that works fine with ubuntu-latest. But for some reason we need it to use windows-latest, it breaks with the error (the error after yaml workflow).
Yaml workflow:
jobs:
build:
name: Create Release
runs-on: windows-latest
steps:
- name: Setup Checkout
uses: actions/checkout#v2
- name: Setup .NET
uses: actions/setup-dotnet#v1
with:
dotnet-version: 6.0.x
- name: Restore .NET dependencies
run: dotnet restore
- name: Build .NET
run: dotnet build --no-restore
- name: Test .NET
run: dotnet test --no-build --verbosity normal
- name: Publish .NET
run: |
dotnet publish /p:PublishProfile=Release-win-x86 -c Release
dotnet publish /p:PublishProfile=Release-win-x64 -c Release
- name: Upload Published Artifact
uses: actions/upload-artifact#v2
with:
name: softwarename
path: |
/home/runner/work/solution/project/Software/win-x86/
/home/runner/work/solution/project/Software/win-x64/
The error:
Upload Published Artifact
Run actions/upload-artifact#v2
Warning: No files were found with the provided path:
/home/runner/work/solution/project/Software/win-x86/
/home/runner/work/solution/project/Software/win-x64/. No artifacts will be uploaded.
Download Published Artifact
Run actions/download-artifact#v2
Starting download for softwarename
Error: Unable to find any artifacts for the associated workflow
I read here that I need to change actions/upload-artifact#v2 to actions/upload-artifact#v2.2.4, that I tried and failed with the same error.
Any Idea how to fix this issue?
I give credit for #jessehouwing for making me a ware of the concept.
Regarding this thread, my solution needed ${{ github.workspace }}, so that my changes looks like this:
${{ github.workspace }}\Software\win-x86
${{ github.workspace }}\Software\win-x64
Don't rely on:
/home/runner/work/solution/project
Instead use
${{ github.workspace }}/project
That way it points to the correct path for the runner independent of the operating system and configuration
Related
I have an ASP .NET Core website whose source code is stored in GitHub. This is automatically deployed to an Azure App Service (running on Linux) when I do a check-in to GitHub. (I set this up a while back using the Azure "wizard", but now I can't find any way to tinker with it).
Recently I added a unit test project to my solution, and when I checked that in the unit test project was deployed along with the web project - which I don't want. (Especially since the runtime host gets confused about which DLL it should run, and decides to run neither - so the website does not start!).
Is there a way to prevent the unit test project from being built or deployed? (I'm happy just to run these tests locally). I'm not even sure where to start - would I do this in GitHub, or in the Azure portal? I can't find any likely-looking knobs or levers either in GitHub or in the Azure portal.
Update: I've found a file that has been created in my repo in a .github/workflows folder. Here's the content:
name: Build and deploy ASP.Net Core app to Azure Web App - MyApp
on:
push:
branches:
- master
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Set up .NET Core
uses: actions/setup-dotnet#v1
with:
dotnet-version: '5.0.x'
include-prerelease: true
- name: Build with dotnet
run: dotnet build --configuration Release
- name: dotnet publish
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp
- name: Upload artifact for deployment job
uses: actions/upload-artifact#v2
with:
name: .net-app
path: ${{env.DOTNET_ROOT}}/myapp
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact#v2
with:
name: .net-app
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy#v2
with:
app-name: 'My-App'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_0C864EC866B247EABE271A962BE84378 }}
package: .
While that's progress, I still can't see where I could modify it to prevent it from including the unit test project, because it doesn't actually reference anything directly.
Here's what worked for me:
I changed:
run: dotnet build --configuration Release
...to:
run: dotnet build MyProject --configuration Release
...where MyProject is the name of the folder containing the website project. (dotnet build is run from the solution folder, and the default behavior is that it will build all projects in the solution; specifying a sub-folder name makes it build only the project(s) it finds in that folder - see the documentation here).
Similarly, I changed:
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp
to:
run: dotnet publish MyProject -c Release -o ${{env.DOTNET_ROOT}}/myapp
Thanks to #LexLi for pointing me in the right direction.
I am using another Git Repo as library, which uses a different .net Version and has missing Permissions to be build on Action.
How do i exclude this/all sub modules from being built ?
Error Codes being Produced:
error MSB3191: Unable to create directory "obj/Debug/". Access to the path '/home/runner/work/Repo/Project/Submodule/Folder/obj/Debug/' is denied.
error MSB3644: The reference assemblies for .NETFramework,Version=v2.0 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application...
Workflow File (dotnet.yml)
name: .NET
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: textbook/git-checkout-submodule-action#master
- name: Setup .NET
uses: actions/setup-dotnet#v1
with:
dotnet-version: 5.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
I have the following action on Github actions that automatically packs and deploy a package to nuget.org every time a PR gets merged into master.
name: Nuget Deploy
on:
push:
branches: [ master ]
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout#v2
- name: Setup .NET Core
uses: actions/setup-dotnet#v1
with:
dotnet-version: 3.1.101
- name: Generate Nuget package
run: dotnet pack
working-directory: DateOverride
- name: Deploy to nuget.org
run: dotnet nuget push *.nupkg -k ${{ secrets.NUGET_DEPLOY_KEY }} -s https://api.nuget.org/v3/index.json
working-directory: DateOverride/DateOverride/bin/Debug
But I would like that it was not run if my update is only a README.md update, is it possible to do so?
I'd think the paths-ignore setting should help:
on:
push:
branches:
- master
paths-ignore:
- '**/README.md'
You might want to combine your current GitHiub Action with another like MarceloPrado/has-changed-path
This action outputs whether a path or combination of paths has changed in the previous commit.
[This] action is meant to be used inside your job steps, not at the root of your workflow file
Or (opposite filter): dorny/paths-filter
With this Github Action you can execute your workflow steps only if relevant files are modified.
I usually hide my API key in an XML file and use .gitignore along with getString() to retrieve my API key.
I'm trying to use Github Actions to automate Gradle build and Release of debug apk's. Due to the XML file not being uploaded to the repo, it obviously fails.
Is there any way to store my key in Github Secrets and then replace the code with the secret?
Current code: headers["token"]= getString(R.string.token)
Replaced code in Github actions server : headers["token"]="MY_API_KEY_FROM_SECRETS"
Here's my YAML file that I was using:
name: Gradle build test and release
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: set up JDK 1.8
uses: actions/setup-java#v1
with:
java-version: 1.8
#I'd like to replace the api key here in code from secrets
- name: Make Gradle executable
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew build
- name: Build Debug APK
run: ./gradlew assembleDebug
- name: Releasing using Hub
uses: ShaunLWM/action-release-debugapk#master
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
APP_FOLDER: app
RELEASE_TITLE: New Build
BODY: github.event.head_commit.message
prerelease: true
Sure, this is possible. You haven't said what file you'd like modified, but this should be easy enough to do with a one-liner (replacing FILENAME with your config file name):
- run: perl -pi -e 's/getString\(R\.string\.token\)/"$ENV{TOKEN}"/' FILENAME
env:
TOKEN: ${{ secrets.TOKEN }}
If you prefer Ruby or some other scripting language, you can use that instead. You could also use sed, but I prefer this approach because it means that the value is never available in ps output (even if this is a locked down VM).
I'm having an issue with uploading artifacts to github from within a workflow.
This is my yaml file:
on:
push:
branches:
- master
jobs:
build:
name: build and test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- name: Install robotframework and dependencies
run: |
pip install selenium
pip install robotframework
pip install robotframework-seleniumlibrary
pip install robotframework-imaplibrary
pip install robotframework-httplibrary
pip install robotframework-requests
- name: Download and install chromedriver
run: |
wget http://chromedriver.storage.googleapis.com/77.0.3865.10/chromedriver_linux64.zip
sudo unzip chromedriver_linux64.zip -d /usr/local/bin
export CHROME_BIN=chromium-browser
- name: Run robot tests
run: |
cd robot/tests
python -m robot -i ready bookingform.robot
- name: publish test results
uses: actions/upload-artifact#v1
with:
name: report
path: report.html
- name: clean up stuff
run: |
history
pwd
Everything runs fine up until "publish test results", at which point nothing is written to the logs and no artifacts are uploaded. If I view the workflow log, there is a grey icon alongside that step (not the usual check or red x), so I'm really baffled at what could be happening. I added arbitrary stuff to the "clean up stuff" step just to test what happens, and that step isn't run either.
I've tried messing around with the path, thinking that it could be related to the path being invalid or something, but that hasn't helped. No matter what I add near the bottom of that file, the same behaviour occurs.
I have tried running another workflow file which uploads artifacts and that ran fine, the logs showed that the upload action was invoked and that the artifact was saved, but I don't see anything like that when my yaml file is used.
Each job step resets the working path to GITHUB_WORKSPACE, which will be the root of your repository after actions/checkout runs.
The upload-artifact action most likely can't find report.html because it's no longer in the correct directory.
Try changing the path as follows:
- name: publish test results
uses: actions/upload-artifact#v1
with:
name: report
path: robot/tests/report.html
There is also a working-directory that you can set for a step. However, it seems to be incompatible with uses for actions. It can only apply to run script steps.
Using working-directory with uses will NOT work:
- name: publish test results
working-directory: robot/tests
uses: actions/upload-artifact#v1
with:
name: report
path: report.html
Using working-directory with run will work:
- name: print test results
working-directory: robot/tests
run: cat report.html
Tasks are not executed, if previous Tasks have failed; see Status check functions.
Using if: ${{ failure() }} a Task only executes, if the previous Task has failed.
So for me it solved the Problem to add if: ${{ failure() }}:
- name: Upload Cypress Artifacts
if: ${{ failure() }}
uses: actions/upload-artifact#v3
with:
path: ./cypress