- Building and Monitoring Your First Github Actions Workflow
- Original article by Meercode
- Translation from: The Gold Project
- This article is permalink: github.com/xitu/gold-m…
- Translator: zenblo
- Proofreader: Plusmultiply0, HurryOwen
Github Actions workflow creation management
Github Actions is Github’s native solution for CI/CD and has been available to community developers since its 2019 launch. The simplicity, flexibility, and low cost of Action enabled many teams to migrate from existing CI/CD solutions and explore the possibilities of the new platform.
My team was an early adopter of Github Actions. As a group of javascript-heavy developers, we were able to automate dozens of workflows for both front and back end projects. Because the platform supports Javascript/Typescript, we created a number of Actions (like plug-ins in traditional build tools) to extend functionality to our needs.
After using Github Actions for a year, we found that the tool has the following advantages over the CI/CD solutions we tested previously:
- Zero administrative cost (no agents or master nodes required).
- Easy to learn and master.
- You can keep the workflow in the source code.
- Rich Action (plug-in) library, easy to develop custom Action.
- Reasonable pricing model: 3000 free minutes for power users of private repositories. The public repository is completely free!
- It has a rich action library that makes it easy to develop custom actions.
- Supports Linux, Windows, and macOS platforms. (Support for macOS is rare among competitors).
- You can run the free version on your own device with the help of a self-managed run tool.
One small flaw in the platform is the lack of monitoring tools to track workflow status. As the number of project libraries and workflows we had to manage increased, the problem became more difficult. In the end, we decided to develop our own dashboard as a solution.
With the React front end and NestJS back end, use the relevant Github API and display it in a concise way. The tool has been very popular with our team members and we will continue to develop new features for it.
Recently, we released the dashboard tool as a SaaS project, then launched a public beta program and shared it with the developer community. If you’re interested, you can read Meercode’s story about this blog post or visit meercode. IO to try out the product.
To demonstrate how simple it is to create workflows on Github Actions, we want to show a real-world example.
The task is simple. For a project library on Github, we need the AppCenter to trigger the build when the pull request is sent. Fortunately, AppCenter has a public REST API that you can use to launch builds.
The action we want to create should be triggered in the following scenarios:
- The pull request is opened or reopened.
- Passed the unit tests.
If all the conditions are met, we will start building on AppCenter. Let’s create our action.
From the repository on GitHub, create an app_center_pull_request.yml in the.github/workflows directory. The file.
By using the “name:” attribute, we name the action “Pull Request Opened [App]”.
To trigger our action when we pull the request, we will use native Github workflow events. Of course, the workflow can also be configured to run against one or more events using the “on:” syntax. You can also record a complete list of workflow events available in the Action on the reference page.
Next we will show when triggeredpull_request
Event, what does the action do
Under the “jobs:” attribute, we can add any number of jobs to run. We marked the first job with the “build:” attribute and configured it as shown above.
The “runs-on:” and “matrix:” properties specify the environment in which the action will run. “Steps:” defines steps to run simultaneously:
- The first step is to retrieve the “pull Request Name” from other Actions in the Actions Marketplace for use in the next step.
- In the second step, we will initialize the application and run the tests. If the test runs successfully, proceed to the next action.
- Then use the curl command to call the AppCenter API and configure the build for the appropriate branch name. We use the branch name from step 1 to build the corresponding URI.
- Finally, we trigger builds for the iOS and Android versions:
To run and test the workflow, simply open a Pull Request. This will automatically trigger and run the action. To see the results, go to the Actions TAB of the project library, select the appropriate workflow, and run it.
If you want to use Github Actions more deeply or need to manage a large number of workflows across multiple project libraries, you can always try Meercode, the previously mentioned dashboard solution.
If you find any errors in the translation or other areas that need improvement, you are welcome to revise and PR the translation in the Gold Translation program, and you can also get corresponding bonus points. The permanent link to this article at the beginning of this article is the MarkDown link to this article on GitHub.
Diggings translation project is a community for translating quality Internet technical articles from diggings English sharing articles. The content covers the fields of Android, iOS, front end, back end, blockchain, products, design, artificial intelligence and so on. For more high-quality translations, please keep paying attention to The Translation Project, official weibo and zhihu column.