The following shows what the Github Actions tab displays for a typical build:
The Build step actually has a number of sub-steps, but I do not want to use Github Actions as a scripting language just to be able to have each sub-step discreetly displayed. Is there any sort of magic that Github Actions provides to signal that you wish the visualization of the build to show a discrete step (i.e. a "dynamic step")?
I'm hoping for something like the following which would cause the creation of discrete result nodes in the output of the Github Actions build visualization:
- name: Dynamic Steps
run |
echo "###github-action-step: Step 1"
echo "###github-action-step: Step 2"
echo "###github-action-step: Step 3"
Something close to that can be achieved by skipping steps and/or dynamically setting the steps name.
i.e. I'm using like this to customize the tab message on GH actions:
- name: "Pulling existing Docker image ${{ github.event.repository.name }}:${{ steps.variables.outputs.commitSha }}"
if: steps.image_checker.outputs.shouldBuildNewImage == 0
run: |
docker pull ${{ steps.variables.outputs.dockerRepositoryUrl }}:${{ steps.variables.outputs.commitSha }}
When the step is skipped, it still appears in the logs, but grayed out and in my scenario, the text doesn't show the 'image:tag' getting pulled
Related
I'm quite a rookie with GitHub Actions so this might be a stupid question: Is there a way to link pull requests with issues (in the UI linked PRs are shown under Development) in Github Actions using Github CLI or octokit/rest.js via actions/github-script?
enter image description here
Background: there is a workflow that creates pull requests. That works fine, only thing missing is the link between issues and corresponding pull requests. I would prefer not to use keywords nor other custom actions from the marketplace.
I've searched in the octokit/rest.js documentation https://octokit.github.io/rest.js/v19 under Issues and Pulls as well as in the GitHub cli documentation https://cli.github.com/manual/gh but couldn't find a solution.
I would like to have a solution either using GitHub Script https://github.com/marketplace/actions/github-script
or the command line.
You can use the Add an issue link Action for that.
This Action allows linking issues to Pull Requests. For example:
name: 'Issue Links'
on:
pull_request:
types: [opened]
jobs:
issue-links:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: tkt-actions/add-issue-links#v1.8.1
with:
repo-token: '${{ secrets.GITHUB_TOKEN }}' # required
branch-prefix: 'issue-' # required
This workflow will trigger on Pull Request open and link related issues mentioned in the PR body.
Make sure to set the corresponding permission for the job:
permissions:
pull-requests: write
For more about these permissions visit the Permissions for the GITHUB_TOKEN.
I have a Github action that sets a name and is run on pull requests:
name: Code Quality
on:
workflow_dispatch:
pull_request:
branches: [ main, develop ]
When I trigger the run manually (because workflow_dispatch is also set), the run will get the title “Code Quality” in the list of runs.
But when the action is run on a pull request, the run name in the list is set to the name of the PR. That may or may not be a good title, very much depending on the PR’s author. Is there a way to influence the title of the action in the list?
Since Sept. 2022, there might be a way to set the title of the run itself:
GitHub Actions: Dynamic names for workflow runs (Sep. 2022)
GitHub Actions customers can now dynamically name their workflow runs.
The new run-name feature will accept expressions and be displayed on the list of workflow runs.
For more information on how to use run-name, visit the documentation.
For questions, visit the GitHub Actions community.
To see what's next for Actions, visit our public roadmap.
You now have:
The name for workflow runs generated from the workflow.
GitHub displays the workflow run name in the list of workflow runs on your repository's "Actions" tab.
If you omit run-name, the run name is set to event-specific information for the workflow run.
For example, for a workflow triggered by a push or pull_request event, it is set as the commit message.
This value can include expressions and can reference the github and inputs contexts.
Example
run-name: Deploy to ${{ inputs.deploy_target }} by #${{ github.actor }}
It does not seem like there is a way to set the title of the run itself (reference).
Scheduled and manual runs will get the title of the workflow, and runs triggered by commit / PR will get the commit message or PR title.
However, notice that the commit / PR title is displayed in addition to the name of the workflow, which appears in two places:
I can't for the life of me figure out why my GitHub Action isn't triggering on push. For context: I have a data file that is updated daily and pushed to the test branch with a timestamp commit message. I am trying to use this timestamp in a Dynamic Badge for my README. Everything works fine when the workflow is run manually (except, of course, I don't get the event data I am hoping to obtain when the action runs on the trigger.)
on:
push:
branches:
- test
paths:
- 'data/Sales.csv'
env:
BADGE_MESSAGE: ${{ github.event.commits[0].message }}
jobs:
create-badge-test:
runs-on: ubuntu-latest
steps:
- name: Create Dynamic Badge
uses: schneegans/dynamic-badges-action#v1.1.0
with:
auth: ${{ secrets.GIST_PAT }}
gistID: 0123456789 #Not actual gist ID
filename: test.json
label: Last Refresh
message: $BADGE_MESSAGE
color: orange
And yes, I've tried putting the branch name in quotes and updating the paths: to - '**.csv' and the action still does not trigger.
There must be something else wrong - all you have here in this workflows is just fine.
You can see it working here:
https://github.com/grzegorzkrukowski/stackoverflow_tests/actions/runs/1860382530
For this commit:
https://github.com/grzegorzkrukowski/stackoverflow_tests/commit/f3f8dd20fa780746441c7b6623b6a2a9929aa70d
It's exact copy of workflow from your question.
I would expect you are pushing a file with different name - keep in mind some systems will be case-sensitive - so pushing data/sales.csv won't work properly.
Another idea is that you pushing it to wrong branch or you have wrong path to the file.
You have to push to test branch and with data/Sales.csv - it only triggers workflow if both are true.
Short answers is - workflow is fine as it is - no brackets needed.
I could help more seeing the repository with this workflow and exact commits being done.
The action is not running because you also need to satisfy the paths condition as explained on GitHub docs
Note: If you use both the branches filter and the paths filter, the workflow will only run when both filters are satisfied.
If you want the action to run when you push to test you have to remove the paths condition
on:
push:
branches:
- 'test'
I have a manually triggered job that builds and deploys an image based on the tag I specify. Is there a way to make the workflow name dynamic?
name: Build and push
on:
workflow_dispatch:
inputs:
tag:
description: 'Image Tag'
required: true
jobs:
...
I would like to do something like
name: "Build and push ${{ github.event.inputs.tag }}"
As of Sep 26th 2022, this is now supported. Here's the announcement (which contains a link to the documentataion): https://github.blog/changelog/2022-09-26-github-actions-dynamic-names-for-workflow-runs/
Workflow names are not dynamic, but fixed.
To get at the actual data of a workflow run, you'll have to chose the specific run from the Actions > All Workflows > [name-of-your-workflow] list.
Alternatively, you can think about other ways to propagate the outcomes of your builds.
Our team, for example, propagates build outcomes to teams chat channel (in our case Microsoft Teams using the action notify-microsoft-teams). If you search the market place you'll find plenty of actions for this.
Another alternative could be to generated custom badges, which you could then make visible to your team. A nice action for this is bring-your-own-badge.
Last but not least you can propagate your workflow run data using emails (again, there are actions which do this for you).
Is it possible to split a GitHub Actions workflow file and reference it from other? I need to deploy an application into multiple environments i.e. staging and production and would like to share half of the steps to minimize maintenance.
You can split each action in the following file format:
folder named "test-action"
.github/test-action/action.yml
with contents
name: test-action
description: test action
inputs:
test_input:
description: key
required: true
runs:
using: composite
steps:
- name: echo test
shell: bash
run: |
echo ${{inputs.test_input}}
then you can refer to the action from any yml:
- name: test-action
uses: ./.github/test-action
with:
test_input: "test-string-value"
the key here was to make sure that the file within your named action folder would be called "action.yml"
It seems like there is no way as CircleCI allows defining commands that are a set of steps: https://github.community/t5/GitHub-Actions/reusing-sharing-inheriting-steps-between-jobs-declarations/td-p/37849
At this moment, I guess we can use repository_dispatch as a workaround.
In this example, it handles events between repositories, but I think we can apply this in same repository: https://blog.marcnuri.com/triggering-github-actions-across-different-repositories/