-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add build-app.yaml workflow and update setup.md
- Loading branch information
1 parent
514e7b4
commit 52c9d78
Showing
4 changed files
with
119 additions
and
114 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,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. | ||
|
||
<details> | ||
<summary>:bulb: Git commands to do it if you are using the terminal</summary> | ||
|
||
```bash | ||
git add .github/workflows/hello-world.yml | ||
git commit -m "Add hello world workflow" | ||
git push | ||
``` | ||
|
||
</details> | ||
|
||
- 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:. |
This file was deleted.
Oops, something went wrong.
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
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,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 |