github.com/KusionStack/kpm@v0.8.4-0.20240326033734-dc72298a30e5/docs/push_by_github_action.md (about) 1 # How to Push Your KCL Package by GitHub Action 2 3 [kpm](https://github.com/KusionStack/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. 4 5 ## Step 1: Install kpm 6 7 At first, you need to install kpm on your computer. You can follow [kpm installation document](https://kcl-lang.io/docs/user_docs/guides/package-management/installation). 8 9 ## Step 2: Create a GitHub account 10 11 If you already have a GitHub account, you can skip this step. 12 13 [Sign up for a new GitHub account](https://docs.github.com/en/get-started/signing-up-for-github/signing-up-for-a-new-github-account) 14 15 ## Step 3: Create a GitHub repository for your KCL package 16 17 ### 1. Prepare a GitHub repository for your KCL package 18 19 You need to prepare a GitHub repository for your KCL package. 20 21 [Create a GitHub repository](https://docs.github.com/en/get-started/quickstart/create-a-repo) 22 23 In this repository, add your KCL program, take the repository https://github.com/awesome-kusion/catalog.git as an example, 24 25 ```bash 26 ├── .github 27 │ └── workflows 28 │ └── push.yaml # github action workflow 29 ├── LICENSE 30 ├── README.md 31 ├── kcl.mod # kcl.mod to define your kcl package 32 ├── kcl.mod.lock # kcl.mod.lock generated by kpm 33 └── main.k # Your KCL program 34 ``` 35 36 ### 2. Set OCI Registry, account and password for your Github repository 37 38 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. 39 40 [Add secrets to the repository](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) 41 42 If you use `ghcr.io` as `Registry`, you need to use GitHub token as secrets. 43 44 [Create a GitHub Token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#personal-access-tokens-classic) 45 46 ## Step 4: Add your KCL package to the repository and write github action workflow 47 48 Add github action file `.github/workflows/push.yml` to this repository, the content is as follows: 49 50 ```yaml 51 name: KPM Push Workflow 52 53 on: 54 push: 55 branches: 56 - main 57 58 jobs: 59 build: 60 runs-on: ubuntu-latest 61 steps: 62 - name: Checkout 63 uses: actions/checkout@v2 64 65 - name: Set up Go 1.21 66 uses: actions/setup-go@v2 67 with: 68 go-version: 1.21 69 70 - name: Install kpm 71 run: go install kcl-lang.io/kpm@latest 72 73 - name: Login and Push 74 env: 75 KPM_REG: ${{ secrets.REG }} 76 KPM_REPO: ${{ secrets.REG_ACCOUNT }} 77 run: kpm login -u ${{ secrets.REG_ACCOUNT }} -p ${{ secrets.REG_TOKEN }} ${{ secrets.REG }} && kpm push 78 79 - name: Run kpm project from oci registry 80 run: kpm run oci://${{ secrets.REG }}/${{ secrets.REG_ACCOUNT }}/catalog --tag 0.0.1 81 82 ```