Skip to content

Commit

Permalink
Merge pull request #345 from una-auxme/343-bug-github-actions-not-wor…
Browse files Browse the repository at this point in the history
…king

Reworked structure & added test build to PRs
  • Loading branch information
JulianTrommer authored Oct 23, 2024
2 parents 18820f1 + 23fe7f4 commit 96451c4
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 50 deletions.
23 changes: 19 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
name: Build and push image

on:
workflow_run:
workflows: ["Check code format"]
types:
- completed
pull_request:
branches:
- "main"
push:
branches:
- main
Expand Down Expand Up @@ -43,8 +42,24 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Test build
if: github.event_name == 'pull_request'
uses: docker/build-push-action@v3
with:
context: .
file: ./build/docker/agent/Dockerfile
load: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}:test
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
USERNAME=paf
USER_UID=1000
USER_GID=1000
- name: Build and push Docker image
id: build
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v3
with:
context: .
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/drive.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
env:
AGENT_VERSION: latest
COMPOSE_FILE: ./build/docker-compose.cicd.yaml
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand All @@ -29,7 +30,6 @@ jobs:
run: docker compose down -v
# add rendered JSON as comment to the pull request
- name: Add simulation results as comment
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
name: Check code format

on:
workflow_run:
workflows: ["Linter markdown and code"]
types:
- completed
pull_request:
branches:
- "main"
push:
branches:
- main

jobs:
format:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
pull_request:
branches:
- "main"
push:
branches:
- main

jobs:
linter:
Expand Down
40 changes: 12 additions & 28 deletions doc/development/build_action.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@

**Summary:** This page explains the GitHub build action we use to create an executable image of our work.

- [GitHub actions](#github-actions)
- [General](#general)
- [The Dockerfile (`build/docker/build/Dockerfile`)](#the-dockerfile-builddockerbuilddockerfile)
- [The `build-and-push-image` job](#the-build-and-push-image-job)
- [1. Checkout repository (`actions/checkout@v3`)](#1-checkout-repository-actionscheckoutv3)
- [2. Set up Docker Buildx (`docker/setup-buildx-action@v2`)](#2-set-up-docker-buildx-dockersetup-buildx-actionv2)
- [3. Log in to the Container registry (`docker/login-action@v2`)](#3-log-in-to-the-container-registry-dockerlogin-actionv2)
- [4. Bump version and push tag (`mathieudutour/github-tag-action`)](#4-bump-version-and-push-tag-mathieudutourgithub-tag-action)
- [5. Get commit hash](#5-get-commit-hash)
- [6. Build and push Docker image](#6-build-and-push-docker-image)
- [General](#general)
- [The `build-and-push-image` job](#the-build-and-push-image-job)
- [1. Checkout repository (`actions/checkout@v3`)](#1-checkout-repository-actionscheckoutv3)
- [2. Set up Docker Buildx (`docker/setup-buildx-action@v2`)](#2-set-up-docker-buildx-dockersetup-buildx-actionv2)
- [3. Log in to the Container registry (`docker/login-action@v2`)](#3-log-in-to-the-container-registry-dockerlogin-actionv2)
- [4. Test building the image (`docker/build-push-action@v3`)](#4-test-building-the-image-dockerbuild-push-actionv3)
- [5. Build and push the image (`docker/build-push-action@v3`)](#5-build-and-push-the-image-dockerbuild-push-actionv3)

## General

Expand All @@ -27,12 +24,6 @@ or `docker pull ghcr.io/una-auxme/paf:<version>` to get a specific version.
If action is triggered by a pull request the created image is then used to execute a test run in the leaderboard, using
the devtest routes. The results of this simulation are then added as a comment to the pull request.

## The Dockerfile ([`build/docker/build/Dockerfile`](../../build/docker/build/Dockerfile))

The Dockerfile uses [Dockerfile+](https://github.com/edrevo/dockerfile-plus) to include
the [agent Dockerfile](../../build/docker/agent/Dockerfile) to avoid duplicate code.
The code folder is then copied into the container instead of mounting it as in our dev setup.

## The `build-and-push-image` job

### 1. Checkout repository ([`actions/checkout@v3`](https://github.com/actions/checkout))
Expand All @@ -52,20 +43,13 @@ Logs in with `GITHUB_TOKEN` into the registry (ghcr.io).

Example taken from [here](https://docs.github.com/en/actions/publishing-packages/publishing-docker-images)

### 4. Bump version and push tag ([`mathieudutour/github-tag-action`](https://github.com/mathieudutour/github-tag-action))

If the current commit is on the `main` branch, this action bumps the version and pushes a new tag to the repo.

Major releases can be done manually (e.g. `git tag v1.0.0`).

### 5. Get commit hash
### 4. Test building the image ([`docker/build-push-action@v3`](https://github.com/docker/build-push-action/))

If Step 4 was skipped, this step gets the commit hash of the current commit, to be used as a tag for the Docker image.
Tries to build the image without pushing it to the repository packages if the workflow was triggered with a pull request.

### 6. Build and push Docker image
### 5. Build and push the image ([`docker/build-push-action@v3`](https://github.com/docker/build-push-action/))

Build and push the image to the registry. To avoid large downloads of the base image
This action builds the image and pushes it to repository under the `latest` tag if the workflow was triggered with a merge to the `main` branch.
To avoid large downloads of the base image
the [GitHub Actions cache](https://docs.docker.com/build/building/cache/backends/gha/)
is used to cache the image after build.
If the action is run on a branch other than `main`, the image is tagged with the commit hash from Step 5.
Otherwise, the image is tagged with both the tag created in Step 4 and `latest`.
21 changes: 8 additions & 13 deletions doc/development/linter_action.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,24 @@

**Summary:** This page explains the GitHub lint action we use to unsure Code quality.

- [GitHub actions](#github-actions)
- [General](#general)
- [Pull requests](#pull-requests)
- [🚨 Common Problems](#-common-problems)
- [1. Error in the markdown linter](#1-error-in-the-markdown-linter)
- [2. Error in the python linter](#2-error-in-the-python-linter)
- [General](#general)
- [Pull requests](#pull-requests)
- [🚨 Common Problems](#-common-problems)
- [1. Error in the markdown linter](#1-error-in-the-markdown-linter)
- [2. Error in the python linter](#2-error-in-the-python-linter)

## General

We use a GitHub action to verify code quality.
These actions are defined in `.github/workflows/linter.yml` and `.github/workflows/format.yml`.

The actions are executed only on pull requests in order not to exceed the [minutes per month included in the Github](https://docs.github.com/en/billing/managing-billing-for-github-actions/about-billing-for-github-actions) free plan.
This is done by limiting the execution of the action by the following line:

```yaml
on: pull_request
```
The actions are executed on pull requests and on merges to the main branch.
This should not lead to issues regarding the [GitHub billing plan](https://docs.github.com/en/billing/managing-billing-for-github-actions/about-billing-for-github-actions). If any issues are encountered the linter action can also be run on the self-host runner.

The actions use the same linters described in the section [Linting](./linting.md).

Event though the linters are already active during development,
the execution on pull request ensures that nobody skips the linter during commit.
the execution ensures that nobody skips the linter during commit.

## Pull requests

Expand Down

0 comments on commit 96451c4

Please sign in to comment.