Skip to content

Commit

Permalink
refactor: Update devcontainer image name construction in build-devcon…
Browse files Browse the repository at this point in the history
…tainer.yml
  • Loading branch information
lgersman committed Oct 10, 2024
1 parent d3f0e58 commit feac09c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
16 changes: 16 additions & 0 deletions .github/shared/devcontainer-image-name.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "devcontainer image name"
description: |
set up environment variable IMAGE_NAME containing the computed dev container image.
the dev container image name is constructed from the repository owner/name and the branch name all lowercased.
example : ghcr.io/IONOS-Wordpress/ionos-wordpress-develop-devcontainer for develop branch
runs:
using: "composite"
steps:
- name: build image name
run: |
# construct IMAGE_NAME from repo owner/name and branch
# example value : "ghcr.io/IONOS-Wordpress/ionos-wordpress-develop-devcontainer"
IMAGE_NAME="ghcr.io/${GITHUB_REPOSITORY}-${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}-devcontainer"
# convert imagename to lowercase and store as environment variable
echo "IMAGE_NAME=${IMAGE_NAME@L}" >> "${GITHUB_ENV}"
11 changes: 3 additions & 8 deletions .github/workflows/build-devcontainer.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: 'build devcontainer image'

on:
# rebuild any PRs and main branch changes
pull_request:
Expand Down Expand Up @@ -29,13 +30,7 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: build image name
run: |
# construct IMAGE_NAME from repo owner/name and branch
# example value : "ghcr.io/IONOS-Wordpress/ionos-wordpress-develop-devcontainer"
IMAGE_NAME="ghcr.io/${GITHUB_REPOSITORY}-${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}-devcontainer"
# convert imagename to lowercase and store as environment variable
echo "IMAGE_NAME=${IMAGE_NAME@L}" >> "${GITHUB_ENV}"
- uses: "./.github/shared/devcontainer-image-name.yaml"

- name: Pre-build image and run make ci-build in dev container
uses: devcontainers/ci@v0.3
Expand All @@ -46,7 +41,7 @@ jobs:
# "push" is already the default
# eventFilterForPush: push

# name of the pushed image (example : "ghcr.io/wordpress-ionos/wordpress-ionos-devcontainer")
# use the IMAGE_NAME environment variable produced by ./.github/shared/devcontainer-image-name.yaml
imageName: ${{ env.IMAGE_NAME }}

# make some tests to test the devcontainer image is working
Expand Down

0 comments on commit feac09c

Please sign in to comment.