preface

Dear readers, happy New Year, I am after the New Year rushed back to Shanghai to move the brick of the pretty three knives.

Github recently updated an Action feature (probably a long time ago) that allows for a lot of automation. To replace automated scripts (e.g., hook +Jenkins) set by the user.

Because there is no need to use it at ordinary times, after all, I usually use the COMPANY’s CI/CD process, so I have no chance to play Action.

By the Spring Festival holiday, write their own small Demo experience.

This article gives you a quick start on Github Actions by implementing a small Demo of an automated process that automatically executes Junit unit tests and outputs test reports after submitting code.

What is Github Action?

If you have no idea what Github actions are, I recommend taking a look at CI/CD:

www.redhat.com/zh/topics/d…

Github Action defines itself as follows:

Automate, customize, and execute software development workflows in the GitHub Actions repository. You can discover, create, and share actions to perform any job you like (including CI/CD) and merge the actions into a fully customized workflow.

In other words, you can deploy a series of automated scripts to your repository that automatically execute the scripts after you commit/merge branches, etc.

Ruan Yifeng Github Action Guide:

As you know, continuous integration consists of many operations, such as grabbing code, running tests, logging into remote servers, publishing to third-party services, and so on. GitHub calls these actions actions.

Many operations are similar across projects and can be fully shared. GitHub noticed this and came up with the neat idea of allowing developers to write each action as a separate script file and store it in the repository so that other developers can reference it.

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. This is what makes GitHub Actions special.

GitHub Actions have a few terms of their own:

  • Workflow: Continuous integration of a running process, which is a workflow.
  • Job: A workflow consists of one or more Jobs. A workflow is a continuous integrated operation that can complete multiple tasks.
  • Step: Each job consists of multiple steps.
  • Action: Each step can execute one or more commands (actions) in turn.

It’s a bit boring to look at the introduction and definition, but let’s go straight to the code implementation and understand the definitions and instructions in the code.

Quick learning

Create a new folder for the repository. Github/Workflow

First, use your own GitHub repository and add folders to the repository.

A library can have multiple Workflow files. GitHub automatically runs a. Yml file when it finds one in the. GitHub /workflows directory.

Write your Workflow

A yML script is the core of the Action. Let’s create a new blank. Yml script that looks like this:

I have made some comments in the code to help you understand what each instruction means.

The script process is as follows:

  • Specifies that script execution is triggered when a push or pull request is executed
  • Pull up the latest ubuntu image
  • Cache Maven dependency directories to avoid downloading full dependency packages each time and speed up execution
  • Install Java8
  • Specify the pom.xml file path, and then compile the project using Maven
  • Run Junit unit tests

Write unit test code for the project

Ok, once the script is written, we need to write some test code to keep Junit occupied.

I used a repository of my own with complete action scripts and test class code for your reference:

Github.com/qqxx6661/aw…

This is a Maven repository, and we add the test code to the Test folder.

The above test code tests the following static method:

Submit code to trigger Github Action execution

After committing and pushing the code, click on your repository home page and click on the Action TAB:

You can see that there is already execution information.

To see if our Action is executed, click on the Action TAB and find Junit:

Script code can be edited online:

If you click on the commit record, you can see that the action completed several steps successfully:

If you open Maven’s build log, you can see that the first time we run an action, all dependencies are downloaded in real time:

The unit test run logs are normal:

To test whether Maven’s dependencies can be cached, write a few more unit tests and commit:

As you can see, the new action log starts compiling directly, no longer needs to download the full package:

Unit test page executed successfully:

That concludes our simple introductory tutorial.

There are many more features to explore

Of course, this is just the tip of the iceberg for Action, which can do much more than that:

  • Compile package code
  • Automatically upload to the public cloud /App container
  • Unit testing/code coverage testing/document synchronization/release

Waiting for you to explore.

reference

Docs.github.com/cn/actions/…

www.ruanyifeng.com/blog/2019/0…

Pay attention to my

I am an Internet backend development engineer struggling in the front line.

Usually, I mainly focus on back-end development, data security, edge computing and other directions, welcome to exchange.

I can be found on every platform

  • Wechat official account: A ramble on back-end technology
  • Making:@qqxx6661
  • CSDN: @Pretty three knives
  • Zhihu: @ Ramble on back-end technology
  • Nuggets: @ pretty three knife knife
  • Tencent Cloud + community: @ Back-end technology ramble
  • Blog Garden: @ Back-end Technology Ramblings
  • BiliBili: @Pretty three knives

Original article main content

  • Back-end development practices
  • Back-end technical interviews
  • Algorithm problem solving/data structure/design pattern
  • Life feeling

Personal public account: Back-end technology ramble

If the article is helpful to you, please give me a thumbs-up and support. Your thumbs-up and reading is my motivation to update