GitHub Actions is a continuous integration service that GitHub launched in 2018.

The feeling of using it on the project recently is that it is very easy to use and flexible to use. Most of the plug-ins needed for build and deployment can be found in the Github Actions marketplace.

on: push
jobs:
  test:
    strategy:
      matrix:
        platform: [ubuntu-latest, macos-latest, windows-latest]
    runs-on: ${{ matrix.platform }}
    steps:
    - uses: actions/checkout@v1
    - uses: actions/setup-node@v1
      with:
        version: 12
    - run: npm install-ci-test
    - uses:


  publish:
    needs: [build]
    steps:
    - uses: actions/checkout@v1

Copy the code

However, it is inefficient for beginners to test new or modified GitHub Actions by pushing them to the remote end every time they change the code. It is best to debug GitHub Actions locally for quick verification.

Act is one such tool, as its slogan says:

“Think globally, act locally”

It allows us to run GitHub Actions locally for quick feedback, making it much easier to debug code.

Run Github Actions locally with ACT to quickly validate debugging

Note: Docker installation is a prerequisite for act use.

First, let’s install act with BREW (refer to the act installation documentation for other systems)

brew install act
Copy the code

The following command lists all actions in the current directory

act -l
Copy the code

Suppose we have a local written deploy. Yml file (located in the /. Making/workflows/deploy. Yml), then run the following command will be able to deploy at the local actions to run up.

act -j deploy --bind . --secret-file .env
Copy the code
-secret-file can be used to specify environment variables that need to be used in actions. For example, the above example puts the required environment variables in the.env fileCopy the code

The format of the. Env file is as follows:

BASE_URL=http://www.test.com/
GCS_BUCKET=test_bucket
...
Copy the code

Use an act pit

When I used act to run actions for the first time, I didn’t notice that I chose a Micro Docker image as runner, but the result kept reporting errors. Later, I found that it was because the environment in the image of ACT Micro was incomplete and there was no Python runtime. So it’s usually recommended to use medium because large is a bit too big. Medium docker image does not support YARN. You can choose yarn based on your project.

Here are two examples for your reference

1. Deploy the React project to Google Cloud Storage

name: Deploy

on:
  push:
    branches:
      - develop

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Use Node.js
        uses: actions/setup-node@v2
        with:
          node-version: '14'
      - name: Run CI
        run: |
          npm install
          npm run lint
          npm test
      - name: Build
        run: |
          REACT_APP_BASE_URL=${{secrets.BASE_URL}} npm run build
      - name: Set up Cloud SDK
        uses: google-github-actions/setup-gcloud@master
        with:
          project_id: ${{ secrets.GCP_PROJECT }}
          service_account_key: ${{ secrets.GCP_SA_KEY }}
          export_default_credentials: true
      - name: Upload files
        run: |
          gsutil -m rsync -r -d build/ gs://${{ secrets.GCS_BUCKET }}/
          gsutil -m setmeta -h "Cache-Control:no-store" gs://${{ secrets.GCS_BUCKET }}/*
          gsutil -m setmeta -r -h "Cache-Control:max-age=31536000" gs://${{ secrets.GCS_BUCKET }}/static/*

Copy the code

2. Pack the React Native project and release it on the Google Play Store

name: Deploy on: workflow_dispatch: inputs: deploy: description: 'Do you want to deploy to Google Play Store? ' required: true default: "yes" jobs: build: runs-on: ubuntu-latest name: Build steps: - name: Checkout uses: actions/checkout@v2 - uses: actions/setup-node@master - uses: c-hive/gha-yarn-cache@v1 - name: Install node modules run: | yarn install - name: Run lint and test run: | yarn lint yarn test - name: Cache Gradle Wrapper uses: actions/cache@v2 with: path: ~/.gradle/wrapper key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }} - name: Cache Gradle Dependencies uses: actions/cache@v2 with: path: ~/.gradle/caches key: ${{ runner.os }}-gradle-caches-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }} restore-keys: | ${{ runner.os }}-gradle-caches- - name: Make Gradlew Executable run: cd android && chmod +x ./gradlew - name: Set up JDK 1.8 uses: actions/setup-java@v1 with: Java -version: 1.8-name: Bump version uses: Chkfung /[email protected] with: gradlePath: Android /app/build.gradle versionCode: ${{github.run_number}} - name: Build Android App Bundle run: | cd android && ./gradlew bundleRelease --no-daemon - name: Sign App Bundle id: sign_app uses: r0adkll/sign-android-release@v1 with: releaseDirectory: android/app/build/outputs/bundle/release signingKeyBase64: ${{ secrets.ANDROID_SIGNING_KEY }} alias: ${{ secrets.ANDROID_SIGNING_ALIAS }} keyStorePassword: ${{ secrets.ANDROID_SIGNING_KEYSTORE_PASSWORD }} keyPassword: ${{ secrets.ANDROID_SIGNING_KEY_PASSWORD }} - name: Upload Artifact uses: actions/upload-artifact@v2 with: name: signed-app-bundle path: ${{steps.sign_app.outputs.signedReleaseFile}} - name: Deploy to Google Play Store uses: r0adkll/upload-google-play@v1 with: serviceAccountJsonPlainText: ${{ secrets.ANDROID_SERVICE_ACCOUNT }} packageName: com.projecttest releaseFiles: ${{steps.sign_app.outputs.signedReleaseFile}} track: internalCopy the code