Preface
Github Actions official document (the general entry of all the official documents below) gives a detailed description of many details, but if you are the first time to contact, you see a lot of details, and you don't know what they are, so you will forget them soon. This article, from the code of my project, in general, to understand Actions. At the end of the article, I will post some important official documents, learn these basics, and then read other documents to master them better
Github Actions
When the code is push ed and meets the configured conditions, the specified operation will run automatically. Github Actions provides Free hardware (view configuration) , to realize the operation of continuous integration.
These processes are configured through the yml file in the project.
term
- workflow
Represents a continuous integration process - job
Represents the construction task. Each workflow can be composed of one or more jobs, which can support concurrent job execution. When all jobs are completed, the workflow ends - step
Each job consists of one or more step s, which are executed in sequence - action
Each step consists of an action. github has provided an action market, which can search for various third-party actions and freely combine these actions to achieve more complex operations
Read a lot of articles( Getting started with GitHub Actions,Github Actions )It is said that each step is composed of one or more actions. However, in the specific development process, it is found that there is no field in the list of steps, so we can set multiple actions, and uses can only set one action. More articles even confuse step with action
Each step is composed of one or more actions, which are executed in sequence. Here, action needs to be explained in particular. Action can be a custom script or a script that references a third party. Depending on the github open source community, many actions can be reused directly (or written by yourself). github has provided an action market, which can search for various third-party ACTIS And there are many actions available.
Example
Here is an example to see how to use it. Here is Android's continuous integration yml file,
# The name of workflow will be displayed in the right list of Actions of github project, as shown below name: DEBUG_CI # Trigger the workflow when the following conditions are met on: push: # Push occurred on the specified remote branch branches: - dev # Specified file modified paths: - 'config.gradle' jobs: # Multiple jobs. If there are multiple jobs, each starts with "-" first-job: # The system environment in which the job runs supports ubuntu, windows and Mac OS runs-on: ubuntu-latest steps: # Here are multiple step s, each beginning with "-" # step: check branch - uses: actions/checkout@v1 # step: set jdk version # step name - name: set up JDK 1.8 # Reference public action uses: actions/setup-java@v1 with: # Setting parameters java-version: 1.8 # step: Pack apk - name: Build with Gradle # Run command run: chmod +x gradlew &&./gradlew assembleDebug #step: upload apk to action and view it in the upper right corner # Official documents https://help.github.com/cn/actions/automating-your-workflow-with-github-actions/persisting-workflow-data-using-artifacts#uploading-build-and-test-artifacts - name: Upload APK uses: actions/upload-artifact@v1 with: name: app path: app/build/outputs/apk/debug/xw-debug.apk # step: upload files to Dandelion - name: Upload To Pgyer uses: JantHsueh/upload-file-action@master with: url: https://www.pgyer.com/apiv2/app/upload method: POST # ${{secrets. Pgyer [u key}} uses the secret key. How to set it is described below forms: '{"_api_key":"${{ secrets.pgyer_key }}","buildInstallType":3}' fileForms: '{"file":"app/build/outputs/apk/debug/xw-debug.apk"}' #step: get apk version number - name: Get Apk Info #step id id: apk uses: JantHsueh/get-apk-info-action@master with: apkPath: app/build/outputs/apk/debug/xw-debug.apk #Gets the time in the specified time zone - name: Get Time id: time uses: JantHsueh/get-time-action@master with: timeZone: 8 # Call the interface to modify the version number of the database - name: Update SoftwareVersion uses: JantHsueh/webrequest-action@master with: url: https://www.adsff123.com/app/guest/updateSoftwareVersion method: POST # ${{steps.apk.outputs.versionCode}} uses the output parameter versionCode of step with id apk payload: '{"id":1,"softwareType":1,"recommend":1,"versionDesc":"App Auto publish succeeded, time ${{ steps.time.outputs.time}} \n5 Update in minutes \n8 Minutes later \n10 Best in minutes","version":"${{ steps.apk.outputs.versionNum }}","versionNum":${{ steps.apk.outputs.versionCode }}}' headers: '{"Content-Type": "application/json","authorization":"${{ secrets.update_software_version_key }}","platform":"android"}' #Get git log - name: Get git log id: git_log uses: JantHsueh/get-git-log-action@master with: tag: release # Send message to pin - name: dingtalk uses: JantHsueh/webrequest-action@master with: url: ${{ secrets.dingtalk_webhook }} method: POST payload: '{"msgtype": "text", "text": {"content": "West fog agent-Beta version(debug)-App To update-Version number: ${{ steps.apk.outputs.versionNum }},Directly in App Update to latest version in \n Update record from last official version: \n${{ steps.git_log.outputs.log }}"}}' headers: '{"Content-Type": "application/json"}'
The action s used in each step are as follows:
-
Compile and pack
Execute the command Chmod + X gradlew & &. / gradlew assemblydebug -
Upload to Dandelion https://github.com/JantHsueh/upload-file-action
-
Get APK information https://github.com/JantHsueh/get-apk-info-action
-
Get the time of the specified time zone https://github.com/JantHsueh/get-time-action
-
Get git's submission log https://github.com/JantHsueh/get-git-log-action
-
Send message to pin https://github.com/JantHsueh/webrequest-action
Each item gives the github address and usage. I wrote detailed instructions in README.md. welcome to start these Actions projects
Configure workflow
The workflow yaml file described above needs to be placed in the project root directory:. GitHub / workflow/
For example:. GitHub / workflow / debug-workflow.yml
Official documents: Configure workflow
Data transfer between pairs of different job s
Official documents: Using component persistence workflow data
Output and input of action parameter
Reference to official documents Create JavaScript Action In - an example of testing your actions in a workflow
Set secret key
Official documents: Creating and using encrypted secrets
Custom Action
There are two ways to create an Action:
- Create JavaScript Action , which is to develop functions in Node.js
- Create Docker container Action , this is to create a docker container, and the operations that can be implemented are very free
The Action return value is how json uses:
In the above examples, all return a parameter, such as an int and a string. How to reference it if json is returned?
The official documents don't specify it. I'm here project In, I see that there is such a use. It's about the following. It's to parse json under Ubuntu command. But I want to pass in the specified parameter in json as the parameter of action in the next step, which is not always possible.
run: | $output = '${{ steps.webhook.outputs.output }}' | ConvertFrom-Json Write-Host "Time from output $($output.time) statusCode $($output.statusCode) data $($output.data)"
epilogue
These are the main basic contents. After mastering these, you can go to the official documents to have a better idea. Many of the official documents are in Chinese, and they are clearly written, so we will not repeat them