How to run automated tests in Github actions for Kotlin? - unit-testing

Language: Kotlin,
my build.yml file is:
name: Build
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-java#v2
with:
java-version: '11'
distribution: 'adopt'
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action#e6e38bacfdf1a337459f332974bb2327a31aaf4b
- name: Run the Gradle package task
uses: gradle/gradle-build-action#937999e9cc2425eddc7fd62d1053baf041147db7
- name: Grant Permissions to gradlew
run: chmod +x gradlew
- name: Test
run: ./gradlew test
It sees the test file correctly. But there is a test that has to fail. Yet it successfully passes in GitHub actions. How can I run tests correctly in GitHub actions?

Related

Build GitPages Using GitHub Actions

.github - workflows - github-pages.yml and dry-run.yml
name: Deploy to GitHub Pages
on:
pull_request:
branches:
- master
jobs:
github-pages:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: helaili/jekyll-action#2.0.5
build_only: true
Footer
name: Deploy to GitHub Pages
on:
push:
branches:
- master
jobs:
github-pages:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: helaili/jekyll-action#v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
Git Actions result
Auto-regeneration: disabled. Use --watch to enable.
Jekyll build done
Error: Cannot publish on branch master
master(Default branch) gh-pages(Active branches) I am using two branches.
What is the workaround for the bug?
Maybe you should change
on:
push:
branches:
- master
to another branch

How to implement ./cloud_sql_proxy in GitHub Actions?

jobs:
job1:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Download Cloud SQL Auth Proxy
run: |
wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy
chmod +x cloud_sql_proxy
job2:
needs: job1
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- run: ./cloud_sql_proxy \
-instances=...
I got this error:
./cloud_sql_proxy: No such file or directory
I wanna separate job1 and job2.
How can I use ./cloud_sql_proxy command in job2?
Github jobs do not share files or data unless you take action to do so. One of the reasons is they can run in parallel on different systems/containers/computers.
There are several options. The easiest is to create a step in job2 that does the same download as the step in job1. Other options include workflow artifacts (upload and download) and cache.

Expo Web Build in Vercel - Command "npx expo-cli build:web" exited with 1

I want to build and deploy my expo app in vercel. I know that I can build it locally (expo build:web), cd into the build folder and run vercel, but I would like it to be done automatically with source control integration.
So I have connected my github repository, npm install seems to be working ok. The problem is with the build command. I tried expo build:web but this failed because the expo cli is not installed in vercel, so I tried npx expo-cli build:web and got the folloowing output: Command "npx expo-cli build:web" exited with 1.
Error: Could not find MIME for Buffer <null>
at /vercel/.npm/_npx/727/lib/node_modules/expo-cli/node_modules/xdl/src/Webpack.ts:294:23
at finalCallback (/vercel/.npm/_npx/727/lib/node_modules/expo-cli/node_modules/webpack/lib/Compiler.js:257:39)
Does anyone know how I can run expo build:web in vercel? Many thanks
From my perspective, I think you need to use something like GitHub actions for this task.
I wrote a post on How I automated the releases with the expo-cli and I think we need to follow the same logic.
// .github/workflows/staging.yml
name: Expo Publish on Staging
on:
push:
branches:
- develop
jobs:
publish:
name: Install and publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- uses: actions/setup-node#v1
with:
node-version: 12.x
- uses: expo/expo-github-action#v5
with:
expo-version: 3.x
expo-username: ${{ secrets.EXPO_CLI_USERNAME }}
expo-password: ${{ secrets.EXPO_CLI_PASSWORD }}
expo-cache: true
- run: yarn
- run: expo build:web <------- not sure if it works tho
- run: <------- here we need a way to upload to vercel
I am in the same situation as you —trying to automate the react-native-web to vercel release.
I had the same issue, but found a solution. expo build:web creates a production ready static bundle in the web-build/ directory, which Vercel can deploy. Thus, to deploy the Expo Web-app to Vercel, one can first have a GHA-step that runs expo build:web and then deploy the bundle it produces to Vercel.
Note that one either has to specify the path to the web-build directory as the root-directory in Vercel (which is done in the code below) or has to set the working-directory to the web-build-path in the Vercel step in the code.
Full Github Actions code for job:
deploy-web-staging:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Setup .npmrc and use node 14.15.1
uses: actions/setup-node#v1
with:
node-version: 14.15.1
- name: Expo Web
uses: expo/expo-github-action#v5
with:
expo-username: ${{ secrets.EXPO_CLI_USERNAME }}
expo-password: ${{ secrets.EXPO_CLI_PASSWORD }}
expo-cache: true
- name: Install dependencies
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn
- name: Build Expo Web
working-directory: ./packages/app
run: expo build:web
- name: Vercel Deploy
uses: amondnet/vercel-action#v20.0.0
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
vercel-org-id: VERCEL_ORG_ID
vercel-project-id: VERCEL_PROJECT_ID
scope: TEAM

How to use github action to deploy a serverless mono repo with multiple packages.json?

I'm trying to deploy micro services that are part of a mono repo, for this I'm using github actions but I'm having an issue related to the plugins in the package.json files. This is the structure of my project:
--repo
---package.json
---resources
----package.json
---services
----Service A
-----package.json
----Service B
-----package.json
First I'm trying to deploy the resources folder that basically creates S3 buckets, cognito user pool, etc... and I have added the plugin called "serverless-cognito-add-custom-attributes" as part of this project, this plugin only exists on the package.json that is inside the "resources" folder.
I'm getting this error when trying to deploy from github actions :
Serverless plugin "serverless-cognito-add-custom-attributes" not found. Make sure it's installed and listed in the "plugins" section of your serverless config file.
this is the .yml file I'm using on github actions:
name: Deploy Resources to Dev
on:
push:
branches:
- dev
tags:
- RC-*
paths:
- './resources'
jobs:
InstallActions:
name: deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Download Node
uses: actions/setup-node#v1
with:
node-version: "12.x"
- name: Install NPM Global Packages
run: |
npm install --global
npm install "./resources" --global
- name: Serverless Deploy
uses: serverless/github-action#master
with:
args: deploy --stage dev --config "./resources/serverless.yml"
env:
AWS_ACCESS_KEY_ID: ${{secrets.AWS_ACCESS_KEY_DEV}}
AWS_SECRET_ACCESS_KEY: ${{secrets.AWS_SECRET_ACCESS_KEY_DEV}}
When the above .yml file run I can see this on the console:
+ ----#1.0.0
added 1 package in 2.935s
+ resources#1.0.0
added 3 packages from 3 contributors in 0.654s
for some reason it seems that
uses: serverless/github-action#master
is unable to find the packages when installed from a sub folder, but doing all manually seems to work fine:
name: Deploy Resources to Dev
on:
push:
branches:
- dev
tags:
- RC-*
paths:
- './resources'
jobs:
Deploy:
name: deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Download Node
uses: actions/setup-node#v1
with:
node-version: "12.x"
- name: Install Serverless Framework
run: npm install -g serverless
- name: Serverless Authentication
run: sls config credentials --provider aws --key ${{secrets.AWS_ACCESS_KEY_DEV}} --secret ${{secrets.AWS_SECRET_ACCESS_KEY_DEV}}
- name: Install NPM dependencies
run: |
npm install
npm install "./resources"
- name: Deploy to AWS
run: serverless deploy -v -s dev
working-directory: "./resources"
I had this problem for around 17 hours and then decided to go all manual instead of using the package serverless/github-action#master

Deploy nuxt on AWS amplify console

I have an aws amplify project built on top of nuxt. I'm trying to setup CI using amplify console. My build keeps failing in deploy stage, for some reason the artifacts aren't being created or can't be found:
Here's my amplify.yml file:
version: 0.1
backend:
phases:
build:
commands:
- '# Execute Amplify CLI with the helper script'
- amplifyPush --simple
frontend:
phases:
preBuild:
commands:
- npm install
build:
commands:
- npm run generate
artifacts:
baseDirectory: dist
files:
- '**/*'
cache:
paths:
- node_modules/**/*
If I run npm run generate locally then my app is built and can be found in the dist folder without any problems.
did anyone manage to successfully deploy an amplify/nuxt app using the amplify console?
Thanks
Update 1
change the buildspec:
version: 0.1
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run generate
artifacts:
# IMPORTANT - Please verify your build output directory
baseDirectory: dist
files:
- '**/*'
cache:
paths:
- node_modules/**/*