kpm is a tool for managing kcl packages. This article will guide you how to use kpm in GitHub Action to push your kcl package to OCI registry.
At first, you need to install kpm on your computer. You can follow kpm installation document.
If you already have a GitHub account, you can skip this step.
Sign up for a new GitHub account
You need to prepare a GitHub repository for your KCL package.
In this repository, add your KCL program, take the repository https://github.com/awesome-kusion/catalog.git as an example,
├── .github
│ └── workflows
│ └── push.yaml # github action workflow
├── LICENSE
├── README.md
├── kcl.mod # kcl.mod to define your kcl package
├── kcl.mod.lock # kcl.mod.lock generated by kpm
└── main.k # Your KCL program
Take docker.io as an example, you can set secrets REG
, REG_ACCOUNT
and REG_TOKEN
for your repository. The value of REG
is docker.io
, the value of REG_ACCOUNT
is your docker.io
account, and the value of REG_TOKEN
is your docker.io
login password.
If you use ghcr.io
as Registry
, you need to use GitHub token as secrets.
Add github action file .github/workflows/push.yml
to this repository, the content is as follows:
name: KPM Push Workflow
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Go 1.19
uses: actions/setup-go@v2
with:
go-version: 1.19
- name: Install kpm
run: go install kcl-lang.io/kpm@latest
- name: Login and Push
env:
KPM_REG: ${{ secrets.REG }}
KPM_REPO: ${{ secrets.REG_ACCOUNT }}
run: kpm login -u ${{ secrets.REG_ACCOUNT }} -p ${{ secrets.REG_TOKEN }} ${{ secrets.REG }} && kpm push
- name: Run kpm project from oci registry
run: kpm run oci://${{ secrets.REG }}/${{ secrets.REG_ACCOUNT }}/catalog --tag 0.0.1