|
| 1 | +--- |
| 2 | +name: Build multi-arch images |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_call: |
| 6 | + ### |
| 7 | + ### Variables |
| 8 | + ### |
| 9 | + inputs: |
| 10 | + matrix: |
| 11 | + description: 'The build matrix' |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + has_refs: |
| 15 | + description: 'The ref build matrix as JSON string (list of git refs to build/deploy).' |
| 16 | + required: true |
| 17 | + type: string |
| 18 | + artifact_prefix: |
| 19 | + description: 'Unique artifact name prefix (to avoid overriding existing artifcats during parallel runs).' |
| 20 | + required: true |
| 21 | + type: string |
| 22 | + flavour: |
| 23 | + description: 'The flavour to build (Examples: base, mods, prod or work).' |
| 24 | + required: true |
| 25 | + type: string |
| 26 | + flavour_prev: |
| 27 | + description: 'The previous flavour (used for downloading previous artifact).' |
| 28 | + required: true |
| 29 | + type: string |
| 30 | + run_tests: |
| 31 | + description: 'Dertermines whether we run integration tests or not.' |
| 32 | + required: true |
| 33 | + type: boolean |
| 34 | + upload_artifact: |
| 35 | + description: 'Dertermines whether we upload the artifact not.' |
| 36 | + required: true |
| 37 | + type: boolean |
| 38 | + |
| 39 | +jobs: |
| 40 | + # ----------------------------------------------------------------------------------------------- |
| 41 | + # JOB: BUILD |
| 42 | + # ----------------------------------------------------------------------------------------------- |
| 43 | + build: |
| 44 | + name: ${{ matrix.name }}-${{ matrix.version }}-${{ inputs.flavour }} (${{ matrix.arch }}) ${{ matrix.refs }} |
| 45 | + runs-on: ubuntu-latest |
| 46 | + strategy: |
| 47 | + fail-fast: false |
| 48 | + matrix: |
| 49 | + include: ${{ fromJson(inputs.matrix) }} |
| 50 | + steps: |
| 51 | + |
| 52 | + # ------------------------------------------------------------ |
| 53 | + # Setup repository |
| 54 | + # ------------------------------------------------------------ |
| 55 | + - name: "[SETUP] Checkout repository (current)" |
| 56 | + uses: actions/checkout@v3 |
| 57 | + with: |
| 58 | + fetch-depth: 0 |
| 59 | + if: inputs.has_refs == 0 |
| 60 | + |
| 61 | + - name: "[SETUP] Checkout repository (ref: ${{ matrix.refs }})" |
| 62 | + uses: actions/checkout@v3 |
| 63 | + with: |
| 64 | + fetch-depth: 0 |
| 65 | + ref: ${{ matrix.refs }} |
| 66 | + if: inputs.has_refs != 0 |
| 67 | + |
| 68 | + - name: "[SETUP] Setup QEMU environment" |
| 69 | + uses: docker/setup-qemu-action@v1 |
| 70 | + with: |
| 71 | + image: tonistiigi/binfmt:latest |
| 72 | + platforms: all |
| 73 | + |
| 74 | + - name: "[SETUP] Set artifact names" |
| 75 | + id: set-artifact-name |
| 76 | + run: | |
| 77 | + PRE_HASH="$( git rev-parse HEAD | head -c 10 )" |
| 78 | + VERSION="${{ matrix.version }}" |
| 79 | + ARCH="$( echo "${{ matrix.arch }}" | sed 's|/|-|g' )" |
| 80 | +
|
| 81 | + NAME_PREV="${{ inputs.artifact_prefix }}-${PRE_HASH}-${VERSION}-${ARCH}-${{ inputs.flavour_prev }}" |
| 82 | + NAME_CURR="${{ inputs.artifact_prefix }}-${PRE_HASH}-${VERSION}-${ARCH}-${{ inputs.flavour }}" |
| 83 | + echo "::set-output name=prev::${NAME_PREV}" |
| 84 | + echo "::set-output name=curr::${NAME_CURR}" |
| 85 | +
|
| 86 | +
|
| 87 | + # ------------------------------------------------------------ |
| 88 | + # Artifact Import |
| 89 | + # ------------------------------------------------------------ |
| 90 | + |
| 91 | + ### |
| 92 | + ### Download and import previously built image (if it exists) |
| 93 | + ### |
| 94 | + - name: "[Artifact Load] Download previously built image" |
| 95 | + uses: Wandalen/wretry.action@v1.0.11 |
| 96 | + with: |
| 97 | + action: actions/download-artifact@v3 |
| 98 | + with: | |
| 99 | + name: ${{ steps.set-artifact-name.outputs.prev }} |
| 100 | + attempt_limit: 20 |
| 101 | + attempt_delay: 10000 |
| 102 | + if: ${{ inputs.flavour_prev != '' }} |
| 103 | + |
| 104 | + - name: "[Artifact Load] Import previously built image" |
| 105 | + uses: cytopia/shell-command-retry-action@v0.1.2 |
| 106 | + with: |
| 107 | + command: | |
| 108 | + make load INFILE=${{ steps.set-artifact-name.outputs.prev }} |
| 109 | + if: ${{ inputs.flavour_prev != '' }} |
| 110 | + |
| 111 | + |
| 112 | + # ------------------------------------------------------------ |
| 113 | + # Build |
| 114 | + # ------------------------------------------------------------ |
| 115 | + - name: Build |
| 116 | + uses: cytopia/shell-command-retry-action@v0.1.2 |
| 117 | + with: |
| 118 | + command: | |
| 119 | + make build VERSION=${{ matrix.version }} FLAVOUR=${{ inputs.flavour }} ARCH=${{ matrix.arch }} |
| 120 | +
|
| 121 | +
|
| 122 | + # ------------------------------------------------------------ |
| 123 | + # Test |
| 124 | + # ------------------------------------------------------------ |
| 125 | + - name: Test |
| 126 | + uses: cytopia/shell-command-retry-action@v0.1.2 |
| 127 | + with: |
| 128 | + command: | |
| 129 | + make test VERSION=${{ matrix.version }} FLAVOUR=${{ inputs.flavour }} ARCH=${{ matrix.arch }} |
| 130 | + if: ${{ inputs.run_tests }} |
| 131 | + |
| 132 | + |
| 133 | + # ------------------------------------------------------------ |
| 134 | + # Artifact Export |
| 135 | + # ------------------------------------------------------------ |
| 136 | + |
| 137 | + ### |
| 138 | + ### Export current image |
| 139 | + ### |
| 140 | + - name: "[Artifact Save] Export currently built image" |
| 141 | + uses: cytopia/shell-command-retry-action@v0.1.2 |
| 142 | + with: |
| 143 | + command: | |
| 144 | + make save-verify VERSION=${{ matrix.version }} FLAVOUR=${{ inputs.flavour }} ARCH=${{ matrix.arch }} OUTFILE=${{ steps.set-artifact-name.outputs.curr }} INFILE=${{ steps.set-artifact-name.outputs.curr }} |
| 145 | + if: ${{ inputs.upload_artifact }} |
| 146 | + |
| 147 | + ### |
| 148 | + ### Upload current image |
| 149 | + ### |
| 150 | + - name: "[Artifact Save] Upload currently built image" |
| 151 | + uses: Wandalen/wretry.action@v1.0.11 |
| 152 | + with: |
| 153 | + action: actions/upload-artifact@v3 |
| 154 | + with: | |
| 155 | + name: ${{ steps.set-artifact-name.outputs.curr }} |
| 156 | + path: ${{ steps.set-artifact-name.outputs.curr }} |
| 157 | + if-no-files-found: error |
| 158 | + attempt_limit: 20 |
| 159 | + attempt_delay: 10000 |
| 160 | + if: ${{ inputs.upload_artifact }} |
| 161 | + |
| 162 | + ### |
| 163 | + ### Verify uploaded image |
| 164 | + ### |
| 165 | + - name: "[Artifact Save] Download (verify)" |
| 166 | + uses: actions/download-artifact@v3 |
| 167 | + with: |
| 168 | + name: ${{ steps.set-artifact-name.outputs.curr }} |
| 169 | + path: ${{ steps.set-artifact-name.outputs.curr }}.tmp |
| 170 | + if: ${{ inputs.upload_artifact }} |
0 commit comments