Skip to main content
版本: 0.5.6

Push Your KCL Package by GitHub Action

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.

Step 1: Install kpm

At first, you need to install kpm on your computer. You can follow kpm installation document.

Step 2: Create a GitHub account

If you already have a GitHub account, you can skip this step.

Sign up for a new GitHub account

Step 3: Create a GitHub repository for your KCL package

1. Prepare a GitHub repository for your KCL package

You need to prepare a GitHub repository for your KCL package.

Create a GitHub repository

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

2. Set OCI Registry, account and password for your Github repository

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.

Add secrets to the repository

If you use ghcr.io as Registry, you need to use GitHub token as secrets.

Create a GitHub Token

Step 4: Add your KCL package to the repository and write github action workflow

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