Reusing GitHub Action workflow steps inside another job - github

I have created a Reusable Workflow using a workflow_call trigger, but I need to run additional steps based on its outcome.
Example:
jobs:
released:
steps:
- name: Build
uses: my-org/some-repo/.github/workflows/build.yml#main
- name: Upload source maps
run: something
The reusable Build step builds my JS app and produces source maps. Now I need to upload these source maps to somewhere as a separate step that should only run inside this Released job.
Doing the above results in the following error:
Error : .github#L1
reusable workflows should be referenced at the top-level `jobs.*.uses' key, not within steps
It only allows running my reusable workflow inside a job, not inside a step. But by doing that I can no longer access the source maps.
My question: How do I reuse the steps from the Build workflow and access its output inside the Released job?

You can share these output files between jobs using artifacts.
Use the upload-artifact to upload the build files from the Build workflow and download-artifact to download them in the Released workflow.
Build workflow
name: Build
on:
workflow_call:
secrets:
SOME_SECRET:
required: true
jobs:
build:
steps:
# Your build steps here
- name: Create build-output artifact
uses: actions/upload-artifact#master
with:
name: build-output
path: build/
Released workflow
name: Released
on:
push:
branches:
- main
jobs:
build:
uses: my-org/some-repo/.github/workflows/build.yml#main
secrets:
SOME_SECRET: ${{ secrets.SOME_SECRET }}
released:
needs: build
steps:
- name: Download build-output artifact
uses: actions/download-artifact#master
with:
name: build-output
path: build/
# The "build" directory is now available inside this job
- name: Upload source maps
run: something
Bonus tip: Note that the "my-org/some-repo/.github/workflows/build.yml#main" string is case-sensitive. I wasted some time figuring out that that was the cause of the error below.
Error : .github#L1
error parsing called workflow "my-org/some-repo/.github/workflows/build.yml#main": workflow was not found. See https://docs.github.com/en/actions/learn-github-actions/reusing-workflows#access-to-reusable-workflows for more information.

Related

GitHub Action errors because it can't see a folder

I'm trying to set up my first GiHub Action. All it needs to do is run a test over my Godot files. I based it on a template.
name: CI
on:
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: godot-tester
uses: croconut/godot-tester#v2.5
with:
version: 3.4
release_type: stable
# Give relative path to your project.godot, if not in top level of repo
path: app
The action errors every time, when trying to find the project file.
/entrypoint.sh: line 166: cd: ./app: No such file or directory
The folder, app, is there and it contains the project. I've tried with or without a trailing slash, it makes no difference.
When you need to access the files from the proper repository in a Github Actions workflow, you need to setup the actions/checkout first.
This will allow the workflow to access the Github workspace (which is basically the repository root).
In your case, the workflow should look like this:
name: CI
on:
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
- name: godot-tester
uses: croconut/godot-tester#v2.5
with:
version: 3.4
release_type: stable
# Give relative path to your project.godot, if not in top level of repo
path: app
The actions/checkout action has a default behavior, but you can also configure other fields to customize what you want it to do. Check the action README page to see all the possibilities.

Accessing postgresql in review stage of Gitlab CI/CD

How do I import data to the postgresql server during the Review stage (for a review app) during the Gitlab CI/CD process?
I am currently using Gitlab CI/CD to deploy to AWS. Postgresql is used throughout the build stages.
During the build stages, information is successfully imported to postgresql from another application. The data is then dumped as a SQL file to an artifact (in two locations).
artifacts:
paths:
- postgres_backup.sql
- scripts/postgres/postgres_backup.sql
expire_in: 1 day
The build artifacts are created. However, they are not available in the review - autodeploy - stage.
The review stage is basically:
review:
extends: .auto-deploy
stage: review
before_script:
- echo "Supposedly, this helps to carry over artifacts."
The artifacts are not there. Ideally, I would want to push the SQL backup to the database but 1) the artifact is not available and 2) the psql command is not available (nor apt).
Take a look at the .auto-deploy job (it might be coming from an included job this too). If the .auto-deploy job has a dependencies keyword, it's affecting your artifacts.
By default, when one job uploads artifacts, jobs in all following stages will automatically download the artifact. This can be controlled using the dependencies keyword on individual jobs.
For example, using dependencies: [] means this job has no dependencies, so no artifacts are downloaded. dependencies: ["npm install job"] means that the artifacts from a job called "npm install job" are the only artifacts downloaded, even if artifacts from other jobs are uploaded.
So if you see the dependencies keyword in the .auto-deploy job, you'll have to include it in your review job. If .auto-deploy has dependencies: [], you'll have to have dependencies: ["your-job-name"] where the job name is the job that uploads the files.
If .auto-deploy has a dependencies keyword that has at least one job name, you'll have to copy the jobs, and include them in your review job:
// .auto-deploy job:
.auto-deploy
stage: deploy
dependencies: ["job1", "job2"]
script:
- ...
// review job
review:
stage: review
dependencies: ["job1", "job2", "your-postgres-job"]
script:
- ...

Folder missing in artifact - GitHub Actions

I have the following steps to copy files to artifact and publish artifact:
- name: copy FA function arm templates
run: Copy 'Service/Project/Hosts/FA/Infrastructure/' 'upload/functions_arm_templates/FA/Infrastructure'
shell: powershell
- name: copy FB function arm templates
run: Copy 'Service/Project/Hosts/FB/Infrastructure/' 'upload/functions_arm_templates/FB/Infrastructure'
shell: powershell
- name: publish artifact
uses: actions/upload-artifact#v2
with:
name: ${{github.run_number}}
path: upload/**
The Build succeeded however after downloading the artifact, I don't see a folder named functions_arm_templates. What am I missing?
You are only copying the folder without its contents.
Use copy 'Service/Project/Hosts/FA/Infrastructure/' 'upload/functions_arm_templates/FA/Infrastructure/' -recurse to copy the folder with its contents.

Github include md files in README.md?

Is there a way in Github to include md files in for example the README.md?
# Headline
Text
[include](File:load_another_md_file_here.md)
It should not link to the file, it should load the contents from it, like PHP include / file_get_contents.
That does not seem to be possible, especially when considering github/markup#346 and github/markup#172.
No include directive is supported.
This is not the correct answer but a workaround for others who really want this.
It's possible to use Gulp and Gulp Concat to merge the files into one before they are sent to Github..
Since it is not possible I just ended up placing a link as
[MY-LINK](../../SOME-OTHER-README.MD)
migrate your readme to a different file then construct your actual README however you like as a github action
EDIT: Here's a demo that you can build off of. This repo has a single github action that runs a script that dynamically builds the README.md based on the contents of the repository (to build a site map for the repo in the form of a table of contents): https://github.com/dmarx/bench-warmers
the workflow config:
name: update-readme
on:
push:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
- uses: actions/setup-python#v2
- name: Run the script
run: python scripts/update_readme.py
- name: Commit files
run: |
git config --local user.name "dmarx"
git add README.md
git commit -m "Updated TOC"
- name: Push changes
uses: ad-m/github-push-action#master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
force: true
Here's the chunk of my update script that's relevant to you:
... # code that builds the object `toc_str`
# template readme
with open('README.stub') as f:
readme_stub = f.read()
# simple replacement, use whatever stand-in value is useful for you.
readme = readme_stub.replace('{TOC}',toc_str)
with open('README.md','w') as f:
f.write(readme)
Which assumes you have a file named README.stub which might look something like this:
# Title
some text
{TOC}
more text
Where {TOC} is the substitution target for our dynamic content.
Ruby gem markdown_helper implements include files for GitHub flavored markdown (GFM).
Disclosure: I wrote the gem.

How to deploy to github with file pattern on travis?

I have created a simple travis configuration which packages an app and tries to deploy the archive file to github.
The problem is, I would like to have the version number part of the file name, so i require to use a pattern for the filename. I simply can't get it to work.
Configuration is currently:
deploy:
provider: releases
file: "build/distributions/worktrail-app-hub-sync*.zip"
on:
repo: worktrail/worktrail-app-hub-sync
tags: true
all_branches: true
But it fails with: "/home/travis/.rvm/gems/ruby-1.9.3-p547/gems/octokit-3.3.1/lib/octokit/client/releases.rb:86:in `initialize': No such file or directory - build/distributions/worktrail-app-hub-sync*.zip (Errno::ENOENT)" - but the file is certainly there: build/distributions/worktrail-app-hub-sync-0.0.1.zip
Example run: https://travis-ci.org/worktrail/worktrail-app-hub-sync/builds/35704111
travis.yml: https://github.com/worktrail/worktrail-app-hub-sync/blob/0.0.1/.travis.yml
Is this supported by travis deployment, or is there any workaround for this use case?
Wildcards are supported by now if you enable the file_glob option. This is how I deploy a build .deb file to GitHub releases:
before_deploy:
- export RELEASE_PKG_FILE=$(ls *.deb)
- echo "deploying $RELEASE_PKG_FILE to GitHub releases"
deploy:
provider: releases
api_key:
secure: YOUR_ENCRYPTED_API_KEY
file_glob: true
file: "${RELEASE_PKG_FILE}"
on:
tags: true
Setting up is easy by executing travis setup releases with a dummy filename and modifying .travis.yml afterwards.
deploy:
file_glob: true
file: "build/distributions/worktrail-app-hub-sync*.zip"
example
Sorry, wildcard patterns don't work at the moment, but we'll have a look into making that possible on Travis CI.