GitHub Actions in CodeBuild

GitHub Actions in CodeBuild

This month AWS released support for GitHub Actions in CodeBuild.

https://aws.amazon.com/about-aws/whats-new/2023/07/aws-codebuild-github-actions

I'm not sure how useful this is going to be so in this post I'll explore how we can use existing GitHub Actions such as the Super-Linter via CodeBuild.

Setup

Create a new project and give it a meaningful name in the CodeBuild UI.

CodeBuild Project

Next, establish authorization for CodeBuild to access your GitHub account.

Connect GitHub

  • Select GitHub as the Source Provider, and click on Connect to GitHub

Authorise CodeBuild

The above popup window will show and prompt you to authorize the necessary access for CodeBuild within GitHub. To accept, click Authorise aws-codesuite.

This process creates the following GitHub App under your account, which can be viewed via Settings / Applications / Authorised OAuth Apps.

GitHub App

With the access now configured, I can select a source repo from my GitHub Account. For example, I'm using [sjramblings/codebuild-github-actions which contains a simple README file.

GitHub Repo

For the Environment settings, we select Ubuntu and use the latest available image. As the SuperLinter requires the use of Docker so as noted in the AWS Doco, we need to ensure Privileged mode is enabled.

Environment Settings

Environment Settings

Our buildspec file is going to contain the references to the GitHub Action so insert the following commands.

version: 0.2
phases:
  pre_build:
    steps:
      - name: Lint Code Base
        uses: super-linter/super-linter@v5
        env:
          VALIDATE_ALL_CODEBASE: 'true'
          DEFAULT_BRANCH: main
  build:
    commands:
      - echo "Do something else..."

NOTE: The official documentation contains an error as it should be pre_build not pre-build.

Now the project configuration is complete.

Running a build

In the CodeBuild console, start a build for the new project.

Start Build

From the following output our CodeBuild container appears to install the GitHub Actions agent [Container] 2023/07/14 13:07:23 Current runner version: '2.304.0' and then proceed to perform the actions located in the action.yml file for the Superlinter.

[Container] 2023/07/14 13:07:11 Waiting for agent ping
[Container] 2023/07/14 13:07:12 Waiting for DOWNLOAD_SOURCE
[Container] 2023/07/14 13:07:14 Phase is DOWNLOAD_SOURCE
[Container] 2023/07/14 13:07:14 CODEBUILD_SRC_DIR=/codebuild/output/src287353195/src/github.com/sjramblings/codebuild-github-actions
[Container] 2023/07/14 13:07:14 YAML location is /codebuild/readonly/buildspec.yml
[Container] 2023/07/14 13:07:14 No commands found for phase name: pre_build
[Container] 2023/07/14 13:07:15 Downloading Action Runner
[Container] 2023/07/14 13:07:21 Setting HTTP client timeout to higher timeout for Github and GitHub Enterprise sources
[Container] 2023/07/14 13:07:21 Processing environment variables
[Container] 2023/07/14 13:07:21 No runtime version selected in buildspec.
[Container] 2023/07/14 13:07:21 Moving to directory /codebuild/output/src287353195/src/github.com/sjramblings/codebuild-github-actions
[Container] 2023/07/14 13:07:21 Configuring ssm agent with target id: codebuild:b6077838-228e-4ce8-9f68-b1e9f7d4ee1c
[Container] 2023/07/14 13:07:21 Successfully updated ssm agent configuration
[Container] 2023/07/14 13:07:21 Registering with agent
[Container] 2023/07/14 13:07:21 Phases found in YAML: 2
[Container] 2023/07/14 13:07:21  PRE_BUILD: 1 steps
[Container] 2023/07/14 13:07:21  BUILD: 1 commands
[Container] 2023/07/14 13:07:21 Phase complete: DOWNLOAD_SOURCE State: SUCCEEDED
[Container] 2023/07/14 13:07:21 Phase context status code:  Message: 
[Container] 2023/07/14 13:07:21 Entering phase INSTALL
[Container] 2023/07/14 13:07:21 Phase complete: INSTALL State: SUCCEEDED
[Container] 2023/07/14 13:07:21 Phase context status code:  Message: 
[Container] 2023/07/14 13:07:21 Entering phase PRE_BUILD
[Container] 2023/07/14 13:07:21 Preparing action command
[Container] 2023/07/14 13:07:23 Current runner version: '2.304.0'
[Container] 2023/07/14 13:07:23 Preparing the runtime environment
[Container] 2023/07/14 13:07:25 /usr/local/bin/docker pull ghcr.io/super-linter/super-linter:v5
[Container] 2023/07/14 13:07:25 v5: Pulling from super-linter/super-linter
[Container] 2023/07/14 13:07:25 31e352740f53: Pulling fs layer
[Container] 2023/07/14 13:09:00 f97af9b7fcce: Pull complete
[Container] 2023/07/14 13:09:00 Digest: sha256:ba107c9a2909197afae6a6e62c8c9bc1f406a30105279ea3061d11ded94b7a95
[Container] 2023/07/14 13:09:00 Status: Downloaded newer image for ghcr.io/super-linter/super-linter:v5
[Container] 2023/07/14 13:09:00 ghcr.io/super-linter/super-linter:v5
[Container] 2023/07/14 13:09:00 Run super-linter/super-linter@v5
[Container] 2023/07/14 13:09:00 env:
[Container] 2023/07/14 13:09:00   DEFAULT_BRANCH: main
[Container] 2023/07/14 13:09:00   VALIDATE_ALL_CODEBASE: true
[Container] 2023/07/14 13:09:00 /usr/local/bin/docker run --name ghcriosuperlintersuperlinterv5_771769 --label 1f8c8b --workdir /github/workspace --rm -e "DEFAULT_BRANCH" -e "VALIDATE_ALL_CODEBASE" -e "HOME" -e "GITHUB_JOB" -e "GITHUB_EVENT_NAME" -e "GITHUB_REF" -e "GITHUB_SHA" -e "GITHUB_REPOSITORY" -e "GITHUB_REPOSITORY_OWNER" -e "GITHUB_RUN_ID" -e "GITHUB_RUN_NUMBER" -e "GITHUB_ACTOR" -e "GITHUB_WORKFLOW" -e "GITHUB_HEAD_REF" -e "GITHUB_BASE_REF" -e "GITHUB_WORKSPACE" -e "GITHUB_ACTION" -e "GITHUB_EVENT_PATH" -e "GITHUB_ACTION_REPOSITORY" -e "GITHUB_ACTION_REF" -e "GITHUB_PATH" -e "GITHUB_ENV" -e "GITHUB_STEP_SUMMARY" -e "GITHUB_STATE" -e "GITHUB_OUTPUT" -e "RUNNER_OS" -e "RUNNER_TOOL_CACHE" -e "RUNNER_TEMP" -e "RUNNER_WORKSPACE" -e GITHUB_ACTIONS=true -e AWS_CONTAINER_CREDENTIALS_FULL_URI -e AWS_CONTAINER_CREDENTIALS_RELATIVE_URI -e AWS_REGION -e CI=true --network host -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/codebuild/readonly/action-runner/_layout/_work/_temp/_github_home":"/github/home" -v "/codebuild/readonly/action-runner/_layout/_work/_temp/_github_workflow":"/github/workflow" -v "/codebuild/readonly/action-runner/_layout/_work/_temp/_runner_file_commands":"/github/file_commands" -v "/codebuild/readonly/action-runner/_layout/_work/codebuild-github-actions.git/codebuild-github-actions.git":"/github/workspace" ghcr.io/super-linter/super-linter:v5
[Container] 2023/07/14 13:09:01 --------------------------------------------------------------------------------
[Container] 2023/07/14 13:09:01 
[Container] 2023/07/14 13:09:01                               /@@#///////@@/(@//@%/(@.@(       @@
[Container] 2023/07/14 13:09:01                           @@//////////////////////////////#*  @@@
[Container] 2023/07/14 13:09:01                         @////@//(///////////@@@@@///@//@/@**//@@(
[Container] 2023/07/14 13:09:01                       @///////@///////////////@@@@    (           @,
[Container] 2023/07/14 13:09:01                      @/(&/@////////////////////                     @
[Container] 2023/07/14 13:09:01                     @////////////////////////@@                      @
[Container] 2023/07/14 13:09:01                   @%////////(//////////%/////&@            @@       *,@           ______________
[Container] 2023/07/14 13:09:01              @@@@@/@/#/////(&//////////////////                       .@         /              \
[Container] 2023/07/14 13:09:01         *@@@@@.    .%///(//@//////////////////&.   .@@,                 @%      / Don't mind me  \
[Container] 2023/07/14 13:09:01       @@%           .&@&&/@.@//&/////(//////////    @@@@@@@@@         .. &@    / I'm just looking \
[Container] 2023/07/14 13:09:01     @@%               @@@@@   @&/////////////////#   @/       V  @@/ ,@@@ @   <  for some trash... |
[Container] 2023/07/14 13:09:01 @@@%                   @@@@        .%@@@@//////#@ @   @@         @     .,.     \__________________/
[Container] 2023/07/14 13:09:01                                           @@@/@(  (@@@@% @/\      %
[Container] 2023/07/14 13:09:01                                            @@@@(    .     .@@/\   #
[Container] 2023/07/14 13:09:01                                              @                  %@%
[Container] 2023/07/14 13:09:01 
[Container] 2023/07/14 13:09:01 --------------------------------------------------------------------------------
[Container] 2023/07/14 13:09:01 2023-07-14 13:09:01 [INFO]   ---------------------------------------------
[Container] 2023/07/14 13:09:01 2023-07-14 13:09:01 [INFO]   --- GitHub Actions Multi Language Linter ----
[Container] 2023/07/14 13:09:01 2023-07-14 13:09:01 [INFO]    - Image Creation Date:[2023-07-03T19:37:45Z]
[Container] 2023/07/14 13:09:01 2023-07-14 13:09:01 [INFO]    - Image Revision:[98b9f97a88465a982d87e5a4264a87a3d3958560]
[Container] 2023/07/14 13:09:01 2023-07-14 13:09:01 [INFO]    - Image Version:[98b9f97a88465a982d87e5a4264a87a3d3958560]
[Container] 2023/07/14 13:09:01 2023-07-14 13:09:01 [INFO]   ---------------------------------------------
[Container] 2023/07/14 13:09:01 2023-07-14 13:09:01 [INFO]   ---------------------------------------------
[Container] 2023/07/14 13:09:01 2023-07-14 13:09:01 [INFO]   The Super-Linter source code can be found at:
[Container] 2023/07/14 13:09:01 2023-07-14 13:09:01 [INFO]    - https://github.com/github/super-linter
[Container] 2023/07/14 13:09:01 2023-07-14 13:09:01 [INFO]   ---------------------------------------------
[Container] 2023/07/14 13:09:01 2023-07-14 13:09:01 [INFO]   --------------------------------------------
[Container] 2023/07/14 13:09:01 2023-07-14 13:09:01 [INFO]   Gathering GitHub information...
[Container] 2023/07/14 13:09:01 2023-07-14 13:09:01 [INFO]   Successfully found:[GITHUB_SHA], value:[default]
[Container] 2023/07/14 13:09:01 2023-07-14 13:09:01 [INFO]   Successfully found:[GITHUB_WORKSPACE], value:[/github/workspace]
[Container] 2023/07/14 13:09:01 2023-07-14 13:09:01 [INFO]   Successfully found:[GITHUB_EVENT_PATH], value:[/github/workflow/event.json]
[Container] 2023/07/14 13:09:02 2023-07-14 13:09:02 [INFO]   Successfully found:[GITHUB_ORG], value:[null]
[Container] 2023/07/14 13:09:02 2023-07-14 13:09:02 [INFO]   Successfully found:[GITHUB_REPO], value:[null]
[Container] 2023/07/14 13:09:02 2023-07-14 13:09:02 [ERROR]   Failed to get [GITHUB_TOKEN]!
[Container] 2023/07/14 13:09:02 2023-07-14 13:09:02 [ERROR]   []
[Container] 2023/07/14 13:09:02 2023-07-14 13:09:02 [ERROR]   Please set a [GITHUB_TOKEN] from the main workflow environment to take advantage of multiple status reports!
[Container] 2023/07/14 13:09:02 2023-07-14 13:09:02 [INFO]   --------------------------------------------
[Container] 2023/07/14 13:09:02 2023-07-14 13:09:02 [INFO]   Gathering user validation information...
[Container] 2023/07/14 13:09:02 2023-07-14 13:09:02 [INFO]   - Validating ALL files in code base...
[Container] 2023/07/14 13:09:05 2023-07-14 13:09:05 [INFO]   ---------------------------------
[Container] 2023/07/14 13:09:05 2023-07-14 13:09:05 [INFO]   ------ File list to check: ------
[Container] 2023/07/14 13:09:05 2023-07-14 13:09:05 [INFO]   ---------------------------------
[Container] 2023/07/14 13:09:05 2023-07-14 13:09:05 [INFO]   ----------------------------------------------
[Container] 2023/07/14 13:09:05 2023-07-14 13:09:05 [INFO]   Successfully gathered list of files...
[Container] 2023/07/14 13:09:05 2023-07-14 13:09:05 [INFO]   
[Container] 2023/07/14 13:09:05 2023-07-14 13:09:05 [INFO]   ----------------------------------------------
[Container] 2023/07/14 13:09:05 2023-07-14 13:09:05 [INFO]   ----------------------------------------------
[Container] 2023/07/14 13:09:06 2023-07-14 13:09:06 [INFO]   Linting [GITLEAKS] files...
[Container] 2023/07/14 13:09:06 2023-07-14 13:09:06 [INFO]   ----------------------------------------------
[Container] 2023/07/14 13:09:06 2023-07-14 13:09:06 [INFO]   ----------------------------------------------
[Container] 2023/07/14 13:09:06 2023-07-14 13:09:06 [INFO]   ---------------------------
[Container] 2023/07/14 13:09:06 2023-07-14 13:09:06 [INFO]   File:[/github/workspace/LICENSE]
[Container] 2023/07/14 13:09:06 2023-07-14 13:09:06 [INFO]    - File:[LICENSE] was linted with [gitleaks] successfully
[Container] 2023/07/14 13:09:06 2023-07-14 13:09:06 [INFO]      - Command output:
[Container] 2023/07/14 13:09:06 ------
[Container] 2023/07/14 13:09:06 1:09PM INF scan completed in 16.6ms
[Container] 2023/07/14 13:09:06 1:09PM INF no leaks found
[Container] 2023/07/14 13:09:06 ------
[Container] 2023/07/14 13:09:06 2023-07-14 13:09:06 [INFO]   ---------------------------
[Container] 2023/07/14 13:09:06 2023-07-14 13:09:06 [INFO]   File:[/github/workspace/README.md]
[Container] 2023/07/14 13:09:06 2023-07-14 13:09:06 [INFO]    - File:[README.md] was linted with [gitleaks] successfully
[Container] 2023/07/14 13:09:06 2023-07-14 13:09:06 [INFO]      - Command output:
[Container] 2023/07/14 13:09:06 ------
[Container] 2023/07/14 13:09:06 1:09PM INF scan completed in 11.2ms
[Container] 2023/07/14 13:09:06 1:09PM INF no leaks found
[Container] 2023/07/14 13:09:06 ------
[Container] 2023/07/14 13:09:06 2023-07-14 13:09:06 [INFO]   
[Container] 2023/07/14 13:09:06 2023-07-14 13:09:06 [INFO]   ----------------------------------------------
[Container] 2023/07/14 13:09:06 2023-07-14 13:09:06 [INFO]   ----------------------------------------------
[Container] 2023/07/14 13:09:06 2023-07-14 13:09:06 [INFO]   Linting [JSCPD] files...
[Container] 2023/07/14 13:09:06 2023-07-14 13:09:06 [INFO]   ----------------------------------------------
[Container] 2023/07/14 13:09:06 2023-07-14 13:09:06 [INFO]   ----------------------------------------------
[Container] 2023/07/14 13:09:06 2023-07-14 13:09:06 [INFO]   ---------------------------
[Container] 2023/07/14 13:09:06 2023-07-14 13:09:06 [INFO]   File:[/github/workspace/LICENSE]
[Container] 2023/07/14 13:09:07 2023-07-14 13:09:07 [INFO]    - File:[LICENSE] was linted with [jscpd] successfully
[Container] 2023/07/14 13:09:07 2023-07-14 13:09:07 [INFO]      - Command output:
[Container] 2023/07/14 13:09:07 ------
[Container] 2023/07/14 13:09:07 Detection time:: 0.73ms
[Container] 2023/07/14 13:09:07 ------
[Container] 2023/07/14 13:09:07 2023-07-14 13:09:07 [INFO]   ---------------------------
[Container] 2023/07/14 13:09:07 2023-07-14 13:09:07 [INFO]   File:[/github/workspace/README.md]
[Container] 2023/07/14 13:09:08 2023-07-14 13:09:08 [INFO]    - File:[README.md] was linted with [jscpd] successfully
[Container] 2023/07/14 13:09:08 2023-07-14 13:09:08 [INFO]      - Command output:
[Container] 2023/07/14 13:09:08 ------
[Container] 2023/07/14 13:09:08 Detection time:: 0.737ms
[Container] 2023/07/14 13:09:08 ------
[Container] 2023/07/14 13:09:08 2023-07-14 13:09:08 [INFO]   
[Container] 2023/07/14 13:09:08 2023-07-14 13:09:08 [INFO]   ----------------------------------------------
[Container] 2023/07/14 13:09:08 2023-07-14 13:09:08 [INFO]   ----------------------------------------------
[Container] 2023/07/14 13:09:08 2023-07-14 13:09:08 [INFO]   Linting [MARKDOWN] files...
[Container] 2023/07/14 13:09:08 2023-07-14 13:09:08 [INFO]   ----------------------------------------------
[Container] 2023/07/14 13:09:08 2023-07-14 13:09:08 [INFO]   ----------------------------------------------
[Container] 2023/07/14 13:09:08 2023-07-14 13:09:08 [INFO]   ---------------------------
[Container] 2023/07/14 13:09:08 2023-07-14 13:09:08 [INFO]   File:[/github/workspace/README.md]
[Container] 2023/07/14 13:09:08 2023-07-14 13:09:08 [INFO]    - File:[README.md] was linted with [markdownlint] successfully
[Container] 2023/07/14 13:09:08 2023-07-14 13:09:08 [INFO]   
[Container] 2023/07/14 13:09:08 2023-07-14 13:09:08 [INFO]   ----------------------------------------------
[Container] 2023/07/14 13:09:08 2023-07-14 13:09:08 [INFO]   ----------------------------------------------
[Container] 2023/07/14 13:09:08 2023-07-14 13:09:08 [INFO]   Linting [NATURAL_LANGUAGE] files...
[Container] 2023/07/14 13:09:08 2023-07-14 13:09:08 [INFO]   ----------------------------------------------
[Container] 2023/07/14 13:09:08 2023-07-14 13:09:08 [INFO]   ----------------------------------------------
[Container] 2023/07/14 13:09:08 2023-07-14 13:09:08 [INFO]   ---------------------------
[Container] 2023/07/14 13:09:08 2023-07-14 13:09:08 [INFO]   File:[/github/workspace/LICENSE]
[Container] 2023/07/14 13:09:09 2023-07-14 13:09:09 [INFO]    - File:[LICENSE] was linted with [textlint] successfully
[Container] 2023/07/14 13:09:09 2023-07-14 13:09:09 [INFO]   ---------------------------
[Container] 2023/07/14 13:09:09 2023-07-14 13:09:09 [INFO]   File:[/github/workspace/README.md]
[Container] 2023/07/14 13:09:09 2023-07-14 13:09:09 [INFO]    - File:[README.md] was linted with [textlint] successfully
[Container] 2023/07/14 13:09:10 2023-07-14 13:09:10 [INFO]   ----------------------------------------------
[Container] 2023/07/14 13:09:10 2023-07-14 13:09:10 [INFO]   ----------------------------------------------
[Container] 2023/07/14 13:09:10 2023-07-14 13:09:10 [INFO]   The script has completed
[Container] 2023/07/14 13:09:10 2023-07-14 13:09:10 [INFO]   ----------------------------------------------
[Container] 2023/07/14 13:09:10 2023-07-14 13:09:10 [INFO]   ----------------------------------------------
[Container] 2023/07/14 13:09:10 2023-07-14 13:09:10 [NOTICE]   All file(s) linted successfully with no errors detected
[Container] 2023/07/14 13:09:10 2023-07-14 13:09:10 [INFO]   ----------------------------------------------

[Container] 2023/07/14 13:09:10 Phase complete: PRE_BUILD State: SUCCEEDED
[Container] 2023/07/14 13:09:10 Phase context status code:  Message: 
[Container] 2023/07/14 13:09:10 Entering phase BUILD
[Container] 2023/07/14 13:09:10 Running command echo "Do something else..."
Do something else...

[Container] 2023/07/14 13:09:10 Phase complete: BUILD State: SUCCEEDED
[Container] 2023/07/14 13:09:10 Phase context status code:  Message: 
[Container] 2023/07/14 13:09:10 Entering phase POST_BUILD
[Container] 2023/07/14 13:09:10 Phase complete: POST_BUILD State: SUCCEEDED
[Container] 2023/07/14 13:09:10 Phase context status code:  Message:

Summary

This post showed how to use the GitHub Actions integration within AWS CodeBuild.

I'm not sure if this feature is going to get used much as there are some significant limitations as listed in the offical documentation. However, it is good to see AWS trying to integrate more as GitHub Actions is killing it at the moment IMO.

I feel a better way for this integration is to use one of the following open-source projects.

Hope this helps someone else!

Cheers

Photo by Brecht Corbeel on Unsplash

Did you find this article valuable?

Support Stephen Jones by becoming a sponsor. Any amount is appreciated!