Skip to content

Workflow file for this run

name: Build and Push Container Image
on:
push:
tags:
- 'releases/*.*.*'
branches:
- 'releases/*.*.*'
workflow_dispatch:
jobs:
build-and-push:
runs-on: ubuntu-20.04
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
ref: ${{ github.ref_name }}
- name: Determine version
id: version
run: |
REF="${GITHUB_REF_NAME#releases/}"
echo "VERSION=${REF}" >> $GITHUB_ENV
- name: Build container image
id: build-image
uses: redhat-actions/buildah-build@v2
with:
image: toolbox
tags: ${{ env.VERSION }} ${{ github.sha }} latest
containerfiles: |
./Containerfile
oci: true
- name: Push image to GitHub Container Registry
id: push
uses: redhat-actions/push-to-registry@v2
with:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: "ghcr.io/${{ github.repository_owner }}"
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
- name: Echo outputs
run: |
echo "${{ toJSON(steps.push.outputs) }}"
create-release:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Get previous tag
id: get_previous_tag
run: |
git fetch --tags
PREV_TAG=$(git tag --sort=-v:refname | grep 'release/' | sed -n '2p')
echo "PREVIOUS_TAG=${PREV_TAG}" >> $GITHUB_ENV
- name: Generate commit list and diff link
id: generate_release_notes
env:
PREVIOUS_TAG: ${{ env.PREVIOUS_TAG }}
run: |
if [ -n "$PREVIOUS_TAG" ]; then
COMMITS=$(git log $PREVIOUS_TAG..HEAD --pretty=format:"- %s")
DIFF_URL="https://github.com/${{ github.repository }}/compare/${PREVIOUS_TAG}...${{ github.ref_name }}"
else
COMMITS="- No previous release found"
DIFF_URL="https://github.com/${{ github.repository }}/commits/${{ github.ref_name }}"
fi
echo "COMMITS=${COMMITS}" >> $GITHUB_ENV
echo "DIFF_URL=${DIFF_URL}" >> $GITHUB_ENV
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.event.inputs.manual_branch || github.ref_name }}
release_name: "Release ${{ env.VERSION }}"
body: |
## Container Image Released
- GitHub Container Registry Image: `ghcr.io/${{ github.repository_owner }}/toolbox:${{ env.VERSION }}`
## Changes
${{ env.COMMITS }}
[View changes in detail](${{ env.DIFF_URL }})
draft: false
prerelease: false