From 0afe63fccd00f557e967c4b7e87eccf1eb854854 Mon Sep 17 00:00:00 2001
From: Philip Laine <philip.laine@gmail.com>
Date: Thu, 15 Aug 2024 10:13:45 +0200
Subject: [PATCH] test: add workflow to make sure importing Zarf works (#2874)

Signed-off-by: Philip Laine <philip.laine@gmail.com>
Co-authored-by: Austin Abro <37223396+AustinAbro321@users.noreply.github.com>
---
 .github/workflows/test-import.yaml | 50 ++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
 create mode 100644 .github/workflows/test-import.yaml

diff --git a/.github/workflows/test-import.yaml b/.github/workflows/test-import.yaml
new file mode 100644
index 0000000000..72ad5e770f
--- /dev/null
+++ b/.github/workflows/test-import.yaml
@@ -0,0 +1,50 @@
+name: Test Import
+on:
+  pull_request:
+
+permissions:
+  contents: read
+
+# Abort prior jobs in the same workflow / PR
+concurrency:
+  group: import-${{ github.ref }}
+  cancel-in-progress: true
+
+jobs:
+  test-import:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout
+        uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
+
+      - name: Setup Go
+        uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
+        with:
+          go-version-file: 'go.mod'
+          cache: true
+
+      - name: Run test Go program that imports Zarf
+        run: |
+          cd $(mktemp -d)
+          echo "$GO_MAIN" > main.go
+          go mod init github.com/zarf-dev/test-import
+          go mod edit -replace github.com/zarf-dev/zarf=github.com/${{ github.repository }}@${COMMIT_SHA:0:12}
+          go mod tidy
+          cat go.mod | grep -q ${COMMIT_SHA:0:12}
+          go run main.go
+        env:
+          COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
+          GO_MAIN: |
+            package main
+
+            import (
+            	"fmt"
+
+            	"github.com/zarf-dev/zarf/src/api/v1alpha1"
+            	"github.com/zarf-dev/zarf/src/pkg/packager"
+            )
+
+            func main() {
+            	fmt.Println(packager.Packager{})
+            	fmt.Println(v1alpha1.ZarfComponent{})
+            }