|
1 |
| -# Git advanced commands |
| 1 | +# Create your first GitHub action |
2 | 2 |
|
3 | 3 | ## What you will learn
|
4 | 4 |
|
5 |
| -- Get a single commit to another branch |
6 |
| -- Using git fragments |
7 |
| -- Undo _almost_ everything |
| 5 | +- Automate, customize, and execute your software development workflows right in your GitHub repository |
8 | 6 |
|
9 | 7 | ## 👾 Before we start the exercise
|
10 | 8 |
|
11 |
| -- Check the [`oh-my-zsh` Cheatsheet](https://github.com/ohmyzsh/ohmyzsh/wiki/Cheatsheet) |
| 9 | +- GitHub Actions is a CI/CD (Continuous Integration/Continuous Deployment) solution provided by GitHub. |
| 10 | +- You may ask yourself "What is a GitHub action?" [everything is on the `github-actions` documentation](https://help.github.com/en/articles/workflow-syntax-for-github-actions) |
12 | 11 |
|
13 | 12 | ## 👨🚀 Exercise 1.1
|
14 | 13 |
|
15 |
| -- [ ] From `main` create a branch `gcb feature/cherry-pick` |
16 |
| -- [ ] Create a slide "How to apply commit" |
17 |
| -- [ ] Commmit your work |
18 |
| -- [ ] Go to your main branch with `gcm` |
19 |
| -- [ ] Use `git cherry-pick YOURSHA1` to get your commit without merging it to `main` |
| 14 | +Workflows are custom automated processes that you can set up in your repository to build, test, package, release, or deploy any code project on GitHub. |
20 | 15 |
|
21 |
| -## 👨🚀 Exercise 1.2 |
22 |
| - |
23 |
| -- [ ] Create a branch with `gcb feature/stash` |
24 |
| -- [ ] Create a slide "How to use git fragments" |
25 |
| -- [ ] Move your diff between 2 branches using `git stash` and `git stash pop` |
26 |
| -- [ ] Commmit your work |
27 |
| - |
28 |
| -## 👨🚀 Exercise 1.3 —Undo a “public” change |
29 |
| - |
30 |
| -__Scenario__: You just ran `git push`, sending your changes to GitHub, now you realize there’s a problem with one of those commits. You’d like to undo that commit. |
31 |
| - |
32 |
| -- [ ] Create a new slide "this one will be reverted" |
33 |
| -- [ ] Identify the last sha1 with `glol` |
34 |
| -- [ ] Use `git revert <SHA1>` to commit your changes |
| 16 | +To create a new workflow: |
35 | 17 |
|
36 |
| -## 👨🚀 Exercise 1.4 —Fix the last commit message |
| 18 | +- [ ] Go to your GitHub repository. |
| 19 | +- [ ] Click on the Actions tab. |
| 20 | +- [ ] Click on set up a workflow yourself if you want to create a custom workflow, or you can choose a template. |
37 | 21 |
|
38 |
| -__Scenario__: You just typo’d the last commit message, you did `git commit -m "Fxies bug #42"` but before `git push` you realized that really should say `“Fixes bug #42”`. |
39 |
| - |
40 |
| -- [ ] Create a new slide "How to fix the last commit message" |
41 |
| -- [ ] Undo with `git commit --amend` or `git commit --amend -m "Fixes bug #42"` |
42 |
| - |
43 |
| -## 👨🚀 Exercise 1.5 —Undo “local” changes |
| 22 | +## 👨🚀 Exercise 1.2 |
44 | 23 |
|
45 |
| -__Scenario__: The cat walked across the keyboard and somehow saved the changes, then crashed the editor. You haven’t committed those changes, though. You want to undo everything in that file—just go back to the way it looked in the last commit. |
| 24 | +- [ ] Create a new file `.github/workflows/hello.yml` |
46 | 25 |
|
47 |
| -- [ ] Try to reproduce the scenario |
48 |
| -- [ ] Cancel your changes with `git checkout -- <bad filename>` |
| 26 | +```yml |
| 27 | +name: CI |
49 | 28 |
|
50 |
| -## 👨🚀 Exercise 1.6 —Reset “local” changes |
| 29 | +on: [push, pull_request] |
51 | 30 |
|
52 |
| -__Scenario__: You’ve made some commits locally (not yet pushed), but everything is terrible, you want to undo the last three commits—like they never happened. |
| 31 | +jobs: |
| 32 | + build: |
| 33 | + runs-on: ubuntu-latest |
53 | 34 |
|
54 |
| -- [ ] Try to reproduce the scenario |
55 |
| -- [ ] Undo with: `git reset <last good SHA>` or `git reset --hard <last good SHA>` |
| 35 | + steps: |
| 36 | + - uses: actions/checkout@v2 |
56 | 37 |
|
57 |
| -## 👨🚀 Exercise 1.7 —Mass undo/redo |
| 38 | + - name: Run a one-line script |
| 39 | + run: echo Hello, world! |
| 40 | +``` |
58 | 41 |
|
59 |
| -__Scenario__: You started this feature in one direction, but mid-way through, you realized another solution was better. You’ve got a dozen or so commits, but you only want some of them. You’d like the others to just disappear. |
| 42 | +## 👨🚀 Exercise 1.3 |
60 | 43 |
|
61 |
| -- [ ] Create a branch `gcb feature/clean-mess` |
62 |
| -- [ ] Create new slide "How to rebase" |
63 |
| -- [ ] Commit your work |
64 |
| -- [ ] Change the theme |
65 |
| -- [ ] Commit your work |
66 |
| -- [ ] Update your slide |
| 44 | +- [ ] Commit to your repository to launch the action |
67 | 45 |
|
68 |
| -```markdown |
69 |
| -__What’s happening__: `-i` puts rebase in “interactive mode”. It starts off like the rebase discussed above, but before replaying any commits, it pauses and allows you to gently modify each commit as it’s replayed. |
70 |
| -``` |
71 |
| -- [ ] Commit your work |
72 |
| -- [ ] Use `git rebase -i <earlier SHA>` and remove the "Changing theme commit" and `fixup` the last commit |
| 46 | +## 👨🚀 Exercise 1.4 |
73 | 47 |
|
74 |
| -## 👽 Bonus —Redo after undo “local” |
| 48 | +You can trigger a GitHub Actions workflow on a specific branch by specifying the branch name in the on section of your workflow file. |
75 | 49 |
|
76 |
| -__Scenario__: You made some commits, did a `git reset --hard` to “undo” those changes (see above), and then realized: you want those changes back! |
| 50 | +- [ ] Create another file `.github/workflows/hello-branch.yml` |
77 | 51 |
|
78 |
| -- [ ] Try to reproduce the scenario |
79 |
| -- [ ] Undo with: `git reflog` and `git reset` or `git checkout` |
| 52 | +```yml |
| 53 | +name: CI |
80 | 54 |
|
81 |
| -You can recover _almost_ anything—anything you’ve committed—via the reflog. |
| 55 | +on: |
| 56 | + push: |
| 57 | + branches: |
| 58 | + - main # This workflow will only run when changes are pushed to the 'main' branch |
| 59 | + pull_request: |
| 60 | + branches: |
| 61 | + - main # This workflow will also run when pull requests are opened to the 'main' branch |
82 | 62 |
|
83 |
| -There is plenty of ways to undo things, feel free to have a look at [the complete list](https://github.com/blog/2019-how-to-undo-almost-anything-with-git). |
| 63 | +jobs: |
| 64 | + build: |
| 65 | + runs-on: ubuntu-latest |
84 | 66 |
|
85 |
| -## 🏅 Elaboration and Feedback |
| 67 | + steps: |
| 68 | + - uses: actions/checkout@v2 |
86 | 69 |
|
87 |
| -After the exercice, to __remember what you've just learned__, then [fill out the elaboration and feedback form](https://airtable.com/shrBuZqOJL5UeLLF1?prefill_Name=GitHub%20103&prefill_Exercice=01). |
| 70 | + - name: Run a one-line script |
| 71 | + run: echo Hello, world! |
| 72 | +``` |
0 commit comments