generated from ps-actions-sandbox/ActionsFundamentals
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e140620
Showing
11 changed files
with
787 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: Delete Workflows | ||
|
||
on: [workflow_dispatch] | ||
|
||
jobs: | ||
do: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Delete workflow runs | ||
uses: Mattraks/delete-workflow-runs@v2.0.3 | ||
with: | ||
retain_days: 0 | ||
keep_minimum_runs: 0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Init | ||
|
||
on: [create, workflow_dispatch] | ||
|
||
permissions: | ||
issues: write | ||
contents: read | ||
|
||
jobs: | ||
initialize_repo: | ||
runs-on: ubuntu-latest | ||
if: ${{ github.ref == 'refs/heads/main' }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3.3.0 | ||
- name: Create Issue | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
gh issue create -t "❓ What is your experience with GitHub?" -b "What is your experience with GitHub? Whats is your experience with other CI/CD tools? Comment below 👇" | ||
gh issue create -t "❓ What do you want to learn?" -b "What is it you want to learn? What specific scenarios are you interrested in? Comment below 👇" | ||
gh issue create -t "🔍 Retro Day one: What was good?" -b "What did you like on day one of this course? What was good? Comment below 👇" | ||
gh issue create -t "🔍 Retro Day one: What can be improved?" -b "What can be improved? What was missing? Any additional comments? Comment below 👇" | ||
gh issue create -t "❤️ What was the best feature you learned yesterday?" -b "What was the GitHub Actions feature you liked best that you have learned about yesterday the first time? If you want add your hobby to share it with the group. Comment below 👇" | ||
gh issue create -t "🔍 Retro Day two: What was good?" -b "What did you like on day two of this course? What was good? Comment below 👇" | ||
gh issue create -t "🔍 Retro Day two: What can be improved?" -b "What can be improved? What was missing? Any additional comments? Comment below 👇" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Cheat Sheet | ||
|
||
This document contains an overview of fundamental concepts and terminology, you can use this as a reference book if you get lost in the terminology along the way. | ||
|
||
## Github actions high level components | ||
|
||
<img width="671" alt="image" src="https://user-images.githubusercontent.com/10853833/216319332-3d5529e8-abfc-4dab-b9b7-e55c4cba99e5.png"> | ||
|
||
## Yaml functions | ||
|
||
| Function | Description | | ||
|---------------------------------|-------------------------------------------------------------------------------------------------------| | ||
| success() | Returns true if none of the previous steps have failed or been cancelled. | | ||
| always() | Returns true even if a previous step was cancelled and causes the step to always get executed anyway. | | ||
| cancelled() | Returns only true if the workflow was canceled. | | ||
| failure() | Returns true if a previous step of the job had failed. | | ||
| contains(search, item) | Returns true if search contains item. | | ||
| startsWith(search, item) | Returns true if search starts with item. | | ||
| endsWith(search, item) | Return true if search ends with item. | | ||
| format('{0} {1}', item1, item2) | Replaces placeholders in a string. | | ||
| join(array, separator) | All values in array are concatenated into a string using provided separator | | ||
| toJSON(value) | Returns a pretty-print JSON representation of value. | | ||
| fromJSON(value) | Returns a JSON object or JSON data type for value. | | ||
|
||
## Workflow commands | ||
|
||
See also: | ||
https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions | ||
Actions can communicate with the runner machine to set environment variables, output values used by other actions, add debug messages to the output logs, and other tasks. | ||
Most workflow commands use the echo command in a specific format, while others are invoked by writing to a file. | ||
|
||
Example echo workflow command: | ||
```bash | ||
echo "::workflow-command parameter1={data},parameter2={data}::{command value}" | ||
``` | ||
Example write to file workflow command: | ||
```bash | ||
echo "SELECTED_COLOR=green" >> $GITHUB_OUTPUT | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Getting ready | ||
|
||
## Step 1: Set up your GitHub.com account | ||
|
||
For this class, we will use a public account on GitHub.com. We do this for a few reasons: | ||
|
||
We don't want you to "practice" in repositories that contain real code. | ||
We are going to break some things, so we can teach you how to fix them (therefore, refer to the line above). | ||
|
||
You can set up your free account by following these steps: | ||
|
||
* Access [GitHub.com](https://github.com) and click Sign up | ||
* Choose the free account | ||
* You will receive a verification email at the address provided | ||
* Click the link to complete the verification process | ||
* If you already have an account, verify that you can visit github.com within your organization's network. | ||
|
||
GitHub is designed to run on the current versions of all major browsers. Take a look at our list of supported browsers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Michael Kaufmann | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# GitHub Actions Fundamentals | ||
|
||
Repo for the `GitHub Actions Fundamentals` training. | ||
|
||
## 👉 Objectives | ||
|
||
- Understand the __basic components__ and vocabulary of GitHub Actions | ||
- Understand the __YAML__ syntax (scalar types, quotes, literal blocks, maps, and sequences) | ||
- Understand the __workflow syntax__ and how to write workflows using intellisense | ||
- Understand events that can __trigger__ workflows | ||
- Learn the __context and expression syntax__ as well as workflow commands | ||
- Know the different types of __actions__ and how to create/publish them | ||
- Understand the different hosting options for __runners__ | ||
- Use __Secrets__ and __Environments__ for staged deployments | ||
- Workflow templates and __reusable workflows__ | ||
|
||
## Getting ready | ||
|
||
Please follow [these instructions](GettingReady.md) and make sure you have set up everything correctly following the [prerequisites](#-prerequisites). | ||
|
||
## 📆 Agenda | ||
|
||
### Day 1: 🚀 Getting started | ||
|
||
- [ ] Introduction and Icebreaker | ||
- [ ] GitHub Actions Fundamentals | ||
- [ ] The YAML syntax | ||
- [ ] Basic workflow syntax | ||
- [ ] Events that trigger workflow | ||
- [ ] Jobs and steps | ||
- [ ] :mag: Demo: Creating a workflow | ||
- [ ] 🔨 Hands-on: [My first Action workflow](hol/01-My-first-workflow.md) | ||
- [ ] Advanced [workflow syntax](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions) | ||
- [ ] :coffee: Break | ||
- [ ] GitHub Actions | ||
- [ ] Types of Actions | ||
- [ ] 🔨 Hands-on: [My first container Action](hol/02-My-first-action.md) | ||
- [ ] Typescript and composite actions | ||
- [ ] Sharing and releasing actions | ||
- [ ] Using the GitHub API and Octokit | ||
- [ ] Job descriptions | ||
|
||
### Day 2 | ||
- [ ] Introduction | ||
- [ ] Actions for CI/CD | ||
- [ ] Permissions for GitHub Token | ||
- [ ] Environments and Secrets | ||
- [ ] Staged deployments with environments, approvals, and deployment gates | ||
- [ ] 🔨 Hands-on: [Staged deployments](hol/03-Staged-deployments.md) | ||
- [ ] :coffee: Break | ||
- [ ] Action policies | ||
- [ ] Running your workflows | ||
- [ ] Sharing workflows | ||
- [ ] 🔨 Hands-on: [Reusable workflows](hol/04-Reusable-workflows.md) | ||
- [ ] Best practices and security | ||
|
||
|
||
## ⚡ Prerequisites | ||
|
||
The workshop is designed for developers that have used other platforms like Azure DevOps, GitLab, or Bitbucket and now want to switch to GitHub. But it is also suitable for people that are new to topics like git, CI/CD, and DevOps. | ||
|
||
For this workshop you need the following: | ||
|
||
- A laptop (Windows, Mac, or Linux) | ||
- A free account for https://github.com | ||
- It is recommended to have a second screen for the hand-on labs | ||
|
||
## Cheat Sheet | ||
Find common terminology for reference [here](./CheatSheet.md) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
# 🔨 Hands-on: My first workflow | ||
|
||
In this hands-on lab your will create your first GitHub Actions Workflow and learn how you can use Actions to automate tasks in your software development lifecycle. If you like more background information, please refer to the [GitHub Actions](https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions) pages on GitHub Docs. Good luck! 👍 | ||
|
||
This hands on lab consists of the following steps: | ||
- [Creating a repository](#creating-a-repository) | ||
- [Creating the workflow](#creating-the-workflow) | ||
- [Viewing your workflow results](#viewing-your-workflow-results) | ||
|
||
## Creating a repository | ||
|
||
Go to [Code](/../../) tab of this repository and click `Use this template`: | ||
|
||
<img width="400" alt="2022-09-18_11-24-58" src="https://user-images.githubusercontent.com/5276337/190895393-6fa0fad9-e05c-4fea-8126-a291b087d663.png"> | ||
|
||
Select your GitHub user as the owner and name the repository. Leave the repo public to have unlimited action minutes: | ||
|
||
<img width="400" alt="2022-09-18_11-25-57" src="https://user-images.githubusercontent.com/5276337/190895398-751a1ec9-c1cf-497f-beb7-a6b53d4d911e.png"> | ||
|
||
Continue now in the new repository. | ||
|
||
## Creating the workflow | ||
|
||
Go to **Actions** | [New Workflow](/../../actions/new) and click on [set up a workflow yourself](/../../new/main?filename=.github%2Fworkflows%2Fmain.yml&workflow_template=blank). | ||
|
||
1. Rename the file `main.yml` in the `.github/workflows` directory to `github-actions-demo.yml`. | ||
<img width="400" alt="image" src="https://user-images.githubusercontent.com/5276337/174096754-4e2d7219-9caf-42e8-bfd9-c190762886d3.png"> | ||
|
||
2. Remove the template content - we want to create the workflow from scratch. | ||
3. Click <kbd>Ctrl</kbd>+<kbd>Space</kbd> and select name as the first element: | ||
|
||
<img width="400" alt="image" src="https://user-images.githubusercontent.com/5276337/174097468-8be92e37-7948-4895-b5ed-20a22c5773bc.png"> | ||
|
||
4. Set the workflow name to `GitHub Actions Demo`: | ||
|
||
```YAML | ||
name: GitHub Actions Demo | ||
``` | ||
5. Add the triggers to the worklow with the help of <kbd>Ctrl</kbd>+<kbd>Space</kbd> and the documentation. We want the workflow to trigger: | ||
- on every push to the `main` branch, but not when there are changes to files in the `.github` folder. | ||
- on every pull request with `main` as the base branch | ||
- Every sunday at 6:15 UTC | ||
- Manually | ||
|
||
<details> | ||
<summary>Solution</summary> | ||
|
||
```YAML | ||
on: | ||
push: | ||
branches: [ main ] | ||
paths-ignore: [.github/**] | ||
pull_request: | ||
branches: [ main ] | ||
schedule: | ||
- cron: '15 6 * * 0' | ||
workflow_dispatch: | ||
``` | ||
|
||
</details> | ||
|
||
6. Create a job `Build` that runs on the latest Ubuntu image on GitHub hosted runners. Check the documentation of the [virtual environments](https://github.com/actions/virtual-environments/) what label to use and what version it is. The job should do the following things: | ||
- Output the name of the event that triggered the workflow | ||
- Output the name of the branch that the repository is currently referencing | ||
- List all files in the repository | ||
|
||
<details> | ||
<summary>Solution</summary> | ||
|
||
```YAML | ||
jobs: | ||
Build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- run: | | ||
echo "🎉 The job was triggered by event: ${{ github.event_name }}" | ||
echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ." | ||
- uses: actions/checkout@v3.3.0 | ||
- name: List files in the repository | ||
run: | | ||
echo "The repository ${{ github.repository }} contains the following files:" | ||
tree | ||
``` | ||
|
||
</details> | ||
|
||
7. Commit the workflow file - and trigger the workflow manually. It should not run automatically if your path filter works. Got to [Action](/../../Actions), select [GitHub Actions Demo](/../../actions/workflows/github-actions-demo.yml) and `Run workflow`: | ||
|
||
<img width="600" alt="image" src="https://user-images.githubusercontent.com/5276337/174105162-19f33fd1-8533-4860-9279-88fabec84451.png"> | ||
|
||
|
||
## Viewing your workflow results | ||
|
||
1. Click on your workflow run: | ||
|
||
<img width="600" alt="image" src="https://user-images.githubusercontent.com/5276337/174105747-0e205e0d-37cc-464c-905b-5b29be74fc75.png"> | ||
|
||
2. Click on the job 'Build': | ||
|
||
<img width="400" alt="image" src="https://user-images.githubusercontent.com/5276337/174105990-a1c204c6-fb7d-44a4-9343-6982899edb25.png"> | ||
|
||
3. Expand `Set up job` and note the log with the line number (line numbers are links). Check the information about the virtual environment and included software: | ||
|
||
<img width="600" alt="image" src="https://user-images.githubusercontent.com/5276337/174106759-c2a8f933-74cf-42a4-899b-b29dc67eccd7.png"> | ||
|
||
4. Expand your jobs and check that the output was correct. | ||
|
||
<img width="400" alt="image" src="https://user-images.githubusercontent.com/5276337/174107136-af9187c1-dbee-4109-9ddc-f2abd4830282.png"> | ||
|
||
5. Verify you other triggers by modifying the [README.md](/README.md) file: | ||
- Modify and commit: triggers build (`push`) | ||
- Modify and add `[skip ci]` (not triggering the workflow): | ||
<img width="350" alt="image" src="https://user-images.githubusercontent.com/5276337/174110845-93d4a38a-9c8a-4336-9b6a-9089ea9a1cfd.png"> | ||
|
||
- Modify and create pull request (trigger: `pull_request`) | ||
|
||
## Summary | ||
|
||
In this hands-on you've learned to create you first workflow with triggers, jobs, steps, and expressions. Next you will write your [first GitHub Action](02-My-first-action.md). |
Oops, something went wrong.