Experience sharing

This article is a taste of the experience to share, and there is no too complex skills, made a minimum code example show, so that everyone can use the action, if the passing bull has advanced skills, please leave a message to share, I will add. The text begins.

What is?

Is a free operating system container (Linux/Windows/macOS), we can let it preinstall the development environment (Node/PHP/Python…) Note: The following articles assume that we have selected a Linux server with NodeJS installed.

What’s the use?

We can upload (Git push) code and execute it in its nodejs. If we have a test script in the code, it will send us an icon to github’s submission record after executing it, as shown below:

red

How does it work?

Enter the Action page

Any repository now has an action button, as shown below:

Choose your environment

The first entry will let us choose the development environment. Here I select Nodejs and click the corresponding “Set Up this Workflow “button.

Tell Action what you want to do

Here we tell “Action” what it wants to do, as shown below:

action

Explain the configuration file

name: Node CI

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@master
    - name: Use Node.js 10.x
      uses: actions/setup-node@v1
    - name: test
      run: |
        npm i
        npm run test:rules

Copy the code

name

Show the title, run time show, doesn’t make much sense.

on

You can register git actions to monitor push/pull_request actions in your repository

For example, to monitor multiple actions:

on: [push, pull_request]
Copy the code

You can also monitor for branches

on:
  push:
    branches:
    - develop
Copy the code

jobs

This is the core function, where we tell the action what to do,

jobs.id

The “build” field can be changed to another name, such as “test”. If there are more than one jobs, the job id can be parallel, but the id cannot be the same. Note: there is a NEEDS field in the document that can be set to rely on execution. I have not implemented it yet. If there are many people reading this article, I will study it and add 😋 in the second article.

jobs.id.run-on

Ubuntu-latest indicates the latest version of Ubuntu. You can also specify the version number. Action supports the following operating systems as instructed:

  • Ubuntu – latest, ubuntu 18.04, or ubuntu 16.04
  • windows-latest, windows-2019, or windows-2016
  • MacOS – latest or macOS – 10.14
jobs.id.steps

Setting up actions is the core function of actions.

jobs.id.steps.name

Used to set the display title of each action, which is displayed at run time and can be written at will.

jobs.id.steps.uses

You can perform some actions encapsulated by action:

  1. Uses: Actions /checkout@master, pull code.
  2. Actions /setup-node@v1 to initialize the Node environment.
jobs.id.steps.run

Execute the command

  1. NPM Run test:rules
  2. Execute our written test command NPM run test:rules

The execution result

View the real Project

conclusion

Good to write so much bar, is also the first use, when writing is also scared, afraid of being released when the big cow spray, but really like action, or want to write an article to promote the next, throw a brick to attract yu. Thank you for reading.