-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from jpower432/PSCE-199
PSCE-199 feat: adds workflow to publish container image to GHCR
- Loading branch information
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
name: Publish Image to GHCR | ||
|
||
on: | ||
release: | ||
types: [published] | ||
workflow_dispatch: | ||
inputs: | ||
tag: | ||
description: "Name of the tag for the published image" | ||
type: string | ||
required: true | ||
env: | ||
IMAGE_NAME: trestle-bot | ||
IMAGE_REGISTRY: ghcr.io/redhatproductsecurity | ||
|
||
jobs: | ||
publish-image: | ||
runs-on: 'ubuntu-latest' | ||
permissions: | ||
contents: read | ||
packages: write | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Log in to ghcr.io | ||
uses: redhat-actions/podman-login@v1 | ||
with: | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
registry: ${{ env.IMAGE_REGISTRY }} | ||
|
||
- name: Check if triggered by release or workflow dispatch | ||
id: check_event | ||
run: echo "event_type=${{ toJson(github.event_name) }}" >> "$GITHUB_OUTPUT" | ||
|
||
# Using intermediary variable to process event based input | ||
- name: Set TAG environment variable for Release | ||
if: steps.check_event.outputs.event_type == 'release' | ||
run: echo "TAG=$RELEASE_VERSION" >> "$GITHUB_ENV" | ||
env: | ||
RELEASE_VERSION: ${{ github.event.release.tag_name }} | ||
|
||
- name: Set TAG environment variable for Workflow Dispatch | ||
if: steps.check_event.outputs.event_type == 'workflow_dispatch' | ||
run: echo "TAG=$INPUT_VERSION" >> "$GITHUB_ENV" | ||
env: | ||
INPUT_VERSION: ${{ github.event.inputs.tag }} | ||
|
||
- name: Build image with Buildah | ||
id: build_image | ||
uses: redhat-actions/buildah-build@v2 | ||
with: | ||
image: ${{ env.IMAGE_NAME }} | ||
tags: ${{ env.TAG }} | ||
containerfiles: | | ||
./Dockerfile | ||
- name: Push To GHCR | ||
uses: redhat-actions/push-to-registry@v2 | ||
id: push | ||
with: | ||
image: ${{ steps.build_image.outputs.image }} | ||
tags: ${{ steps.build_image.outputs.tags }} | ||
registry: ${{ env.IMAGE_REGISTRY }} | ||
|
||
- name: Echo outputs | ||
run: | | ||
echo "${{ toJSON(steps.push.outputs) }}" | ||