|
4 | 4 | pull_request: |
5 | 5 | branches: |
6 | 6 | - main |
| 7 | +env: |
| 8 | + STACKS_FILEPATH: "images.json" |
7 | 9 |
|
8 | 10 | jobs: |
9 | | - test: |
10 | | - name: Acceptance Test |
| 11 | + preparation: |
| 12 | + name: Preparation |
11 | 13 | runs-on: ubuntu-24.04 |
| 14 | + outputs: |
| 15 | + stacks: ${{ steps.get-stacks.outputs.stacks }} |
| 16 | + |
12 | 17 | steps: |
13 | | - - name: Checkout |
14 | | - uses: actions/checkout@v5 |
| 18 | + - name: Checkout repo |
| 19 | + uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + fetch-depth: 0 # gets full history |
15 | 22 |
|
16 | | - - name: Setup Go |
17 | | - uses: actions/setup-go@v6 |
18 | | - with: |
19 | | - go-version-file: go.mod |
| 23 | + - name: Get stacks images |
| 24 | + id: get-stacks |
| 25 | + run: | |
| 26 | +
|
| 27 | + if [ -f ${{ env.STACKS_FILEPATH }} ]; then |
| 28 | + stacks=$(jq -c '.images' images.json) |
| 29 | + else |
| 30 | + stacks=$(jq -n -c '[ |
| 31 | + { |
| 32 | + "name": "default", |
| 33 | + "config_dir": "stack", |
| 34 | + "output_dir": "build", |
| 35 | + "create_build_image": true, |
| 36 | + } |
| 37 | + ]') |
| 38 | + fi |
| 39 | +
|
| 40 | + stacks=$(echo "$stacks" | jq 'map({ |
| 41 | + name, |
| 42 | + config_dir, |
| 43 | + output_dir, |
| 44 | + create_build_image})') |
| 45 | +
|
| 46 | + stacks=$(jq -c <<< "$stacks" ) |
| 47 | + echo "stacks=$stacks" |
| 48 | + echo "stacks=$stacks" >> "$GITHUB_OUTPUT" |
| 49 | +
|
| 50 | + create_stack: |
| 51 | + name: Create Stack |
| 52 | + needs: [ preparation ] |
| 53 | + runs-on: ubuntu-24.04 |
| 54 | + strategy: |
| 55 | + matrix: |
| 56 | + stacks: ${{ fromJSON(needs.preparation.outputs.stacks) }} |
| 57 | + steps: |
| 58 | + - name: Checkout |
| 59 | + uses: actions/checkout@v4 |
20 | 60 |
|
21 | 61 | # https://github.com/docker/setup-qemu-action |
22 | 62 | - name: Set up QEMU |
23 | 63 | uses: docker/setup-qemu-action@v3 |
24 | 64 |
|
25 | | - - name: Create stack |
| 65 | + - name: Create stack ${{ matrix.stacks.name }} |
26 | 66 | id: create-stack |
27 | 67 | run: | |
28 | | - ./scripts/create.sh |
| 68 | + scripts/create.sh --stack-dir ${{ matrix.stacks.config_dir }} \ |
| 69 | + --build-dir ${{ matrix.stacks.output_dir }} |
| 70 | +
|
| 71 | + - name: Upload run image |
| 72 | + uses: actions/upload-artifact@v4 |
| 73 | + with: |
| 74 | + name: current-run-image-${{ matrix.stacks.name }} |
| 75 | + path: "${{ matrix.stacks.output_dir }}/run.oci" |
| 76 | + if-no-files-found: error |
| 77 | + |
| 78 | + - name: Upload build image |
| 79 | + if: ${{ matrix.stacks.create_build_image == true }} |
| 80 | + uses: actions/upload-artifact@v4 |
| 81 | + with: |
| 82 | + name: current-build-image-${{ matrix.stacks.name }} |
| 83 | + path: "${{ matrix.stacks.output_dir }}/build.oci" |
| 84 | + if-no-files-found: error |
| 85 | + |
| 86 | + test: |
| 87 | + name: Acceptance Test |
| 88 | + needs: [ preparation, create_stack ] |
| 89 | + runs-on: ubuntu-24.04 |
| 90 | + steps: |
| 91 | + - name: Setup Go |
| 92 | + uses: actions/setup-go@v5 |
| 93 | + with: |
| 94 | + go-version: stable |
| 95 | + |
| 96 | + - name: Checkout |
| 97 | + uses: actions/checkout@v4 |
| 98 | + |
| 99 | + - name: Download Build Image(s) |
| 100 | + uses: actions/download-artifact@v4 |
| 101 | + with: |
| 102 | + pattern: current-build-image-* |
| 103 | + |
| 104 | + - name: Download Run Image(s) |
| 105 | + uses: actions/download-artifact@v4 |
| 106 | + with: |
| 107 | + pattern: current-run-image-* |
| 108 | + |
| 109 | + - name: Create OCI artifacts destination directory |
| 110 | + run: | |
| 111 | + echo '${{ needs.preparation.outputs.stacks }}' | jq -c '.[]' | while read -r stack; do |
| 112 | + name=$(echo "$stack" | jq -r '.name') |
| 113 | + output_dir=$(echo "$stack" | jq -r '.output_dir') |
| 114 | + create_build_image=$(echo "$stack" | jq -r '.create_build_image') |
| 115 | + mkdir -p $output_dir |
| 116 | + mv "current-run-image-${name}/run.oci" "${output_dir}/run.oci" |
| 117 | + if [ $create_build_image == 'true' ]; then |
| 118 | + mv "current-build-image-${name}/build.oci" "${output_dir}/build.oci" |
| 119 | + fi |
| 120 | + done |
29 | 121 |
|
30 | 122 | - name: Run Acceptance Tests |
31 | | - run: ./scripts/test.sh |
| 123 | + run: ./scripts/test.sh --validate-stack-builds |
32 | 124 |
|
33 | 125 | upload: |
34 | 126 | name: Upload Workflow Event Payload |
|
0 commit comments