Skip to content

Commit

Permalink
Refactor workflows (#596)
Browse files Browse the repository at this point in the history
  • Loading branch information
int128 authored Nov 21, 2024
1 parent b84b7d3 commit 653cfb0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 51 deletions.
17 changes: 0 additions & 17 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:
- Dockerfile
- Dockerfile.*
- entrypoint.sh
- entrypoint.d/**
- e2e-test/**
push:
paths:
Expand All @@ -17,41 +16,25 @@ on:
- Dockerfile
- Dockerfile.*
- entrypoint.sh
- entrypoint.d/**
- e2e-test/**
branches:
- main
tags:
- '*'
workflow_call:
inputs:
context:
type: string
required: false
description: context passed to docker/build-push-action (optional)
tags:
type: string
required: false
description: tags passed to docker/metadata-action (optional)

jobs:
build:
uses: ./.github/workflows/reusable--build.yaml
permissions:
contents: read
packages: write
with:
context: ${{ inputs.context }}
tags: ${{ inputs.tags }}

build-ubuntu20:
uses: ./.github/workflows/reusable--build.yaml
permissions:
contents: read
packages: write
with:
context: ${{ inputs.context }}
tags: ${{ inputs.tags }}
file: Dockerfile.ubuntu20
flavor: suffix=-ubuntu20

Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:
- Dockerfile
- Dockerfile.*
- entrypoint.sh
- entrypoint.d/**
- hack/**
push:
branches:
Expand All @@ -19,7 +18,6 @@ on:
- Dockerfile
- Dockerfile.*
- entrypoint.sh
- entrypoint.d/**
- hack/**

jobs:
Expand All @@ -38,8 +36,14 @@ jobs:
app-id: ${{ secrets.E2E_TEST_APP_ID }}
private-key: ${{ secrets.E2E_TEST_APP_PRIVATE_KEY }}
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- run: bash hack/create-release-if-not-exists.sh
- id: create-release
run: bash hack/create-release-if-not-exists.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Trigger the build workflow against the new release
RELEASE_TOKEN: ${{ steps.release-token.outputs.token }}
- if: steps.create-release.outputs.comment
uses: int128/comment-action@a20dbdebd79ab886a1e7a20d16bfa7dbaa732e5a # v1.33.0
with:
update-if-exists: replace
post: ${{ steps.create-release.outputs.comment }}
15 changes: 0 additions & 15 deletions .github/workflows/reusable--build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,10 @@ name: build
on:
workflow_call:
inputs:
context:
type: string
required: false
description: context passed to docker/build-push-action
file:
type: string
required: false
description: file passed to docker/build-push-action
build-args:
type: string
required: false
description: build-args passed to docker/build-push-action
tags:
type: string
required: false
description: tags passed to docker/metadata-action
flavor:
type: string
required: false
Expand Down Expand Up @@ -46,7 +34,6 @@ jobs:
id: metadata
with:
images: ghcr.io/${{ github.repository }}
tags: ${{ inputs.tags }}
flavor: ${{ inputs.flavor }}
- uses: int128/docker-build-cache-config-action@34bb1b5886d06c161bf0dd9e169f03a52ff858fb # v1.35.0
id: cache
Expand All @@ -58,14 +45,12 @@ jobs:
- uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0
id: build
with:
context: ${{ inputs.context }}
file: ${{ inputs.file }}
push: true
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
cache-from: ${{ steps.cache.outputs.cache-from }}
cache-to: ${{ steps.cache.outputs.cache-to }}
build-args: ${{ inputs.build-args }}
platforms: |
linux/amd64
linux/arm64
2 changes: 1 addition & 1 deletion .github/workflows/reusable--e2e-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- run: make deploy
env:
ARC_RUNNER_NAME: e2e-${{ github.run_id }}
ARC_RUNNER_IMAGE_URI: ${{ inputs.runner-image-uri}}
ARC_RUNNER_IMAGE_URI: ${{ inputs.runner-image-uri }}
ARC_RUNNER_UBUNTU20_NAME: e2e-ubuntu20-${{ github.run_id }}
ARC_RUNNER_UBUNTU20_IMAGE_URI: ${{ inputs.runner-ubuntu20-image-uri }}
- run: make wait-for-job
Expand Down
29 changes: 14 additions & 15 deletions hack/create-release-if-not-exists.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
#!/bin/bash
set -eux

# find the runner version in Dockerfile
set_comment_output () {
echo "comment=$*" >> "$GITHUB_OUTPUT"
}

# Find the runner version in Dockerfile
actions_runner_version="$(grep RUNNER_VERSION= Dockerfile | cut -f2 -d=)"

# post a comment if pull request
if [[ $GITHUB_EVENT_NAME == pull_request ]]; then
if gh release view "$actions_runner_version"; then
gh pr comment "$GITHUB_HEAD_REF" --body-file - <<EOF
:new: If you need to build a new runner image, [create a new release](https://github.com/quipper/actions-runner/releases/new) after merge.
EOF
exit
if gh release view "$actions_runner_version"; then
if [[ $GITHUB_EVENT_NAME == pull_request ]]; then
set_comment_output ":bulb: If you need a new version, [create a new release](https://github.com/quipper/actions-runner/releases/new) after merge."
fi

gh pr comment "$GITHUB_HEAD_REF" --body-file - <<EOF
:robot: GitHub Actions will automatically create a release ${actions_runner_version} after merge.
EOF
exit
fi

if gh release view "$actions_runner_version"; then
exit # already exists
if [[ $GITHUB_EVENT_NAME == pull_request ]]; then
set_comment_output ":robot: GitHub Actions will automatically create a release ${actions_runner_version} after merge."
exit
fi

# create a release if not exists
# Create a release if not exists
GITHUB_TOKEN="$RELEASE_TOKEN" gh release create "$actions_runner_version" --generate-notes

set_comment_output ":robot: GitHub Actions automatically created a new release ${actions_runner_version}"

0 comments on commit 653cfb0

Please sign in to comment.