github Actions持续化应用(expo)
https://github.com/expo/expo-github-action#creating-a-new-eas-build
利用github actions来对项目进行持续化集成,我现在开发的项目是expo项目,expo发布本来就十分简单,但是随着项目的壮大,持续化集成已经成为不得不考虑的辅助措施了。
关于github actions的介绍:
actions workfows
简单而言就是可以再.github/workflows/下面添加yml文件,通过一定的语法来触发action,比如每次在push之后自动触发就可以添加on: [push],pr合并之后触发等等,支持的触发事件,还可以支持具体哪些branch才会触发之类,功能很强大,甚至比jenkins还方便。这里记录一下本人集成expo项目的过程,以备后续深挖:
在该目录下添加deploy-dev.yml文件(文件名字随意,有意义即可,可以添加多个),其内容如下:
# PR to dev/main, run tests and create review
name: CI Pull Request
on: [push]
# on:
# pull_request:
# # branches-ignore:
# # - 'main'
# paths:
# - 'src/**'
jobs:
ci-test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
node: [14]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- name: Gen Token
run: |
echo "//npm.pkg.github.com/:_authToken=${{ secrets.REPO_READ_TOKEN }}" > ~/.npmrc
- name: Install
run: yarn install --frozen-lockfile
- name: Lint
run: yarn lint
# - name: Build
# run: yarn build
# - name: Test
# run: yarn test
review:
needs: [ci-test]
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest]
node: [14]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- uses: expo/expo-github-action@v6
with:
expo-version: 4.x
token: ${{ secrets.EXPO_TOKEN }}
# expo-username: "niejianlong@cavalry.online"
# expo-password: "NJLd123456"
- name: Echo Token
run: echo "${{ secrets.EXPO_TOKEN }}"
# - name: Gen Token
# run: |
# echo "//npm.pkg.github.com/:_authToken=${{ secrets.REPO_READ_TOKEN }}" > ~/.npmrc
- name: Install
run: yarn install --frozen-lockfile
- name: Gen Graphql
run: yarn gen:gql
- name: Expo Publish Review
run: expo publish --release-channel staging-v1
- name: Find Comment
uses: peter-evans/find-comment@v1
id: fc
with:
# issue-number: ${{ github.event.pull_request.number }}
issue-number: 1
comment-author: "github-actions[bot]"
body-includes: This is a QR code for access to the preview app.
- name: Comment Review QR code
if: steps.fc.outputs.comment-id == ''
uses: peter-evans/create-or-update-comment@v1
with:
# issue-number: ${{ github.event.pull_request.number }}
issue-number: 2
body: |
:lock: This is a QR code for access to the preview app.
:iphone: Scan a code with your device.
![QR Code](https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=https://expo.dev/@the-pique-lab/frontend-parent?release-channel=staging-v1
reactions: rocket
name随便起一个有意义的名字即可,指定push之后触发on: [push],然后jobs分两大块,一个是ci-test,一个是review,
image.png
这里重点说一下 secrets.EXPO_TOKEN这个变量,github设计了secrets机制,可以把一些敏感信息放到secrets下面,这样别人就看不到secrets具体信息了,即使想打印出来这些变量,显示也是
***
image.png
github secrets设置过程,可以设置repository的secrets也可以设置organization的secret,
image.png
其中还有这段代码:
- uses: expo/expo-github-action@v6
with:
expo-version: 4.x
token: ${{ secrets.EXPO_TOKEN }}
uses代表可以使用某些具体的第三方插件,这里用的就是expo提供的expo/expo-github-action插件,可以免登陆,要不还得需要每次执行expo login命令,具体使用:https://github.com/expo/expo-github-action
有时候不同版本的react-native对服务器以及java版本要求是不一样的,所以有时候本地可以打包成功,expo 服务器却有可能失败,这时候需要配置:
https://docs.expo.dev/build-reference/infrastructure/#image--ubuntu-1804-jdk-11-ndk-r19c 可以选择不同的服务器配置,比如我现在遇到了一个问题
image.png
这时候需要选java版本是11的服务器,
image.png
image.png