Skip to content

Commit

Permalink
Merge pull request #27 from slok/slok/v1.30
Browse files Browse the repository at this point in the history
Allow building images from PRs
  • Loading branch information
slok authored Mar 27, 2024
2 parents c6c3292 + 9439087 commit 36cad9c
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 12 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/build-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Build pull request

on:
issue_comment:
types:
- created

jobs:
pr-release-image:
if: ${{ github.event.issue.pull_request && github.event.comment.body == '/yolo'}}
name: Release images
runs-on: ubuntu-latest
steps:
- name: Get PR SHA
id: sha
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const pr = await github.rest.pulls.get({
owner: context.issue.owner,
repo: context.issue.repo,
pull_number: context.issue.number,
});
return pr.data.head.sha
- uses: actions/checkout@v4
with:
ref: ${{ steps.sha.outputs.result }}

- name: React to comment
uses: actions/github-script@v7
with:
script: |
github.rest.reactions.createForIssueComment({
owner: context.issue.owner,
repo: context.issue.repo,
comment_id: context.payload.comment.id,
content: "rocket",
});
- name: Docker auth
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and publish docker images
run: make build-publish-image-all
env:
PROD_IMAGE_NAME: ghcr.io/${GITHUB_REPOSITORY}
VERSION: ${{ steps.sha.outputs.result }}

- name: Message success
if: ${{ success() }}
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '✔ Release ready: `${{ steps.sha.outputs.result }}`',
});
- name: Message failure
if: ${{ failure() }}
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '❌ Release failed: `${{ steps.sha.outputs.result }}`',
});
2 changes: 0 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ jobs:
runs-on: ubuntu-latest
container: golangci/golangci-lint:v1.56.2-alpine
steps:
- run: echo "machine github.com login ${CW_GO_DEPS_LOGIN} password ${CW_GO_DEPS_TOKEN}" > ~/.netrc
- uses: actions/checkout@v4
- run: |
# We need this go flag because it started to error after golangci-lint is using Go 1.21.
Expand All @@ -20,7 +19,6 @@ jobs:
name: Unit test
runs-on: ubuntu-latest
steps:
- run: echo "machine github.com login ${CW_GO_DEPS_LOGIN} password ${CW_GO_DEPS_TOKEN}" > ~/.netrc
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Kube code generator

![Kubernetes release](https://img.shields.io/badge/Kubernetes-v1.<30-green?logo=Kubernetes&style=flat&color=326CE5&logoColor=white)
![Kubernetes release](https://img.shields.io/badge/Kubernetes-v1.30-green?logo=Kubernetes&style=flat&color=326CE5&logoColor=white)

## Introduction

Expand Down
5 changes: 0 additions & 5 deletions scripts/build/docker/build-image-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@ set -e
[ -z "$VERSION" ] && echo "VERSION env var is required." && exit 1
[ -z "$IMAGE" ] && echo "IMAGE env var is required." && exit 1
[ -z "$DOCKER_FILE_PATH" ] && echo "DOCKER_FILE_PATH env var is required." && exit 1
[ -z "$CW_GO_DEPS_LOGIN" ] && echo "CW_GO_DEPS_LOGIN env var is required (go deps)." && exit 1
[ -z "$CW_GO_DEPS_TOKEN" ] && echo "CW_GO_DEPS_TOKEN env var is required (go deps)." && exit 1

# Build image.
echo "Building dev image ${IMAGE}:${VERSION}..."
docker build \
--build-arg CW_GO_DEPS_LOGIN="${CW_GO_DEPS_LOGIN}" \
--build-arg CW_GO_DEPS_TOKEN="${CW_GO_DEPS_TOKEN}" \
-t "${IMAGE}:${VERSION}" \
-f "${DOCKER_FILE_PATH}" .
4 changes: 0 additions & 4 deletions scripts/build/docker/build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ set -e
[ -z "$VERSION" ] && echo "VERSION env var is required." && exit 1
[ -z "$IMAGE" ] && echo "IMAGE env var is required." && exit 1
[ -z "$DOCKER_FILE_PATH" ] && echo "DOCKER_FILE_PATH env var is required." && exit 1
[ -z "$CW_GO_DEPS_LOGIN" ] && echo "CW_GO_DEPS_LOGIN env var is required (go deps)." && exit 1
[ -z "$CW_GO_DEPS_TOKEN" ] && echo "CW_GO_DEPS_TOKEN env var is required (go deps)." && exit 1

# By default use amd64 architecture.
DEF_ARCH=amd64
Expand All @@ -17,8 +15,6 @@ IMAGE_TAG_ARCH="${IMAGE}:${VERSION}-${ARCH}"
# Build image.
echo "Building image ${IMAGE_TAG_ARCH}..."
docker build \
--build-arg CW_GO_DEPS_LOGIN="${CW_GO_DEPS_LOGIN}" \
--build-arg CW_GO_DEPS_TOKEN="${CW_GO_DEPS_TOKEN}" \
--build-arg VERSION="${VERSION}" \
--build-arg ARCH="${ARCH}" \
-t "${IMAGE_TAG_ARCH}" \
Expand Down

0 comments on commit 36cad9c

Please sign in to comment.