In modern software development, Continuous Integration (CI) and Continuous Deployment (CD) are key practices for improving development efficiency and quality. GitHub Actions is a powerful automation tool provided by GitHub that helps developers easily implement CI/CD and broader automation workflows.
The Role of GitHub Actions
GitHub Actions is a powerful automation platform that allows developers to define and run workflows in GitHub repositories. It can automatically execute a series of tasks (such as code building, testing, deployment, etc.) based on specific events (like code pushes, pull requests, tag releases, etc.). Through GitHub Actions, developers can achieve full automation from code submission to deployment, saving time and effort while reducing human errors.
GitHub Actions Workflow Structure
GitHub Actions workflows consist of several components, with the most important being jobs and steps.
Jobs
A workflow can contain multiple jobs, each being an independent execution unit that can run in different environments.
1 | jobs: |
runs-on
specifies the environment for running the job - here we’re using GitHub’s latest Ubuntu environment.
Steps
Each job can contain multiple steps, where each step is an independent task that can execute a series of commands or call predefined actions. Predefined actions can be found in the GitHub Marketplace.
1 | - name: Get current tag # Step name |
Variable Passing
Just like in bioinformatics analysis pipelines I’ve written before, different steps often need to pass information to complete a task. As a simple configuration file, YAML can’t implement variable passing directly, so we need to rely on some environment variables set in the GitHub Actions framework.
Passing Information Between Steps
When executing code in steps, you can pass information between steps by appending content to the special environment variable $GITHUB_OUTPUT
:
1 | - name: Save info |
Passing Information Between Jobs
In jobs, you can specify to pass outputs from specific steps to job inputs as follows:
1 | jobs: |
Example: Building a Project and Publishing
1 | name: BUILD |