Skip to content
name: Build and push Docker image with release tag
on:
release:
types:
- published
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
permissions:
packages: write
jobs:
push_to_ghcr:
runs-on: ubuntu-latest
steps:
- name: Checkout GitHub Action
uses: actions/checkout@v4
- name: Get Latest Release Tag
id: get_latest_release
uses: actions/github-script@v6
with:
script: |
const latestRelease = await github.rest.repos.getLatestRelease({
owner: context.repo.owner,
repo: context.repo.repo,
});
core.setOutput('tag_name', latestRelease.data.tag_name);
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push Docker Image
run: |
GITHUB_REPO="${GITHUB_REPO,,}" # convert repo name to lowercase as required by docker
TAG=${{ steps.get_latest_release.outputs.result }}
echo "building docker image in repository '$GITHUB_REPO' with tag '$TAG' ..."
docker build --label "org.opencontainers.image.title=copilot-metrics-viewer" --label "org.opencontainers.image.description=Metrics viewer for GitHub Copilot usage" --label "org.opencontainers.image.source=$GITHUB_REPO" -t ghcr.io/$GITHUB_REPO:$TAG .
docker push ghcr.io/$GITHUB_REPO:$TAG
env:
GITHUB_REPO: ${{ github.repository }}