Skip to content

Commit

Permalink
Merge pull request #91 from MCR-Digital/migrate_to_github_actions
Browse files Browse the repository at this point in the history
Migrate to GitHub actions
  • Loading branch information
alectunbridge authored Jan 25, 2023
2 parents 803bf96 + 9f99ab9 commit 9adb3d7
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 120 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Two–three mentors required in addition to leads. These should be able to cover

Exercises (katas and code starters) will need to be ported to required languages.

Mentors should be comfortable with branching, feature toggles, setting up Travis for their chosen language.
Mentors should be comfortable with branching, feature toggles, setting up GitHub Actions for their chosen language.

## Prep-work for apprentices

Expand Down Expand Up @@ -84,7 +84,7 @@ The slides can be viewed from the link at the top of the repository. Hit ‘`?`

## Exercises

* Setting up Travis CI, changing tax_calculator & watching Travis fail/pass
* Setting up GitHub Actions CI, changing tax_calculator & watching GitHub Actions fail/pass
* Changing tax_calculator using feature branches
* Changing tax_calculator using trunk development and feature toggles
* Git: reset
Expand All @@ -98,7 +98,7 @@ The slides can be viewed from the link at the top of the repository. Hit ‘`?`
* Continuous Integration
* What it is and why we do it
* Examples of different CI systems
* Exercise: add Travis to fork of existing repo
* Exercise: add GitHub Actions to fork of existing repo
* Exercise: Make change to their fork and show (hopefully) successful build
* Continuous Delivery/Deployment
* What it is and why we do it
Expand Down
86 changes: 13 additions & 73 deletions docs/_posts/0000-02-03-how-to-do-ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Note: Some tests are unreliable—might fail 1% of the time.
* GoCD
* Jenkins
* TravisCI
* GitHub Actions (new)
* GitHub Actions

Note: Enterprises tend to favour on site code and CI buy moving towards cloud hosted solutions.

Expand All @@ -66,103 +66,43 @@ Note: Enterprises tend to favour on site code and CI buy moving towards cloud ho

---

## Upcoming Travis CI exercise
## Upcoming GitHub Actions CI exercise

+ Not expecting you to have used Travis CI
+ Not expecting you to have used GitHub Actions
+ Using it today in an exercise as an example
+ Partly as it is so easy to set up
+ Partly as it is easy to set up
+ We don’t use it other than this boot camp

--

## E.g. Travis CI
## E.g. GitHub Actions CI

+ Authorise Travis CI to use your github.com account
+ Activate Travis CI with your repository
+ Add a `.travis.yml` file to your repository
+ Add a YAML config file to your repository
+ Optional: add build badge to the repository

Note: GitHub Actions is the same, and you don’t even have to leave GitHub!

--

## Then…

+ GitHub tells Travis CI each time there is something to fetch and build
+ Travis fetches that version of the code
+ Travis works out what to run based on repository contents (including `.travis.yml`)
+ Travis reports status back to GitHub to mark commits with success/failure
+ Every time a commit is made
+ GitHub fetches that version of the code
+ GitHub works out what to run based on repository contents (including the YAML config)

--

## Build status

Status appears against each commit and PR.

<img src=images/travis-build-status.png>

--

## Configuring Travis

* Contents of `.travis.yml` tells Travis what to do
* Specific to each language… e.g.

```yaml
language: java
```
Note: Travis looks at repo to work out how to build once it knows language.
One line is enough to build and validate your Java.
<img src=images/github-actions-build-status.png>

--

## Travis vs GitHub Actions
Travis:
```yaml
language: node_js
before_script: "cd exercises/javascript"
node_js:
- 10
```
<!-- .element: style="font-size: 35%" -->
GitHub Actions:
```yaml
name: Node CI

on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Read .nvmrc
run: echo ::set-output name=NVMRC::$(cat .nvmrc)
id: nvm
working-directory: exercises/javascript
- name: Setup node
uses: actions/setup-node@v1
with:
node-version: '${{ steps.nvm.outputs.NVMRC }}'
- name: npm install, build, and test
run: |
npm ci
npm test
working-directory: exercises/javascript
env:
CI: true
```
## Configuring GitHub Actions

<!-- .element: style="font-size: 25%" -->
* Contents of a YAML file tell GitHub what to do
* Specific to each language…

Notes: GitHub Actions is more verbose but seems more extensible

---

Expand Down
99 changes: 56 additions & 43 deletions docs/_posts/0000-02-04-ci-exercise.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,74 +7,87 @@ Note: explain difference between forking and using a template.

--

## Exercise Part 1: Set up Travis CI

* Work in pairs
* Log into https://travis-ci.com with your GitHub account
* [Activate your repositories](https://app.travis-ci.com/account/repositories)
* You may need to confirm your Travis account in your email
* Check that you can see your repository in the list
* Activate Travis CI for your fork
* Subscribe to the free trial

Note:
You’ll be asked to authorise a Travis app
You can limit the repositories it has access to
## Exercise Part 1: Set up GitHub Actions

* Look at your fork of the repo at https://github.com
* Select the 'Actions' tab
* Click the 'New workflow' button
* Find the right workflow for your language (ask if you're not sure)
* Click the 'Configure' button
* You should see an online editor with a default YAML file loaded

Note:
Share the exercise slide!

--

## Exercise Part 2: Configure your build

* On GitHub, create `.travis.yml` at root of repo
* The only configuration you should need to change is your build's working directory
* Hopefully see your tests pass

--

Java / Kotlin
```yaml
language: java
before_script: "cd exercises/java"
- name: Build with Gradle
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
with:
arguments: build
build-root-directory: exercises/java
```
<!-- .element: style="font-size: 35%" -->
--
C#
```yaml
language: csharp
solution: exercises/dotnet/TaxCalculator.sln
before_script: "cd exercises/dotnet"
mono: none
dotnet: "2.1.502"
script:
- "dotnet restore"
- "dotnet test"
defaults:
run:
working-directory: exercises/dotnet

jobs:
...
```
<!-- .element: style="font-size: 35%" -->
--
PHP
```yaml
language: node_js
before_install: "cd exercises/javascript"
node_js:
- 10
defaults:
run:
working-directory: exercises/php

jobs:
...
- name: Run test suite
run: ./vendor/bin/phpunit --testdox tests
```
<!-- .element: style="font-size: 35%" -->
--
Javascript / Typescript
```yaml
language: python
before_script: "cd exercises/python"
python:
- "3.6"
script:
- pytest
defaults:
run:
working-directory: exercises/typescript

jobs:
...
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: 'exercises/typescript/package-lock.json'
```
<!-- .element: style="font-size: 35%" -->
Note: Remind them about the dot at the front of the filename!
Don’t share the travis code over chat etc, as whitespace can get stripped.
Share the exercise slide!
--
## Exercise Part 3: Make it fail
* Pull down the changes (`.travis.yml`) you just made on GitHub
* Pull down the changes (the YAML config) you just made on GitHub
* Find the tests which aren't running (the ones for petrol vehicles)
* Make the tests run (and fail)
* Push your change
Expand Down
2 changes: 1 addition & 1 deletion docs/_posts/0000-04-02-branching-exercise.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ git remote set-url origin https://github.com/[USER]/apprentice-boot-camp-fundame
* Both add to your TaxCalculator implementation with regular commits, ___***BOTH CHANGE THE SAME FILE***___
* Merge branches back to master one by one
* Use a GitHub PR or merge on the command line
* Check Travis after each push
* Check GitHub Actions after each push

Notes:
See branch ```petrol_tax``` for a starting point to this exercise if they haven't completed the previous one.
Expand Down
Binary file added docs/images/github-actions-build-status.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/travis-build-status.png
Binary file not shown.

0 comments on commit 9adb3d7

Please sign in to comment.