Can't open ./scripts/ci.sh with github action - github-actions

My Rust repository containing multiple subfolders.I would like to be able to build and test each of the projects for each pull request or when a new code is pushed to the master. So I created a ci.sh. Performing the action, I get a "Can't open ./scripts/ci.sh" error.
I've checked that ci.sh has been added to the repo.
What's the proper way to designate ci.sh's path?
name: Rust
on:
push:
branches: [master]
pull_request:
branches: [master]
env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Build, test, clippy all
# run: "${{ format('{0}/.github/scripts/ci.sh', github.workspace) }}" <-also can't find script
run: sh ./scripts/ci.sh
Directory Structure:
MY_EXAMPLES
- .github
- workflows
- scripts
- ci.sh
- build.yml
- EXAMPLE_1
- EXAMPLE_2
- EXAMPLE_3

I did the following and it worked.
echo hi > .github/workflows/scripts/ci.sh
name: test
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: test
run: sh .github/workflows/scripts/ci.sh

Related

How to run server and tests within Github actions

I have this github action:
jobs:
run-server:
name: Run Contract Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- ...
- name: Start Server
run: iex -S mix phx.server
run-tests:
name: Run Tests
runs-on: ubuntu-latest
needs: run-server
...
steps:
- uses: actions/checkout#v2
- name: Run API Tests
id: run-newman
uses: anthonyvscode/newman-action#v1
...
But the server closes before the second job starts. How do I keep the server going while I run the contract tests?

Run GitHub workflow from non-gradle project

I have a non-gradle root project which should launch child gh action, but can’t figure out how to. File child.yml should generate apk artifact, since android/ dir is app directory.
Project structure:
root
|
--- .github/workflows/root.yml
--- android/
|
___ .github/actions/apk/child.yml
Closest I get was running a yaml on root level:
root.yml
name: use my action
on:
push:
branches:
- ci_test
jobs:
#Build job
test_build:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout#v2
- uses: ./android/.github/actions/apk
child.yml
name: Build of dev branch
on:
push:
branches:
- develop
jobs:
#Build job
build:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout#v2
- uses: actions/cache#v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('**/buildSrc/**/*.kt') }}
- name: Set up JDK 11
uses: actions/setup-java#v1
with:
java-version: '11'
- name: Change wrapper permissions
run: chmod +x ./gradlew
- name: Build the app
run: ./gradlew assembleDebug
- name: Upload apk
uses: actions/upload-artifact#v2
with:
name: debug apk
path: ./app/build/outputs/apk/debug/app-debug.apk
But I get an error with doubled "/my-root-dir/my-root-dir"
Can't find 'action.yml', 'action.yaml' or 'Dockerfile' under '/home/runner/work/my-root-dir/my-root-dir/android/.github/actions/child.yaml'. Did you forget to run actions/checkout before running your local action?

GitHub Action Vitest CI pipeline

I would like to create a CI pipeline with GitHub Action but I have problems. The front end of the project is developed in Vue 3 and uses vitest to run the tests. It's in a folder called "WEB" in the root directory. So I would like to run my tests at each commit in the master branch but it returns this error:
Error: .github#L1
each step must define a `uses` or `run` key
I used the preexisting "Node.js" template and just added the "working-directory" property to specify the "WEB" folder.
Here is my ".yml" file
name: Runs frontend tests
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout#v3
- name: Use Node.js ${{ matrix.node-version }}
working-directory: ./WEB
uses: actions/setup-node#v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Execute Unit tests
- run: npm ci
- run: npm run test
When you add a - it add an element at the steps array:
You should do it like this:
- name: Execute Unit tests
run: |
npm ci
npm run test

Why are both github workflows running when they are configured to only run on their respective branches?

I have two workflows, develop.yml and production.yml.
develop is configured to run on develop:
name: Develop
on:
push:
workflow_dispatch:
branches:
- develop
jobs:
perform-linting:
runs-on: windows-latest
steps:
- name: Checkout repository code
uses: actions/checkout#v2
- name: Setup node
uses: actions/setup-node#v2
with:
node-version: "14.x"
- name: Install base dependencies
run: npm install
- name: Bootstrap
run: lerna bootstrap
- name: Run ESLint
run: lerna run lint
And production is configured to run on master:
name: Production
on:
push:
workflow_dispatch:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repo code
uses: actions/checkout#v2
- name: Deploy to Heroku
uses: akhileshns/heroku-deploy#v3.12.12
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: ${{secrets.HEROKU_APP_NAME}}
heroku_email: ${{secrets.HEROKU_EMAIL}}
However, pushing changes to develop or master will trigger both of these workflows to run:
In the above scenario, why is production being run when I only pushed to develop?
your configuration effectively says 'run on all pushes, only allow manual dispatch on a particular branch' (though the latter isn't an option it seems).
You probably mean:
develop.yml
name: Develop
on:
push:
branches:
- develop
workflow_dispatch:
production.yml
name: Production
on:
push:
branches:
- master
workflow_dispatch:

Use two different GitHub environment secrets in single action

I have created GitHub Environment Secrets for staging and productions for example
Enviroment > Production > DB_PASS
and
Enviroment > Staging > DB_PASS
in my workflow I have
on:
push:
branches:
- main
- staging
jobs:
deploy:
environment: Production
name: Deploy
runs-on: ubuntu-latest
steps:
- name: Debug Secret
run: echo ${{ secrets.DB_PASS}}
How can I change the environment to Staging when branch merged is staging, probably by using
gihub.ref for the branch name. I tried passing the value dynamically to environment from the previous job using needs.job1.outputs.output1 but it didn't work.
I found that some developer on Stackoverflow has suggested using a prefix in secret names
like
PROD_DB_PASS
STG_DB_PASS
but is there any better and cleaner way to do this?
Like you mentioned github.ref is probably the best way to go about it.
on:
push:
branches:
- main
- staging
jobs:
deploy-production:
environment: Production
name: Deploy production
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/main' }}
steps:
- name: Debug Secret
run: echo ${{ secrets.DB_PASS }}
deploy-staging:
environment: Staging
name: Deploy staging
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/staging' }}
steps:
- name: Debug Secret
run: echo ${{ secrets.DB_PASS }}
Agreed there is a lot of duplicated code, but I think it is simpler, clearer and more reliable than dynamically passing the environment based on some previous job.