Skip to content

Commit

Permalink
feat(07-expressions): add README
Browse files Browse the repository at this point in the history
  • Loading branch information
lauromueller committed Nov 5, 2023
1 parent cfeee2b commit 20303c6
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/07-expressions.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# See 07-expressions/README.md for more information
# about the how to use expressions in GitHub Actions.

name: 07 - Using Expressions
run-name: 07 - Using Expressions | DEBUG - ${{ inputs.debug && 'ON' || 'OFF' }}

Expand Down
57 changes: 57 additions & 0 deletions 07-expressions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Using Expressions in GitHub Actions

GitHub Actions provides a powerful feature called expressions that allows you to dynamically evaluate and manipulate data within your workflows. Expressions enable you to create more flexible and intelligent automation. This README provides an overview of how to use expressions effectively in GitHub Actions.

## Understanding Expressions

Expressions in GitHub Actions are enclosed within `${{ }}` and can be used to access and transform data from GitHub contexts, environment variables, inputs, and more. They are evaluated at runtime and can be used in various workflow scenarios, such as conditional statements, setting variables, or generating dynamic content.

## Common Use Cases

Here are some common use cases for using expressions in GitHub Actions:

### 1. Dynamic Variable Assignment

You can use expressions to assign dynamic values to variables within your workflow:

```yaml
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Set Variable Using an Expression
run: |
# Define a dynamic variable using an expression
MY_VAR="Hello, ${{ github.actor }}!"
# Use the variable in an echo statement
echo $MY_VAR
```
## 2. Conditional Steps
Expressions allow you to create conditional steps based on GitHub context or other data:
```yaml
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Conditional Step Using an Expression
run: |
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "This is a push to the main branch."
fi
```
We can also use expressions in `if` statements when deciding whether to execute a step or a job. Under the `if` key, we don't need to add the special `${{ <expression> }}` syntax.

```yaml
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Conditional Step Using an Expression
if: github.event_name == "push" && github.ref == "refs/heads/main"
run: echo "This is a push to the main branch."
```

0 comments on commit 20303c6

Please sign in to comment.