Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create workshop setup and solutions for every step #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/actions/example/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Bad practice example
description: 'This composite action to generic'
inputs:
execute-command:
description: 'The command to execute'
required: true
runs:
using: "composite"
steps:
- uses: actions/checkout@v4
- name: Execute command
run: echo "Running command ${{ inputs.execute-command }}"
shell: bash
- uses: actions/upload-artifact@v4
with:
name: ${{ inputs.execute-command }}-artifact
path: ./**
22 changes: 22 additions & 0 deletions .github/actions/greet-and-randomize/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Greet and randomize
description: 'Greet someone and create a random number as output'
inputs:
who-to-greet:
description: 'Who to greet'
required: true
outputs:
random-number:
description: "Random generated number"
value: ${{ steps.random-number.outputs.random-number }}
runs:
using: "composite"
steps:
- name: Greet
run: echo "Hello $INPUT_WHO_TO_GREET."
shell: bash
env:
INPUT_WHO_TO_GREET: ${{ inputs.who-to-greet }}
- name: Generate random number
id: random-number
run: echo "random-number=$(echo $RANDOM)" >> $GITHUB_OUTPUT
shell: bash
10 changes: 10 additions & 0 deletions .github/workflows/1_basic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Basic Action Skills
on: push
jobs:
echo:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run a sample script
run: echo "Hello, Github Actions Workshop Workflow"
50 changes: 50 additions & 0 deletions .github/workflows/2_intermediate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Intermediate Action Skills
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '20'
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
docker-base:
runs-on: ubuntu-latest
container: node:hydrogen-alpine
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
matrix:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18, 22]
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Deploy
run: |
chmod +x ./deploy/deploy.sh
./deploy/deploy.sh
env:
API_TOKEN: ${{ secrets.API_TOKEN }}
44 changes: 44 additions & 0 deletions .github/workflows/3_advanced.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Advanced action skills
on:
issue_comment:
push:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '20'
- name: Install dependencies
run: npm install
- uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Run tests
run: npm test
variables:
runs-on: ubuntu-latest
steps:
- name: Create date
id: create_date
run: |
CURRENT_DATE=$(date +'%Y-%m-%d')
echo "current date $CURRENT_DATE"
echo "current_date=$CURRENT_DATE" >> "$GITHUB_OUTPUT"
- name: Create image
run: echo "Create docker image with tag ${{ steps.create_date.outputs.current_date }}"
- name: Deploy tag
run: echo "Deploy tag ${{ steps.create_date.outputs.current_date }} to environment"
deploy:
if: contains(github.event.comment.body, '/deploy')
runs-on: ubuntu-latest
steps:
- name: Run on deploy comment
run: |
echo "Reference: ${{ github.ref }} or the base reference of the pull-request: ${{ github.base_ref }}"
echo "Deploy to a certain environment"
28 changes: 28 additions & 0 deletions .github/workflows/4_composite.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Composite Actions
on: [push]

jobs:
greet-randomize:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: greet-and-randomize
uses: ./.github/actions/greet-and-randomize
with:
who-to-greet: 'Hack&Heat'
- run: echo random-number "$RANDOM_NUMBER"
shell: bash
env:
RANDOM_NUMBER: ${{ steps.greet-and-randomize.outputs.random-number }}
greet-randomize-external:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: greet-and-randomize
uses: senacor/[email protected]
with:
who-to-greet: 'Hack&Heat'
- run: echo random-number "$RANDOM_NUMBER"
shell: bash
env:
RANDOM_NUMBER: ${{ steps.greet-and-randomize.outputs.random-number }}
33 changes: 33 additions & 0 deletions .github/workflows/bad_practice.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Bad practice
on:
push:
branches:
- doesnt-exist

jobs:
install:
runs-on: ubuntu-latest
steps:
- id: Install application
uses: ./.github/actions/example
with:
execute-command: "npm install"
build:
needs:
- install
runs-on: ubuntu-latest
steps:
- id: Install application
uses: ./.github/actions/example
with:
execute-command: "npm build"
container-build:
needs:
- install
- build
runs-on: ubuntu-latest
steps:
- id: Install application
uses: ./.github/actions/example
with:
execute-command: "podman build"
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
.idea/*
.idea/*

node_modules/*

.tap/*
35 changes: 24 additions & 11 deletions 1_basic_github_actions.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# Introduction to GitHub Actions

Key Concepts: Workflows, Jobs, Steps, Actions.
YAML syntax overview.
Overview of the GitHub Actions marketplace.
# How to ?

# Creating Your First Workflow
* Create a yaml file unter ``.github/workflows``
* Every file needs the following information:
** name -> name of the workflow
** on -> trigger for the workflow
** jobs -> list of jobs to execute

Hands-On Exercise:
Create a simple workflow that runs on push to the main branch.

Example:
```yaml
name: First Workflow
on: push
Expand All @@ -18,11 +16,26 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Run a sample script
run: echo "Hello, GitHub Actions!"
```
Run the workflow and review the output.
Discussion on the YAML file structure and how to interpret the workflow logs.

## Details: Trigger

* Trigger are different GIT or Github Events
* Git Events (https://docs.github.com/de/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows):
** push: [BRANCH oder TAG] -> Run on a ``git push``
* Github Events (example):
** pull_request -> Run on every push within a pull request
** issue_comment -> Run on comment within a pull request or issue

# Exercise: Your First Workflow

Hands-On Exercise: `Create a simple workflow that runs on push to the main branch.`

* Create a new branch within this repository (with your name or codename)
* Create a workflow file
* Run the workflow file

[next >>](./2_intermediate_github_actions.md)
73 changes: 55 additions & 18 deletions 2_intermediate_github_actions.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Exploring Pre-built Actions (20 minutes)
# Next level

Hands-On Exercise:
Use pre-built actions from the GitHub Marketplace (e.g., setting up Node.js, running tests).
Example:
## Pre-build actions

Pre-built actions from the GitHub Marketplace (e.g., setting up Node.js, running tests) provide flexibility and simple workflows.
The actions provide additional commands or functionality within your job. Such as the Setup Node.js Action provide a working node environment

Usage:
```yaml
name: Node.js CI
on: [push]
Expand All @@ -14,27 +17,62 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
node-version: '14'
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
```
Discussion on the flexibility of using community actions.

# Workflow Triggers and Contexts (20 minutes)
## Using docker images as base

Usage:
```yaml
name: Node.js CI
on: [push]
jobs:
docker-base:
runs-on: ubuntu-latest
container: node:hydrogen-alpine
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
```

The defined container image is used as base for the following steps within the jobs.

## Parallel Jobs and Matrix Builds

Steps within a Job are running sequentially. Multiple jobs run in parallel as long no dependencies between jobs are defined.

You want to test your application against multiple node version, this is used in libraries.
You can use matrix build, defining multiple node version and referencing in the job, spawns for every defined version a job.
Example: https://github.com/senacor/azure-function-middleware/blob/master/.github/workflows/ci.yml#L13

```yaml
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10, 12, 14]
steps:
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
```

Hands-On Exercise:
Explore different triggers (push, pull_request, schedule, etc.).
Use contexts and expressions to add conditional logic to workflows.
Example: Conditionally run jobs only on certain branches.
## Using Secrets in Workflows

# Using Secrets in Workflows (20 minutes)
As every other build system secrets are used to install apps in a cloud or kubernetes environment.

Hands-On Exercise:
Store sensitive data using GitHub Secrets.
Create a workflow that uses a secret for deployment.
Example:
```yaml
name: Deploy to Production
on: push
Expand All @@ -45,10 +83,9 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2
- name: Deploy
run: ./deploy.sh
run: ./deploy/deploy.sh
env:
API_TOKEN: ${{ secrets.API_TOKEN }}
```
Discussion on security best practices.

[next >>](./3_advanced_github_actions.md)
Loading
Loading