During workflow execution, I produce several artifacts but after a successful build I no longer need them and I want to clean that up as I only need them temporarily.
- name: Make artifact available to use
uses: actions/upload-artifact#v2
with:
name: setup
path: setup.yml
As a part of a different job I need artifacts so I also have
- name: Download yaml file
uses: actions/download-artifact#v2
with:
name: setup
How can I add a step in the workflow (in my case, the last step) that's gonna remove these artifacts that were produced during runtime?
There are delete artifact actions on the marketplace that could help you with that.
Example with this one:
steps:
- uses: actions/checkout#v3
- run: echo hello > world.txt
- name: Make artifact available to use
uses: actions/upload-artifact#v2
with:
name: setup
path: world.txt
# delete-artifact
- uses: geekyeggo/delete-artifact#v1
with:
name: setup
I made a workflow run example here if you want to have a look.
As part of a python API for accessing GitHub. One of the examples provides a tool for waxy repository artifact build-up. Demo: https://youtu.be/lS37uCKELNM
Related
I am using this tutorial to publish my Blazor WebAssemply site to Github pages. When I run the action I get
/home/runner/work/learning-blazor/learning-blazor/Learning_Blazor.csproj : error MSB4236: The SDK 'Microsoft.NET.Sdk.BlazorWebAssembly' specified could not be found.
All other tutorials lead to the same result. Here is my main.yml:
name: Deploy to GitHub Pages
# Run workflow on every push to the master branch
on:
push:
branches: [ main ]
jobs:
deploy-to-github-pages:
# use ubuntu-latest image to run steps on
runs-on: ubuntu-latest
steps:
# uses GitHub's checkout action to checkout code form the master branch
- uses: actions/checkout#v2.4.2
# sets up .NET Core SDK 3.1
- name: Setup .NET Core SDK
uses: actions/setup-dotnet#v2.1.0
with:
dotnet-version: 3.1
# publishes Blazor project to the release-folder
- name: Publish .NET Core Project
run: dotnet publish Learning_Blazor.csproj -c Release -o release --nologo
- name: Deploy GitHub Pages site
uses: actions/deploy-pages#v1.0.10
with:
token: github.token
Can someone suggest a fix?
I was faced with the same issue, and it was caused by the dotnet-version of my app actually being .NET 7 so I changed that line to dotnet-version: 7.0.x. You can do the same for .NET 5 and 6 I imagine.
I have 2 java projects on GitHub, the first project produces a java library and the second project uses it.
The first project is build via first job in yaml file and it installs the library in /home/runner/.m2/repository/ successfully
Then when the second project is build via the second job in the same yaml file , it fails with error
Failed to execute goal on project <>: Could not resolve dependencies
for project Could not find artifact <>:jar:1.0-
SNAPSHOT -> [Help 1]
In my second project, I have included the dependency to load this library jar(produced by first project) from the repository.
MY understanding is that my second project should load the jar library from the /home/runner/.m2/repository/ but its not loading it.
Any help is appreciated.
Also can we access /home/runner/.m2/repository/ to check if it contains the library jar.
./project_account_library/account_library => Contains maven project
./project_account_service/account_service => Contains maven project
./.github/workflows/build.yml
Here is the yml file
name: Build account service
on:
push:
branches: [main]
env:
IMAGE_NAME: accountservice
jobs:
build_dependency:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout#v2
- uses: actions/setup-java#v2
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
- name: Build Dependency
run: |
cd ./project_account_library/account_library
mvn clean install
build_accountservice:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout#v2
- uses: actions/setup-java#v2
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
- name: Build Account Service
run: |
cd ./project_account_service/account_service
mvn clean install
First Step
[INFO] Installing /home/runner/work/<>/<>/target/account_
library_1.0-SNAPSHOT.jar to
/home/runner/.m2/repository/com/<>/<>/account_library/1.0-
SNAPSHOT/account_library-1.0-SNAPSHOT.jar
Second Step
Error: Failed to execute goal on project <>: Could not resolve
dependencies for project <>: Could not find artifact com.<>.
<>:account_library:jar:1.0-SNAPSHOT -> [Help 1]
Thanks Frennky
I now used only 1 job and below is my new .yml file
- name: Build Account Service
run: |
cd ./project_account_library/account_library
mvn clean install
cd ../../project_account_service/account_service
mvn clean install
First directory is successfully built but it fails to cd to ../../project_account_service/account_service and fails to build with below error
/home/runner/work/_temp/ea229141-b0c3-455d-82f0-12ff588d420a.sh: line 12: cd ../../project_account_service/account_service: No such file or directory
The reason you're missing dependencies on your second job is because those 2 jobs, by default, run in parallel and they do so on 2 different runners. From docs:
Each job will run inside its own virtual machine runner, or inside a
container...
There's few ways you can go around this. I can suggest one quick and easy, and another that would probably be a way to go, but require slightly more effort.
Easy way out of this is to put all steps in a single job.
Better way would be to make use of Github Package repository, where
you could push your lib/dependencies and then resolve them for your
service.
For more details on Github Package repository you can check docs.
Update:
Ok, I've reread your new error and I think I understand the issue.
If I got it right your dir structure is as follows:
repo
project_account_library
account_library
project_account_service
account_service
Each run step actually starts at root of you repo. You can use working-directory like so:
# ...
- name: Build Dependency
run: mvn clean install
working-directory: ./project_account_library/account_library
# ...
- name: Build Account Service
run: mvn clean install
working-directory: ./project_account_service/account_service
I don't know how to solve this issue, people online had pointed out that it may have something to do with baseurl:, typing the name of my site there or leaving it empty doesn't seem to be working. People had also pointed out changing theme on the config.yml to "remote_theme", that also didn't work
Please have a look at my code, any ideas? I wish I had more information in regards to why this happens
Repo: https://github.com/SimonXTest/simonxtest.github.io
You'll know it's the right repo because there should be a broken.txt in the directory
Remote website image:
Local website image:
Try to add to your github workflow the bundle-install statement.
The rubygems (for the theme) are missing.
You don't have the _layout folder in your source control, so you need to get it from the gems.
In your GitHub Workflow / Action you should do sth. like this.
jobs:
bundler:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Setup Ruby
uses: ruby/setup-ruby#v1
with:
ruby-version: 3.0
bundler-cache: true
- name: Installing dependencies
run: bundle install
I have a GitHub Action that runs tests for my Python/Django project. It caches the virtual environment that Pipenv creates. Here's the workflow with nearly everything but the relevant steps commented out/removed:
jobs:
build:
runs-on: ubuntu-latest
services:
# postgres:
steps:
#- uses: actions/checkout#v2
#- name: Set up Python
#- name: Install pipenv and coveralls
- name: Cache pipenv virtualenv
uses: actions/cache#v2
id: pipenv-cache
with:
path: ~/.pipenv
key: ${{ runner.os }}-pipenv-v4-${{ hashFiles('**/Pipfile.lock') }}
restore-keys: |
${{ runner.os }}-pipenv-v4-
- name: Install dependencies
env:
WORKON_HOME: ~/.pipenv/virtualenvs
PIPENV_CACHE_DIR: ~/.pipenv/pipcache
if: steps.pipenv-cache.outputs.cache-hit != 'true'
run: pipenv install --dev
# Run tests etc.
This works fine usually, but because caches are removed after 7 days, if this is run less frequently than that, it can't find the cache and the Install Dependencies step fails with:
FileNotFoundError: [Errno 2] No such file or directory: '/home/runner/.pipenv/virtualenvs/my-project-CfczyyRI/bin/pip'
I then bump the cache key's version number (v4 above) and the action runs OK.
I thought the if: steps.pipenv-cache.outputs.cache-hit != 'true' would fix this but it doesn't. What am I missing?
First alternative: using a separate workflow, with a schedule trigger event, you can run workflows on a recurring schedule.
That way, you force a refresh of those dependencies in the workflow cache.
Second alternative: use github.rest.actions.getActionsCacheList from actions/github-script (as seen here) again in a separate workflow, just to read said cache, and check if it still disappear after 7 days.
Third alternative: check if reading the cache through the new Web UI is enough to force a refresh.
On that third point (Oct. 2022):
Manage caches in your Actions workflows from Web Interface
Caching dependencies and other commonly reused files enables developers to speed up their GitHub Actions workflows and make them more efficient.
We have now enabled Cache Management from the web interface to enable developers to get more transparency and control over their cache usage within their GitHub repositories.
Actions users who use actions/cache can now:
View a list of all cache entries for a repository.
Filter and sort the list of caches using specific metadata such as cache size, creation time, or last accessed time.
Delete a corrupt or a stale cache entry
Monitor aggregate cache usage for repositories and organizations.
In addition to the Cache Management UX that we have now enabled, you could also use our Cache APIs or install the GitHub CLI extension for Actions cache to manage your caches from your terminal.
Learn more about dependency caching to speed up your Actions workflows.
I followed the steps documented here https://docs.github.com/en/free-pro-team#latest/actions/creating-actions/creating-a-composite-run-steps-action and created a custom github action sucessfully.
Problem now: it only works if the bash shell is available. Unfortunately the shell property is required and it is not possible to use an input variable for that (tested both).
This, doesn't work:
jobs:
build:
runs-on: ubuntu-latest
name: Build project
container: elixir:1.10.4-alpine
env:
MIX_ENV: prod
steps:
- uses: actions/checkout#v2
- name: My custom composite action
uses: path/to-my-custom-composite-action#version
Error: OCI runtime exec failed: exec failed: container_linux.go:370: starting container process caused: exec: "bash": executable file not found in $PATH: unknown
Now I can duplicate the action for alpine (using sh) or build a second version especially for alpine (perhaps autom. via build environment). Is there a better solution?