Skip to content

Commit

Permalink
Add Publish to MCR workflow
Browse files Browse the repository at this point in the history
Signed-off-by: Heba Elayoty <[email protected]>
  • Loading branch information
helayoty committed Sep 15, 2023
1 parent ded71da commit 3e83a0d
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
1 change: 0 additions & 1 deletion .github/workflows/build-publish-image.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: Create, Scan and Publish KDM image
on:
workflow_dispatch:
pull_request:
branches:
- main
Expand Down
73 changes: 73 additions & 0 deletions .github/workflows/publish-image-mcr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Push image to MCR
on:
workflow_dispatch:
workflow_run:
workflows: [ "Create release" ]
types: [ completed ]
branches: [ main, release-** ]


permissions:
id-token: write
contents: read

jobs:
publish:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
defaults:
run:
shell: pwsh
steps:
- name: Download tag artifact
uses: actions/github-script@v6
with:
github-token: ${{ secrets.KDM_ACCESS_TOKEN_READ }}
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "artifacts"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`/tmp/artifacts.zip`, Buffer.from(download.data));
- run: |
mkdir -p /tmp/artifacts
unzip /tmp/artifacts.zip -d /tmp/artifacts
shell: bash
- run: |
echo "Downloaded artifacts:"
ls -ablh /tmp/artifacts
shell: bash
- name: Parse artifacts and assign GA environment variables
run: |
tag=$(tail -n 1 /tmp/artifacts/tag.txt)
echo "IMG_TAG=$tag" >> $GITHUB_ENV
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
ref: ${{ env.IMG_TAG }}
- name: 'Az CLI login'
uses: azure/[email protected]
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: 'Publish to ACR'
id: publish
run: |
az acr login -n ${{ vars.AZURE_MCR_REGISTRY }}
OUTPUT_TYPE=type=registry make docker-build-kdm
env:
VERSION: ${{ env.IMG_TAG }}
REGISTRY: ${{ secrets.AZURE_MCR_REGISTRY }}

0 comments on commit 3e83a0d

Please sign in to comment.