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.
Related
i want to use Github Actions for deploying my react nodejs code to nginx. For this i've run those commands:
curl -o actions-runner-linux-x64-2.301.1.tar.gz -L
https://github.com/actions/runner/releases/download/v2.301.1/actions-runner-linux-x64-2.301.1.tar.gz
tar xzf ./actions-runner-linux-x64-2.301.1.tar.gz
yes "" | ./config.sh --url https://github.com/yuuval/react-deploy-aws --token AVYXWHVAXX2TB4J63XBJCIDDYB6TA
sudo ./svc.sh install
sudo ./svc.sh start
Those are the essential commands. I want, that i can use this token also for other ec2 instances: AVYXWHVAXX2TB4J63XBJCIDDYB6TA. I've set a repository secret with a value, but it doesn't work. I want to run this commands by terraform and cloud-init, thats why i can't just copy the token from the online github page. So does anyone know how i can set a fix token, so i can create multiple instances with terraform and cloud-init. Isn't it enough if the token is given in the workflow file?
workflow file:
**# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
name: Node.js CI
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:
jobs:
build:
runs-on: self-hosted
strategy:
matrix:
node-version: [16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout#v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
token: ${{ secrets.ACTIONS_TOKEN }}
- run: npm ci
- run: npm run build --if-present
After this command yes "" | ./config.sh --url https://github.com/yuuval/react-deploy-aws --token AVYXWHVAXX2TB4J63XBJCIDDYB6TA this happens:
Http response code: NotFound from 'POST https://api.github.com/actions/runner-registration' (Request Id: 9530:5EB4:1A2D16B:35B9403:63D2A781)
{"message":"Not Found","documentation_url":"https://docs.github.com/rest"}
Response status code does not indicate success: 404 (Not Found).
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?
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
name: MoneyTracker Test
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Set up python 3.7
uses: actions/setup-python#v2
with:
python-version: 3.7
- name: Install dependency
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Lint with flake8
run: |
pip install flake8
flake8
- name: Coverage report
env:
secret_key: ${{secrets.SECRET_KEY}}
debug: ${{secrets.DEBUG}}
db: ${{secrets.DB}}
run: |
pip install coverage
coverage run MoneyTracker/manage.py test
coverage report
- name: Django testing
run: |
python3 MoneyTracker/manage.py test MoneyTracker
Project link is in here.
How should I add secret key to my project on GitHub action?
Environment variables are case-sensitive. Commands run in actions or steps can create, read, and modify environment variables. To set custom environment variables, you need to specify the variables in the workflow file. You can define environment variables for a step, job, or entire workflow using the jobs.
1. (Recommended way for Secrets) The preferred and secure way is to add the Secret env variables in your GitHub repo settings (See this [Link] for more info. Then you can use those variables with the below syntax in your actions/django.yml file.
env:
SECRET_KEY: ${{ secrets.SECRET_KEY }}
See below image or this Link
Add Secrets in Github Repo
1. (Not recommended for Secrets) You can set the env variables using the below syntax, or you can follow Official Docs Here. But if your repo is public then this method will still expose your SECRET_KEY so I wouldn't recommend this for secrets. However, this method can be used if you want to set env variables like PATH.
env:
SECRET_KEY: your_django_secret_key
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