Skip to content

Merge pull request #233 from kbst/fix-goreleaser-input #498

Merge pull request #233 from kbst/fix-goreleaser-input

Merge pull request #233 from kbst/fix-goreleaser-input #498

Workflow file for this run

name: Run Tests
on: push
env:
GO_VERSION: ">=1.20"
TERRAFORM_VERSION: "1.4.6"
KIND_VERSION: "v0.17.0"
jobs:
tf_tests:
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
runner: ["ubuntu-latest", "windows-latest", "macos-latest"]
steps:
- name: Checkout using linefeed for tests
run: |
git config --global core.autocrlf false
- name: 'Checkout'
uses: actions/checkout@v3
- name: 'Setup K8s'
if: startsWith(matrix.runner, 'ubuntu-')
uses: helm/kind-action@v1.7.0
with:
version: "${{ env.KIND_VERSION }}"
cluster_name: ci
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "${{ env.GO_VERSION }}"
- name: Set up Helm
uses: azure/setup-helm@v3.5
with:
version: '3.12.0'
- name: 'Run TF acceptance tests (${{ matrix.runner }})'
if: startsWith(matrix.runner, 'ubuntu-')
env:
KUBECONFIG_PATH: ~/.kube/config
run: make test
- name: 'Run TF unit tests (${{ matrix.runner }})'
if: startsWith(matrix.runner, 'ubuntu-') == false
env:
KUBECONFIG_PATH: ${{ github.workspace }}/tests/fakekubeconfig
run: |
go test -ldflags "-X google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=ignore" -v ./kustomize
compile_provider:
runs-on: ubuntu-latest
steps:
- name: 'Checkout'
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "${{ env.GO_VERSION }}"
- name: Run goreleaser build
if: startsWith(github.ref, 'refs/tags/v')
uses: kbst/goreleaser-action@v4
with:
version: latest
args: build --config .goreleaser-build.yml --rm-dist
- name: Run goreleaser build --snapshot
if: startsWith(github.ref, 'refs/tags/v') == false
uses: kbst/goreleaser-action@v4
with:
version: latest
args: build --config .goreleaser-build.yml --rm-dist --snapshot
- name: 'Prepare terraform-plugins'
run: |
mkdir -p ./dist/terraform.d/plugins/registry.terraform.io/kbst/kustomization/1.0.0/linux_amd64
cp ./dist/terraform-provider-kustomization_linux_amd64_v1/terraform-provider-kustomization_v* ./dist/terraform.d/plugins/registry.terraform.io/kbst/kustomization/1.0.0/linux_amd64/terraform-provider-kustomization_v1.0.0
- name: 'Upload terraform-plugins'
uses: actions/upload-artifact@v3
with:
name: terraform-plugins
path: dist/terraform.d/plugins
int_test_kubeconfig_path:
runs-on: ubuntu-latest
needs: [compile_provider]
env:
KUBECONFIG_PATH: ~/.kube/config
steps:
- name: 'Checkout'
uses: actions/checkout@v3
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_wrapper: false
terraform_version: "${{ env.TERRAFORM_VERSION }}"
- name: 'Download terraform-plugins'
uses: actions/download-artifact@v3
with:
name: terraform-plugins
path: terraform.d/plugins
- name: 'Ensure provider is executable'
run: chmod +x terraform.d/plugins/registry.terraform.io/kbst/kustomization/1.0.0/linux_amd64/terraform-provider-kustomization_v1.0.0
- name: 'Setup K8s'
uses: helm/kind-action@v1.7.0
with:
version: "${{ env.KIND_VERSION }}"
cluster_name: ci
- name: 'Terraform Init'
run: terraform init
- name: 'Terraform Apply'
run: terraform apply --auto-approve
int_test_kubeconfig_raw:
runs-on: ubuntu-latest
needs: [compile_provider]
steps:
- name: 'Checkout'
uses: actions/checkout@v3
- name: 'Setup K8s'
uses: helm/kind-action@v1.7.0
with:
version: "${{ env.KIND_VERSION }}"
cluster_name: ci
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_wrapper: false
terraform_version: "${{ env.TERRAFORM_VERSION }}"
- name: 'Download terraform-plugins'
uses: actions/download-artifact@v3
with:
name: terraform-plugins
path: terraform.d/plugins
- name: 'Ensure provider is executable'
run: chmod +x terraform.d/plugins/registry.terraform.io/kbst/kustomization/1.0.0/linux_amd64/terraform-provider-kustomization_v1.0.0
- name: 'Create provider.tf with kubeconfig_raw'
run: |
echo "provider "kustomization" {" > provider.tf
echo " kubeconfig_raw = <<EOT" >> provider.tf
kind get kubeconfig --name ci >> provider.tf
echo "EOT" >> provider.tf
echo "}" >> provider.tf
- name: 'Terraform Init'
run: terraform init
- name: 'Terraform Apply'
run: terraform apply --auto-approve
int_test_in_cluster:
runs-on: ubuntu-latest
needs: [compile_provider]
steps:
- name: 'Checkout'
uses: actions/checkout@v3
- name: 'Setup K8s'
uses: helm/kind-action@v1.7.0
with:
version: "${{ env.KIND_VERSION }}"
cluster_name: ci
- name: 'Download terraform-plugins'
uses: actions/download-artifact@v3
with:
name: terraform-plugins
path: terraform.d/plugins
- name: Create terraform pod
run: kubectl apply -f tests/in-cluster.yaml
- name: Wait for pod to be ready
run: kubectl wait pod/terraform --for condition=Ready --timeout 60s
- name: 'Ensure provider is executable'
run: chmod +x terraform.d/plugins/registry.terraform.io/kbst/kustomization/1.0.0/linux_amd64/terraform-provider-kustomization_v1.0.0
- name: Make provider directory
run: kubectl exec terraform -- mkdir terraform.d
- name: Copy provider
run: kubectl cp terraform.d/plugins terraform:terraform.d/plugins
- name: Copy test file
run: kubectl cp test.tf terraform:test.tf
- name: Copy kustomize directory
run: kubectl cp kustomize terraform:kustomize
- name: Create provider file
run: kubectl exec -it terraform -- sh -c 'echo "provider \"kustomization\" {" > provider.tf; echo " kubeconfig_incluster = true" >> provider.tf; echo "}" >> provider.tf'
- name: 'Terraform Init'
run: kubectl exec -it terraform -- terraform init
- name: 'Terraform Apply'
run: kubectl exec -it terraform -- terraform apply --auto-approve
int_test_state_import:
runs-on: ubuntu-latest
needs: [compile_provider]
env:
KUBECONFIG_PATH: ~/.kube/config
steps:
- name: 'Checkout'
uses: actions/checkout@v3
- name: 'Setup K8s'
uses: helm/kind-action@v1.7.0
with:
version: "${{ env.KIND_VERSION }}"
cluster_name: ci
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_wrapper: false
terraform_version: "${{ env.TERRAFORM_VERSION }}"
- name: 'Download terraform-plugins'
uses: actions/download-artifact@v3
with:
name: terraform-plugins
path: terraform.d/plugins
- name: 'Ensure provider is executable'
run: chmod +x terraform.d/plugins/registry.terraform.io/kbst/kustomization/1.0.0/linux_amd64/terraform-provider-kustomization_v1.0.0
- name: 'Download kustomize'
run: |
wget https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv3.5.4/kustomize_v3.5.4_linux_amd64.tar.gz
sudo tar -C /usr/local/bin -xvf kustomize_v3.5.4_linux_amd64.tar.gz
kustomize version
- name: 'Kubectl apply'
run: |
kustomize build kustomize/test_kustomizations/basic/initial | kubectl apply -f -
- name: 'Terraform Init'
run: terraform init
- name: 'Terraform Import'
run: |
terraform import 'kustomization_resource.from_build["_/Namespace/_/test-basic"]' _/Namespace/_/test-basic
terraform import 'kustomization_resource.from_build["apps/Deployment/test-basic/test"]' apps/Deployment/test-basic/test
terraform import 'kustomization_resource.from_build["_/Service/test-basic/test"]' _/Service/test-basic/test
terraform import 'kustomization_resource.from_build["networking.k8s.io/Ingress/test-basic/test"]' networking.k8s.io/Ingress/test-basic/test
- name: 'Terraform Apply'
run: terraform apply --auto-approve
int_test_state_migration:
runs-on: ubuntu-latest
needs: [compile_provider]
env:
KUBECONFIG_PATH: ~/.kube/config
steps:
- name: 'Checkout'
uses: actions/checkout@v3
- name: 'Setup K8s'
uses: helm/kind-action@v1.7.0
with:
version: "${{ env.KIND_VERSION }}"
cluster_name: ci
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_wrapper: false
terraform_version: "${{ env.TERRAFORM_VERSION }}"
- name: 'Temporarily use old provider version'
run: |
mv test-schema-migration._tf test.tf
- name: 'Terraform Init'
run: terraform init
- name: 'Terraform Apply'
run: terraform apply --auto-approve
- name: 'Download terraform-plugins'
uses: actions/download-artifact@v3
with:
name: terraform-plugins
path: terraform.d/plugins
- name: 'Ensure provider is executable'
run: chmod +x terraform.d/plugins/registry.terraform.io/kbst/kustomization/1.0.0/linux_amd64/terraform-provider-kustomization_v1.0.0
- name: 'Reset provider version'
run: |
git checkout -- test.tf
- name: 'Terraform Init'
run: terraform init --upgrade
- name: 'Terraform Apply'
run: terraform apply --auto-approve
int_test_kubestack_kind:
runs-on: ubuntu-latest
needs: [compile_provider]
steps:
- name: 'Checkout'
uses: actions/checkout@v3
- name: 'Download terraform-plugins'
uses: actions/download-artifact@v3
with:
name: terraform-plugins
path: tests/kubestack-starter-kind/terraform.d/plugins
- name: 'Ensure provider is executable'
run: chmod +x tests/kubestack-starter-kind/terraform.d/plugins/registry.terraform.io/kbst/kustomization/1.0.0/linux_amd64/terraform-provider-kustomization_v1.0.0
- name: 'Build Kubestack Image'
run: |
docker build \
-t test-image:${{ github.sha }} \
tests/kubestack-starter-kind/
- name: 'Terraform Init'
run: |
docker run \
--rm \
--privileged \
--net host \
-v `pwd`/tests/kubestack-starter-kind:/infra \
-v /var/run/docker.sock:/var/run/docker.sock \
test-image:${{ github.sha }} \
terraform init
- name: 'Terraform Workspace'
run: |
docker run \
--rm \
--privileged \
--net host \
-v `pwd`/tests/kubestack-starter-kind:/infra \
-v /var/run/docker.sock:/var/run/docker.sock \
test-image:${{ github.sha }} \
terraform workspace new apps
- name: 'Terraform Apply'
run: |
docker run \
--rm \
--privileged \
--net host \
-v `pwd`/tests/kubestack-starter-kind:/infra \
-v /var/run/docker.sock:/var/run/docker.sock \
test-image:${{ github.sha }} \
terraform apply --auto-approve
- name: 'Terraform Destroy'
run: |
docker run \
--rm \
--privileged \
--net host \
-v `pwd`/tests/kubestack-starter-kind:/infra \
-v /var/run/docker.sock:/var/run/docker.sock \
test-image:${{ github.sha }} \
terraform destroy --auto-approve
goreleaser:
runs-on: ubuntu-latest
needs:
- tf_tests
- int_test_kubeconfig_path
- int_test_kubeconfig_raw
- int_test_in_cluster
- int_test_state_import
- int_test_kubestack_kind
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "${{ env.GO_VERSION }}"
- name: Import GPG key
id: import_gpg
uses: kbst/ghaction-import-gpg@v5
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
- name: Run goreleaser release
uses: kbst/goreleaser-action@v4
with:
version: latest
args: release
env:
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}