Skip to content

update registries and improve GHA #43

update registries and improve GHA

update registries and improve GHA #43

name: Build API Container
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
env:
REGISTRY: ghcr.io
REPO: r-techsupport
IMAGE: webdbg-api
jobs:
build_and_push:
runs-on: windows-2022
permissions:
contents: write
pull-requests: write
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
submodules: true
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
run: |
$SHORT_SHA = "${{ github.sha }}"[0..6] -join ''
if ("${{ github.ref }}" -eq 'refs/heads/main') {
$TAG = 'latest'
} else {
$TAG = 'devel'
}
Write-Host "Using tag: $TAG"
docker build -t `
${{ env.REGISTRY }}/${{ env.REPO }}/${{ env.IMAGE }}:$TAG `
-t ${{ env.REGISTRY }}/${{ env.REPO }}/${{ env.IMAGE }}:${{ env.SHORT_SHA }} `
api/
docker push ${{ env.REGISTRY }}/${{ env.REPO }}/${{ env.IMAGE }}:$TAG
docker push ${{ env.REGISTRY }}/${{ env.REPO }}/${{ env.IMAGE }}:${{ env.SHORT_SHA }}
- name: Log out from the Container registry
run: docker logout ${{ env.REGISTRY }}
- name: Comment on the PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
script: |
const tag = '${{ env.REGISTRY }}/${{ env.REPO }}/${{ env.IMAGE }}:${{ env.TAG }}';
const shortSha = '${{ env.REGISTRY }}/${{ env.REPO }}/${{ env.IMAGE }}:${{ env.SHORT_SHA }}';
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `Docker images have been built and pushed:\n- \`${tag}\`\n- \`${shortSha}\``
});