Skip to content

ci: try content: write perm #33

ci: try content: write perm

ci: try content: write perm #33

Workflow file for this run

name: Build and Publish Docker Image
on:
push:
branches:
- main
paths:
- 'dockerfiles/dnf/Dockerfile'
tags:
- 'v*.*.*'
pull_request:
branches:
- main
paths:
- 'dockerfiles/dnf/Dockerfile'
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract version from tag
if: startsWith(github.ref, 'refs/tags/')
id: extract_version
run: echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Determine image tag
id: set_tag
run: |
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
TAG="ghcr.io/openchami/image-build:${GITHUB_REF#refs/tags/}"
elif [[ "${GITHUB_REF}" == refs/pull/* ]]; then
TAG="ghcr.io/openchami/image-build:latest-prbuild"
else
TAG="ghcr.io/openchami/image-build:test"
fi
echo "tag=${TAG}" >> $GITHUB_OUTPUT
echo "Computed tag: ${TAG}"
- name: Build and push Docker image
# Only run this step if a valid tag is computed
if: steps.set_tag.outputs.tag != ''
uses: docker/build-push-action@v3
with:
context: .
file: dockerfiles/dnf/Dockerfile
push: true
tags: ${{ steps.set_tag.outputs.tag }}
- name: Generate release notes
# Only run this step if version was computed from tag
if: steps.extract_version.outputs.version != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
{
echo '# image-build ${{ steps.extract_version.outputs.version }}'
echo
echo 'Pull with:'
echo
echo '```'
echo "podman pull ghcr.io/openchami/image-build:${{ steps.extract_version.outputs.version }}"
echo '```'
echo
gh api "repos/${GITHUB_REPOSITORY}/releases/generate-notes" -F tag_name="${{ steps.extract_version.outputs.version }}" --jq .body
} > CHANGELOG.md
- name: Create release
# Only run this step if version was computed from tag
if: steps.extract_version.outputs.version != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh release create ${{ steps.extract_version.outputs.version }} -F CHANGELOG.md