How to create random uuid in a github action - github-actions

Howdo i create a random uuid from a github action? I found a third party github action that creates a random uuid but i am hoping there is some native action that already supports this scenario.

as an improvement to the answer from #riQQ
name: Test linux job
on:
push
jobs:
testJob:
name: Test
runs-on: ubuntu-latest
steps:
- name: Get uuid
id: uuid
run: |
echo "::set-output name=uuid::$(uuidgen)"

With a Linux runner you can use uuidgen:
name: Test linux job
on:
push
jobs:
testJob:
name: Test
runs-on: ubuntu-latest
steps:
- run: |
uuidgen
This will output the uuid to the console. You can then redirect the output to a file or a variable with the standard shell mechanisms.

Related

Marking GitHub actions workflow as failed if a single job fails in matrix

When running a GitHub Actions matrix workflow, how can we allow a job to fail, continue running all the other jobs, and also mark the workflow itself as failed?
Below in this image, you can see that the workflow passes even after a job failed. We need to mark the workflow as failed in this case.
Here is the small portion of my workflow yaml file.
continue-on-error line will continue the workflow even if a job fails but how do we get the whole workflow marked as failed?
matrixed:
runs-on: ubuntu-latest
continue-on-error: true
timeout-minutes: 60
defaults:
run:
shell: bash
working-directory: myDir
strategy:
matrix:
testgroups:
[
"bookingpage-docker-hub-parallel",
"bookingpage-docker-hub-parallel-group-1",
"bookingpage-payments",
]
I did find this unanswered question, but this is about steps and we need to know about jobs.
Use fail-fast: false for the strategy and don't set continue-on-error on the job.
matrixed:
runs-on: ubuntu-latest
timeout-minutes: 60
defaults:
run:
shell: bash
working-directory: myDir
strategy:
fail-fast: false
matrix:
testgroups:
[
"bookingpage-docker-hub-parallel",
"bookingpage-docker-hub-parallel-group-1",
"bookingpage-payments",
]

Get the name of variable from a JSON file in GitHub Actions

I am trying to setup the GitHub actions for deployment to the Azure. What I am trying to do is getting the name of some variables from the armtemplates with the given code.
name: Create Initial Resources
on:
push:
branches:
- CreateResources
jobs:
Read:
runs-on: ubuntu-latest
steps:
- name: Chekout branch
uses: actions/checkout#v2
with:
ref: CreateResources
- name: get storage account
run: |
echo ::set-output name=storage-account-name::$(jq '.parameters.storage_account_name.value' at ./armtemplates/sac/parameters-example.json)
This is the code that I use, first it checks the branch and in the second step it tries to parse the file that is in the branch but the error is like this:
jq: error: Could not open file at: No such file or directory
Issue here is at phrase. Please use this:
echo ::set-output name=storage-account-name::$(jq '.parameters.storage_account_name.value' ./armtemplates/sac/parameters-example.json)

Github Action tmate - This check was cancelled

I've already attempted to ask about this on the repo itself with no luck so far.
I've created a fairly simple workflow based on this SO answer to retrieve a forgotten secret:
name: Show Me the S3cr3tz
on: [push]
jobs:
debug:
name: Debug
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout#v2
- name: Set up secret file
env:
MY_SECRET: ${{ secrets.MY_SECRET }}
run: |
echo $MY_SECRET >> secrets.txt
- name: Run tmate
uses: mxschmitt/action-tmate#v3
However, I can never see the tmate link because it is cancelled automatically and immediately after leaving the queue:
What am I doing wrong?
This is probably related to the recent GitHub Actions outage.
The workflow YAML syntax is valid, and confirmed to be working.

GitHub Action error: "Top level 'runs:' section is required"

I am trying to get a private GitHub action to work within my private GitHub org. The private repo that contains these workflow 'templates' has this simple file structure as I'm just trying to get the bare minimum to work:
.
├── .git
├── test
│ ├── action.yml
And the action.yml file contents are:
name: Test
on: push
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Echo
run: |
echo Heyyyyy
I am trying to use this action in another private repo with a workflow file with these contents:
name: Test
on:
push:
branches:
- master
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
with:
repository: <private-actions-repo>
token: ${{ secrets.REPO_TOKEN }}
path: github-actions
- name: Test private action
uses: ./github-actions/test
When this action runs, I get the following error:
##[error]Top level 'runs:' section is required for /home/runner/work/<private-repo>/./github-actions/test/action.yaml
Trying to debug this, I updated the workflow that uses the template to cat the file contents of this file:
- name: Test private action
run: |
cat ./github-actions/test/action.yml
..and I get the contents I would expect:
> Run cat ./github-actions/test/action.yml
name: Test
on: push
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Echo
run: |
echo Heyyyyy
Why would this not be working when using it from the action repo, but the exact same content works in the target repo?
You have to differentiate between workflows, actions, and different action types.
Workflows are toplevel elements and not composable. Actions are building blocks that can be used in workflows. The action you defined in action.yml is actually a workflow but should be a composite run steps action, i.e. a specific type of action, that has to follow the rules given in:
https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-composite-run-steps-actions
You can find an example for a composite run steps action here:
https://docs.github.com/en/actions/creating-actions/creating-a-composite-run-steps-action#creating-an-action-metadata-file
If you use the following as action.yaml, it should work:
name: Test
description: 'composite run action'
runs:
using: "composite"
steps:
steps:
- name: Echo
shell: bash
run: |
echo Heyyyyy

How to get the GitHub Pull Request ID Number

Is there a way to get and set the Github’s pull request number (example PR #323 ) into Github Actions’s Environment Variable (without the hashtag)?
env:
GITHUB_PR_NUMBER: 323
on:
pull_request
env:
GITHUB_PR_NUMBER: ${{github.event.pull_request.number}}
jobs:
prJob:
name: Print event
runs-on: ubuntu-latest
steps:
- run: |
echo "$GITHUB_PR_NUMBER"
For more information, see https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#pull_request