Skip to content

Commit 2e0afcb

Browse files
authored
Merge pull request #85 from github-copilot-resources/feature/add-workflows
feat: Add workflows for building and pushing Docker images with custo…
2 parents c641d4d + 686fac5 commit 2e0afcb

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Build and push Docker image with custom tag
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
tag:
7+
description: 'Tag for the Docker image'
8+
required: true
9+
default: 'latest'
10+
11+
permissions:
12+
packages: write
13+
14+
jobs:
15+
push_to_ghcr:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout GitHub Action
19+
uses: actions/checkout@v4
20+
21+
- name: Login to GitHub Container Registry
22+
uses: docker/login-action@v3
23+
with:
24+
registry: ghcr.io
25+
username: ${{ github.actor }}
26+
password: ${{ secrets.GITHUB_TOKEN }}
27+
28+
- name: Build and Push Docker Image
29+
run: |
30+
GITHUB_REPO="${GITHUB_REPO,,}" # convert repo name to lowercase as required by docker
31+
TAG=${{ github.event.inputs.tag }}
32+
echo "building docker image in repository '$GITHUB_REPO' with tag '$TAG' ..."
33+
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 .
34+
docker push ghcr.io/$GITHUB_REPO:$TAG
35+
env:
36+
GITHUB_REPO: ${{ github.repository }}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Build and push Docker image with release tag
2+
3+
on:
4+
5+
release:
6+
types:
7+
- published
8+
9+
# Allows you to run this workflow manually from the Actions tab
10+
workflow_dispatch:
11+
12+
permissions:
13+
packages: write
14+
15+
jobs:
16+
push_to_ghcr:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout GitHub Action
20+
uses: actions/checkout@v4
21+
22+
- name: Get Latest Release Tag
23+
id: get_latest_release
24+
uses: actions/github-script@v6
25+
with:
26+
script: |
27+
const latestRelease = await github.repos.getLatestRelease({
28+
owner: context.repo.owner,
29+
repo: context.repo.repo,
30+
});
31+
return latestRelease.data.tag_name;
32+
33+
- name: Login to GitHub Container Registry
34+
uses: docker/login-action@v3
35+
with:
36+
registry: ghcr.io
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Build and Push Docker Image
41+
run: |
42+
GITHUB_REPO="${GITHUB_REPO,,}" # convert repo name to lowercase as required by docker
43+
TAG=${{ steps.get_latest_release.outputs.result }}
44+
echo "building docker image in repository '$GITHUB_REPO' with tag '$TAG' ..."
45+
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 .
46+
docker push ghcr.io/$GITHUB_REPO:$TAG
47+
env:
48+
GITHUB_REPO: ${{ github.repository }}

0 commit comments

Comments
 (0)