diff --git a/labs/build-app.md b/labs/build-app.md new file mode 100644 index 00000000..def2085d --- /dev/null +++ b/labs/build-app.md @@ -0,0 +1,108 @@ +## Building the application + +Github Actions is configured through the [YAML files](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions). + +:bulb: The trickiest part of writing the configuration files is typically getting the indentation right. + +### learning goals + +- Understand the basic structure of a workflow file +- Understand the basic structure of a job +- Understand the basic structure of a step + +## Building a CI pipeline in GitHub Actions + +In this workshop we will be using a small java service which uses Gradle to build the application. + +The application is found in the `app` directory, though the details of the implementation are not interesting for the purposes of these katas. +There are a number of shell scripts that help with building the application, these are located in the `ci` directory. + +The purpose of these katas is to use the small java application to exemplify how to use Github Actions to build, test and package your applications. + +We ultimately want a pipeline that has the following jobs: + +- **Build and test:** Clones down and run the gradle build command found in [ci/build-app.sh](../ci/build-app.sh), and thereafter runs the gradle test command found in [ci/unit-test-app.sh](../ci/unit-test-app.sh) +- **Build docker:** runs both [building of the docker image](../ci/build-docker.sh), and [pushes it up to the hub](../ci/push-docker.sh) +- **Component test:** runs a [docker-compose file](../component-test/docker-compose.yml) with a [python test](../component-test/test_app.py) to test the application. +- **Performance test:** runs a [docker-compose file](../performance-test/docker-compose.yml) with a [k6 performance tester](../performance-test/single-request.js) to test the application. + +We are not going to do it all in one go, but rather step by step. + +### A basic example: + +Now we want to diver a bit more into a pipeline. + +Examine the following example, that makes the agent running the pipeline echo out "hello world": + + +```yaml +name: Main workflow +on: push +jobs: + Build: + runs-on: ubuntu-latest + container: gradle:6-jdk11 + steps: + - name: Clone-down + uses: actions/checkout@v4 + - run: chmod +x ci/build-app.sh && ci/build-app.sh +``` + +A line-by-line explanation of the above: + +- **Line 1**: Specifies the name of the workflow, in this case, "Main workflow". +- **Line 2**: Specifies that the workflow should be triggered on a `push` event. +- **Line 3**: Introduces the `jobs` section where all job definitions reside. +- **Line 4-5**: Defines a job named `Build` that runs on an Ubuntu VM. +- **Line 6**: Specifies that the job should run in a container with the image `gradle:6-jdk11`. +- **Line 7**: Defines the steps that should be executed in the job. +- **Line 8-9**: Checks out the repository's content to the runner, enabling subsequent steps to access it. +- **Line 10**: Runs the `build-app.sh` script. + + +This workflow is a basic example that provides insights into the event type, branch reference, and repository structure when code is pushed to it. + +## Task + +- Replase the workflow you created in `.github/workflows/main.yml` with the above example. +- Add and commit the file and push it to Github. + +
+:bulb: Git commands to do it if you are using the terminal + +```bash +git add .github/workflows/hello-world.yml +git commit -m "Add hello world workflow" +git push + +``` + +
+ +- Go to Github Actions tab of the repository and check the action status. + +## Results + +You should see something like this in the logs of Github Actions: + +```bash +#!/bin/sh -eo pipefail +echo 'Hello World!' + +Hello World! +``` + +**Manually triggering the workflow** + +You can also trigger the workflow manually by clicking the `Run workflow` button. + +![run-workflow](img/run-workflow.png) + +- Click on the `Run workflow` button and click `Run workflow` again in the popup. +- Go to the `Actions` tab and see the workflow running again, this time with the `workflow_dispatch` event. + + +## Summary +Congratulations! + +You have successfully created the first Github Actions workflow, and ran it successfully :tada:. diff --git a/labs/hello-world-pipeline.md b/labs/hello-world-pipeline.md deleted file mode 100644 index 3d541f58..00000000 --- a/labs/hello-world-pipeline.md +++ /dev/null @@ -1,96 +0,0 @@ -## Making your first "hello world" pipeline - -Github Actions is configured through the [YAML files](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions). - -:bulb: The trickiest part of writing the configuration files is typically getting the indentation right. - -### learning goals - -- Understand the basic structure of a workflow file -- Understand the basic structure of a job -- Understand the basic structure of a step - -### A basic example: - -Now we want to diver a bit more into a pipeline. - -Examine the following example, that makes the agent running the pipeline echo out "hello world": - - -```yaml -name: Hello world workflow -on: - push: - workflow_dispatch: -jobs: - my-job: - 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@v4 - - - name: List files in the repository - run: | - echo "The repository ${{ github.repository }} contains the following files:" - tree -``` - -A line-by-line explanation of the above: - -- **Line 1**: Specifies the name of the workflow, in this case, "Hello world workflow". -- **Line 2-4**: The workflow is triggered by a `push` event or a manual trigger. -- **Line 5**: Introduces the `jobs` section where all job definitions reside. -- **Line 6-7**: Defines a job named `my-job` that runs on an Ubuntu VM. -- **Line 8-11**: First step in `my-job` prints out the event that triggered the workflow and the reference of the branch using `github.event_name` and `github.ref`. -- **Line 13**: Checks out the repository's content to the runner, enabling subsequent steps to access it. -- **Line 15-18**: Lists and displays the directory structure of the checked-out repository using the `tree` command. - -This workflow is a basic example that provides insights into the event type, branch reference, and repository structure when code is pushed to it. - -## Task - -- Replase the workflow you created in `.github/workflows/main.yml` with the above example. -- Add and commit the file and push it to Github. - -
-:bulb: Git commands to do it if you are using the terminal - -```bash -git add .github/workflows/hello-world.yml -git commit -m "Add hello world workflow" -git push - -``` - -
- -- Go to Github Actions tab of the repository and check the action status. - -## Results - -You should see something like this in the logs of Github Actions: (Note: The logs can be a bit hard to find the first time, but give it a shot) - -```bash -#!/bin/sh -eo pipefail -echo 'Hello World!' - -Hello World! -``` - -**Manually triggering the workflow** - -You can also trigger the workflow manually by clicking the `Run workflow` button. - -![run-workflow](img/run-workflow.png) - -- Click on the `Run workflow` button and click `Run workflow` again in the popup. -- Go to the `Actions` tab and see the workflow running again, this time with the `workflow_dispatch` event. - - -## Summary -Congratulations! - -You have successfully created the first Github Actions workflow, and ran it successfully :tada:. diff --git a/labs/setup.md b/labs/setup.md index 75901b53..59f3cfec 100644 --- a/labs/setup.md +++ b/labs/setup.md @@ -5,25 +5,8 @@ This series of katas will go through the basic steps in github actions, making y ## Learning Goals - Creating an instance of the template repository -- Creating a workflow file +- Creating a workflow file seeing Github Actions in action -## Building a CI pipeline in GitHub Actions - -In this workshop we will be using a small java service which uses Gradle to build the application. - -The application is found in the `app` directory, though the details of the implementation are not interesting for the purposes of these katas. -There are a number of shell scripts that help with building the application, these are located in the `ci` directory. - -The purpose of these katas is to use the small java application to exemplify how to use Github Actions to build, test and package your applications. - -We ultimately want a pipeline that has the following jobs: - -- **Build and test:** Clones down and run the gradle build command found in [ci/build-app.sh](../ci/build-app.sh), and thereafter runs the gradle test command found in [ci/unit-test-app.sh](../ci/unit-test-app.sh) -- **Build docker:** runs both [building of the docker image](../ci/build-docker.sh), and [pushes it up to the hub](../ci/push-docker.sh) -- **Component test:** runs a [docker-compose file](../component-test/docker-compose.yml) with a [python test](../component-test/test_app.py) to test the application. -- **Performance test:** runs a [docker-compose file](../performance-test/docker-compose.yml) with a [k6 performance tester](../performance-test/single-request.js) to test the application. - -We are not going to do it all in one go, but rather step by step. ## Exercise ### Overview diff --git a/trainer/.github/workflows/build-app.yaml b/trainer/.github/workflows/build-app.yaml new file mode 100644 index 00000000..884ab405 --- /dev/null +++ b/trainer/.github/workflows/build-app.yaml @@ -0,0 +1,10 @@ +name: Main workflow +on: push +jobs: + Build: + runs-on: ubuntu-latest + container: gradle:6-jdk11 + steps: + - name: Clone-down + uses: actions/checkout@v4 + - run: ci/build-app.sh \ No newline at end of file