Interpolate the version of reusable workflow in Github Actions - github-actions

Any to pass a variable (of sorts) for the version of a reusable workflow
For example ,if I have this workflow:
name: caller-workflow
on:
pull_request:
push:
branches:
- master
# 2
jobs:
call-the-workflow:
uses: action-foobar/action-testing/.github/workflows/called_workflow.yml#${{github.ref_name}}
with:
TRIGGER_EVENT : ${{ github.event_name }}
from the example above
`uses: action-foobar/action-testing/.github/workflows/called_workflow.yml#${{github.ref_name}}` using a `${{github.ref_name}}`
instead of a pinned reference.
Would like to be able to call the reusable workflow, using a reference (Thereby I could do easy automation on pull requests or any branch (for pipeline or CI development)

No - it's impossible unfortunately.

Related

What github action can i use in the event of push to get changes that were a part of the commit that was pushed?

Currently, my GitHub workflow looks as follows:
name: learn-github-actions
run-name: ${{ github.actor }} is learning GitHub Actions
on:
push:
branches:
- main
jobs:
update-x:
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout#v2
with:
# fetch depth is needed since we will be taking git diff with HEAD^1
fetch-depth: 2
- name: Run script
run: scripts/x/x-version-bump.sh
Instead of using git diff in my x-version-bump.sh script I would like to get the changes of the commit pushed via a GitHub action and pass it on to the script. I cannot find a way currently in Github actions to do the same.

Prevent GitHub Action to run for each tag on a commit

I have a publish workflow that is supposed to push the dists to PyPi if a commit on main is tagged with either frontend-v* or backend-v* (both are separate packages)
However, if a commit has changes on both the front- and backend and I add two tags to the commit, the workflow is triggered twice.
I understand that I could simply split the workflow into two, but I have another job that should run if either frontend or backend or both were updated which should only be ran once, thus I want to keep this in one workflow.
Can I somehow circumvent this to run this only once?
Thank you very much!
on:
workflow_dispatch:
push:
branches: [ main ]
tags:
- frontend*
- backend*
jobs:
backend:
name: Publish backend
if: ${{contains(github.ref_name, 'backend') }}
runs-on: ubuntu-latest
steps:
...
frontend:
name: Publish frontend
if: ${{contains(github.ref_name, 'frontend') }}
runs-on: ubuntu-latest
steps:
...
housekeeping: # this should only be ran once for the commit
name: House Keeping
runs-on: ubuntu-latest
steps:
...

Chain testing and releasing workflows in GitHub Actions

I have 2 conditions under which I want to run my workflows in GH actions on a go project
run unit tests on every PR (I have already taken care of this with the following workflow.yaml
name: unit-tests
on: [ pull_request ]
jobs:
unit-tests:
runs-on: Linux
steps:
- name: checkout project
uses: actions/checkout#v2
- name: dynamically retrieve go version
uses: arnested/go-version-action#v1
id: go-version
- name: setup go ${{ steps.go-version.outputs.minimal }}
uses: actions/setup-go#v2
with:
go-version: ${{ steps.go-version.outputs.minimal }}
- name: run unit tests
run: go test -race -cover -v ./... -run Unit
My second requirement is the following:
run unit tests AND proceed to creating a tag + release if the tests succeed and the target branch is master
My question is the following: Since the on clause is unique per workflow, is there a way I can leverage the above workflow (without the need to write a more or less clone) that can be integrated in the second use case?
First, reusing workflows is available since Oct. 2021
That means you can make a workflow on master branch, which would "call" (reuse) your second (existing) workflow, itself with its on: directive
The call would look like:
jobs:
call-workflow-passing-data:
uses: octo-org/example-repo/.github/workflows/reusable-workflow.yml#main
with:
username: mona
secrets:
envPAT: ${{ secrets.envPAT }}

Github action manual execution not working

I have 3 different workflows in a project configured at top as:
plan_streamline.yml
name: plan
on:
push:
branches:
- main
workflow_dispatch:
...
terrform_import.yml
name: terraform_import
on: workflow_dispatch
...
plan.yml
on:
push:
branches:
- main
workflow_dispatch:
But within the github action I do not see the ability to manually execute any of the workflows, as I should be seeing something like https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/
What is wrong with my workflow configuration?
Merged the branch with the new workflows to the default branch so that option appears now

Does Github Actions have templates

As I have repetitve steps in my Github Actions, I would like to create a template. Let's make a example
name: ci
on: ["push"]
jobs:
build-and-test:
strategy:
matrix:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: checkout
uses: actions/checkout#v1
- name: do stuff
run: |
bash stuff
Is it possible to save only the steps in a separated file? And import afterwards?
Unfortunately it does not look like github-actions supports reusing workflows. Not even YAML anchors are supported.
It looks like the only way to share steps (not setup) is to create actions.
Update: A storm brewing
I have also caught wind of the possibility of reusing actions. Follow the issue to stay up-to-date.
I mentioned in "Reuse portion of GitHub action across jobs" that reusing GitHub Worfflow is now (Oct. 2021) available.
The documentation "Reusing workflows" includes a section "Reusable workflows and workflow templates", which leads to "Creating workflow templates"
If you need to refer to a repository's default branch, you can use the $default-branch placeholder.
When a workflow is created using your template, the placeholder will be automatically replaced with the name of the repository's default branch.
For example, this file named octo-organization-ci.yml demonstrates a basic workflow.
name: Octo Organization CI
on:
push:
branches: [ $default-branch ]
pull_request:
branches: [ $default-branch ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Run a one-line script
run: echo Hello from Octo Organization