update registries and improve GHA #37
Workflow file for this run
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
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: Set short SHA | ||
run: echo "SHORT_SHA=${GITHUB_SHA::7}" >> $GITHUB_ENV | ||
- 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: | | ||
Check failure on line 41 in .github/workflows/bsod-api-container.yaml GitHub Actions / Build API ContainerInvalid workflow file
|
||
if ($env:GITHUB_REF -eq 'refs/heads/main') { | ||
$TAG = 'latest' | ||
} else { | ||
$TAG = 'devel' | ||
} | ||
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}\`` | ||
}); |