Push Your KCL Package by GitHub Action
This article will guide you how to use the kcl package management tool in GitHub Action to push your kcl package to OCI registry.
Step 1: Install KCL CLI
First, you need to install KCL CLI on your computer. You can follow the instructions in the KCL CLI installation documentation.
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.
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 the kcl package management tool
└── 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.
If you use ghcr.io as Registry, you need to use GitHub token as secrets.
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.21
        uses: actions/setup-go@v2
        with:
          go-version: 1.21
      - name: Install KCL CLI
        run: go install kcl-lang.io/cli/cmd/kcl@latest
      - name: Login and Push
        env:
          KPM_REG: ${{ secrets.REG }}
          KPM_REPO: ${{ secrets.REG_ACCOUNT }}
        run: kcl registry login -u ${{ secrets.REG_ACCOUNT }} -p ${{ secrets.REG_TOKEN }} ${{ secrets.REG }} && kcl mod push
      - name: Run kcl project from oci registry
        run: kcl run oci://${{ secrets.REG }}/${{ secrets.REG_ACCOUNT }}/catalog --tag 0.0.1