I am trying to run scripts from Github Actions and it keeps saying: No file or directory found.
This is the github action:
name: Build And Deploy
on:
push:
# branches:
# - master`
jobs:
generate-build-number-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# https://github.com/marketplace/actions/build-number-generator
- name: Generate build number
uses: einaregilsson/build-number@v3
with:
token: ${{secrets.github_token}}
- name: Print new build number
run: echo "Build number is $BUILD_NUMBER"
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-2
- name: Print GITHUB_WORKSPACE
run: echo ${GITHUB_WORKSPACE}
- name: Build Docker
run: |
chmod x "${GITHUB_WORKSPACE}/../docker/build-docker.sh"
${GITHUB_WORKSPACE}/../docker/build-docker.sh
- name: Push Docker
run: |
chmod x "${GITHUB_WORKSPACE}/../docker/push-docker.sh"
${GITHUB_WORKSPACE}/../docker/push-docker.sh
For some reason the GITHUB_WORKSPACE
has weird path and thats why i have to do ${GITHUB_WORKSPACE}/../docker/push-docker.sh
, add ../
in the path. Is there a way to list the files or get the current working directory to look where the files actually are located?
I tried doing echo ${cwd}
and echo ${pwd}
but it echos nothing.
I have referenced the following link for running bash script: https://github.community/t/running-a-bash-script/141584
CodePudding user response:
The best practice is to run your commands with working-directory:
for those steps to make them execute in a certain directory - relative to your root folder.
CodePudding user response:
The issue was directory structure. Once i listed the files in the directory and found the path to the files, the action ran successfully. Here is the final yml script.
on:
push:
branches:
- master
jobs:
generate-build-number-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# required for accessing files in repository.
# https://github.com/marketplace/actions/build-number-generator
- name: Generate build number
uses: einaregilsson/build-number@v3
with:
token: ${{secrets.github_token}}
- name: Print new build number
run: echo "Build number is $BUILD_NUMBER"
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-2
- name: Build Docker
run: ${PWD}/docker/build-docker
- name: Push Docker
run: ${PWD}/docker/push-docker