diff --git a/.github/workflows/test-action.yaml b/.github/workflows/test-action.yaml new file mode 100644 index 0000000000..05f7dd5a2a --- /dev/null +++ b/.github/workflows/test-action.yaml @@ -0,0 +1,33 @@ +name: Test Setup GitHub Actions + +on: + pull_request: + paths: + - action.yaml + - .github/workflows/test-action.yaml + +# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#concurrency +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + sparse-checkout: | + action.yaml + - name: Set up kwokctl + uses: . # kubernetes-sigs/kwok@main + with: + command: kwokctl + - name: Test kwokctl + shell: bash + run: | + kwokctl --version + kwokctl create cluster + kubectl version + kwokctl delete cluster diff --git a/action.yaml b/action.yaml new file mode 100644 index 0000000000..3f97aad216 --- /dev/null +++ b/action.yaml @@ -0,0 +1,50 @@ +name: Setup kwok + +description: This action runs kwok + +inputs: + command: + required: true + description: Command to install + kwok-version: + required: false + description: Specific version of command to install, defaults to latest release + repository: + required: false + description: Repository is kwok's repository, will use release from this repository, defaults same as use in this step + args: + required: false + description: The arguments to pass to the command; if passed, after the command is installed, it will run with the arguments +runs: + using: composite + steps: + - name: Install and start kwok + shell: bash + env: + KWOK_REPO: ${{ inputs.repository || github.repository }} + KWOK_VERSION: ${{ inputs.kwok-version }} + run: | + if [[ ! -f /usr/local/bin/${{ inputs.command }}-${KWOK_VERSION} ]]; then + if [[ -z "${KWOK_VERSION}" ]]; then + echo "Fetching latest version..." + KWOK_VERSION="$(curl "https://api.github.com/repos/${KWOK_REPO}/releases/latest" | jq -r '.tag_name')" + echo "Latest version is ${KWOK_VERSION}" + fi + echo "Installing ${{ inputs.command }} ${KWOK_VERSION}..." + wget -O ${{ inputs.command }}-${KWOK_VERSION} "https://github.com/${KWOK_REPO}/releases/download/${KWOK_VERSION}/${{ inputs.command }}-$(go env GOOS)-$(go env GOARCH)" + chmod +x ${{ inputs.command }}-${KWOK_VERSION} + sudo mv ${{ inputs.command }}-${KWOK_VERSION} /usr/local/bin/ + sudo ln -sf /usr/local/bin/${{ inputs.command }}-${KWOK_VERSION} /usr/local/bin/${{ inputs.command }} + if ! ${{ inputs.command }} --version; then + echo "Failed to run ${{ inputs.command }} --version" + exit 1 + fi + fi + if [[ -n "${{ inputs.args }}" ]]; then + echo "Running ${{ inputs.command }} ${{ inputs.args }}" + if ! ${{ inputs.command }} ${{ inputs.args }}; then + echo "Failed to run ${{ inputs.command }} ${{ inputs.args }}" + exit 1 + fi + echo "Done!" + fi diff --git a/site/config.yaml b/site/config.yaml index e56d66b2f2..8f105bc2f1 100644 --- a/site/config.yaml +++ b/site/config.yaml @@ -123,6 +123,10 @@ menu: pageRef: "/docs/user/all-in-one-image" weight: 1010 parent: user-guide + - identifier: github-action + pageRef: "/docs/user/github-action" + weight: 1015 + parent: user-guide - identifier: installation pageRef: "/docs/user/installation" weight: 1020 diff --git a/site/content/en/docs/user/github-action.md b/site/content/en/docs/user/github-action.md new file mode 100644 index 0000000000..91775fc8f2 --- /dev/null +++ b/site/content/en/docs/user/github-action.md @@ -0,0 +1,40 @@ +--- +title: Github Action +--- + +# Github Action + +{{< hint "info" >}} + +This document walks through the steps to use in the Github Action. + +{{< /hint >}} + +## Usage + +``` yaml +- uses: kubernetes-sigs/kwok@main + with: + # Required: The command to install ('kwok' or 'kwokctl') + command: '' + # Optional: Specific version of command to install, defaults to latest release + kwok-version: '' +``` + +### Create Cluster + +``` yaml +- name: Set up kwokctl + uses: kubernetes-sigs/kwok@main + with: + command: kwokctl +- run: kwokctl create cluster + env: + KWOK_KUBE_VERSION: v1.28.0 +``` + +## Next steps + +Now, you can use `kwok` to [manage nodes and pods] in the Kubernetes cluster. + +[manage nodes and pods]: {{< relref "/docs/user/kwok-manage-nodes-and-pods" >}}