YAML (Yet Another Markup Language) is a human-readable data serialization language that is often used for configuration files, data storage, and communication between systems. Below are some basic concepts and tips for working with YAML.
- YAML is indentation-based, meaning that the indentation of a line indicates its hierarchy and nest within the document.
- YAML uses whitespace, colons, and hyphens to indicate structure. For example, a hyphen indicates the start of a new list item, and a colon indicates the start of a key-value pair.
- YAML supports various data types, including strings, numbers, booleans, and null values. Strings can be denoted using either single or double quotes.
- YAML supports comments, which start with a
#symbol and continue until the end of the line.
- YAML uses anchors (
&) and references (
*) to reuse values within a document. An anchor is a label that is associated with a value, and a reference is a reference to that label.
- YAML supports multiline strings, which can be denoted using either the
|character preserves line breaks and leading whitespace, while the
>character removes line breaks and condenses the string into a single line.
GitHub Actions are a powerful tool for automating workflow processes on GitHub. Below are some tips for working with GitHub Actions:
- To create a workflow, you need to create a
.ymlfile in the
.github/workflowsdirectory of your repository.
- Workflows are triggered by events, such as a push to a branch or the creation of a pull request. You can specify the events that trigger a workflow using the
- Workflows consist of one or more jobs, which are defined using the
jobskey. Each job consists of a series of steps, which are defined using the
- Steps can be one of three types: actions, shell commands, or annotations. GitHub Actions are predefined tasks that are defined in a separate repository or package, shell commands are executed in a shell environment.
- Checkout: The
checkoutaction is used to check out a repository’s code in the GitHub Actions runner environment. This is typically the first step in a workflow and is required for most other actions to work.
- uses: actions/checkout@v2
2. Set up a runtime: The
setup-* actions are used to install and set up various runtime environments in the runner environment. For example, you can use the
setup-node action to install and set up a Node.js runtime, or the
setup-python action to install and set up a Python runtime.
- uses: actions/setup-node@v2
3. Run a script: You can use the
run action to execute a script or command in the runner environment. This is often used to build, test, or deploy code.
- name: Run tests
run: npm test
4. Publish artifacts: The
upload-artifact action is used to upload files or directories as artifacts that can be accessed later in the workflow or after the workflow is complete.
- name: Publish build artifacts
5. Use a condition: You can use the
if key to specify a condition that must be met in order for a step or group of steps to be executed.
- name: Deploy to production
if: github.ref == 'refs/heads/main'
6. Use environment variables: You can use environment variables to pass data between steps and jobs in a workflow. GitHub Actions provides a number of built-in variables, and you can also define your own variables using the
- name: Set environment variable