GitHub Action is a CI\CD continuous integration service launched by GitHub.

It can create and share action scripts to perform any required tasks (including CI/CD) and combine actions in a fully customized workflow.

If you need an action, you don’t have to write a complex script, you can just refer to someone else’s action, and the whole continuous integration process becomes a combination of actions.

For a long time, I used GitHub as a code repository or file repository. My projects were uploaded directly to the server. With GitHub Action, it automatically helps me to deploy to my own server by submitting the code.

The basic concept

GitHub Actions

  1. Runner: github assigned build server to execute CI/CD (can also build runner)
  2. Workflow: Continuous integration of a running process, which is a workflow.
  3. Job: A workflow consists of one or more Jobs. A workflow is a continuous integrated operation that can complete multiple tasks.
  4. Step: Each job consists of multiple steps.
  5. Action: Each step can execute one or more commands (actions) in turn.

Static pages published to Ali Cloud ECS

Go to your warehouse on Github and find the Warehouse Actions TAB

You can create a new one directly, or you can use an existing one. GitHub has created an official marketplace that allows you to search for actions submitted by others.

Link: github.com/marketplace…

Generates a file at this time. Making/workflows/main yaml, its content is revised as follows:

Name: Build And Deploy To Aliyun ECS on: # This CI/CD trigger event push: # Trigger process as long as the push code, refer To the official documentation of branches for more trigger events. [main] pull_request: Branches: [main] Jobs: # Tasks to be executed. There can be multiple tasks. All jobs are in parallel, but often have dependencies. Ubuntu - Latest # Github 2- Core CPU/7 GB of RAM memory/14 GB of SSD disk space Steps -uses: actions/checkout@v2 # Select an existing action and perform your action with: persist-credentials: False ref: main submodules: true - name: Deploy to aliyun server # Specify a name for step that will display uses: Easingthemes /[email protected] # can access the repository, the implementation of the upload server step is encapsulated in this action env: SSH_PRIVATE_KEY: ARGS: "-avzr --delete" SOURCE: "./" REMOTE_HOST: ${{secrets.REMOTE_HOST}} # REMOTE_USER: ${{secrets. "/opt/webwiki/docs" # path to the deployed serverCopy the code

A secret is a context that describes the CI/CD workflow context, using the ${{expression}} syntax. In addition to Secret, there are

  • Github: Workflow information, such as github. Sha, can be used to get the current commit SHA, which can be used to enter a version number for a Sentry or Docker image
  • Env: environment variable
  • Job: indicates the information about the current job. For example, job.status indicates the execution status of the current job
  • Matrix: Describes build information, such as Node and OS version numbers

See the official documentation for more context information

Setting secret content

In the project Settings, add a server configuration with a custom name that is the same as that in main.yaml.

Run the publish

After running, the running result is displayed on the right side:

Each subsequent submission will be executed, and you can view all the executed workflows from the Actions home page:

Ali cloud ECS SERVER_SSH_KEY generated

Log in to the server using Xshell and run the ssh-keygen command.

Then look at the key file:

For security and convenience, you can save the file, copy the content and paste it to Github.