Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get the project folder name only on a Github action?

Tags:

I can get repoowner/repo-name with ${{ github.repository }} but I like to get just the repo-name.

While I am at it.

GitLab has a straight forward variable for this.

How do I get reference access env variables from the .yaml not inside scripts? Does ${{ $ENV_VAR }} work? Probably not.

Is there a way to remove or replace the slashes directly in the yaml?

  build:     needs: test     name: Build release Zip     runs-on: ubuntu-latest     env:       DEPLOY_REF: ${{ github.sha }}       DEPLOY_REF_SHORT: ${{ github.sha }}       DEPLOY_ZIPFILE: ${{ github.workspace }}/build/zip/${{ github.repository }}-${{ github.sha }}.zip     steps: 
like image 777
redanimalwar Avatar asked Oct 19 '19 20:10

redanimalwar


People also ask

Which directory does GitHub Actions run?

GitHub Actions uses YAML syntax to define the workflow. Each workflow is stored as a separate YAML file in your code repository, in a directory named . github/workflows .

What is ID in GitHub Action?

ID is used as a reference, from other jobs or steps (for example, in jobs. <job_id>. needs ). Name is used for display purposes on GitHub.

What is GitHub Head_ref?

github.head_ref. string. The head_ref or source branch of the pull request in a workflow run. This property is only available when the event that triggers a workflow run is either pull_request or pull_request_target . github.job.


Video Answer


1 Answers

github context also contains event data, from where you can easily read some more detailed info. In this case, ${{ github.event.repository.name }} will give you only repo-name part.

It might be a good idea to create testing workflow/job to print all context data until you're familiar with them, see Example printing context information to the log file.


As for replacing text, you can always dedicate one of first steps to prepare everything you need later with either ::set-env or ::set-output. You just need to print name/value in specific format, so you can use any shell you're familiar with to manipulate text while doing that:

# All steps after this one will have env variable `GHA_BRANCH` passed to them. - run:   echo ::set-env name=GHA_BRANCH::$(echo $GITHUB_REF | awk -F / '{print $3}')   shell: bash 
like image 157
Samira Avatar answered Sep 19 '22 07:09

Samira