github.com/opentofu/opentofu@v1.7.1/.github/workflows/build.yml (about)

     1  name: build
     2  
     3  # If you want to test changes to this file before merging to a main branch,
     4  # push them up to a branch whose name has the prefix "build-workflow-dev/",
     5  # which is a special prefix that triggers this workflow even though it's not
     6  # actually a release branch.
     7  
     8  on:
     9    workflow_dispatch:
    10    push:
    11      branches:
    12        - main
    13        - 'v[0-9]+.[0-9]+'
    14        - releng/**
    15      tags:
    16        - 'v[0-9]+.[0-9]+.[0-9]+*'
    17  
    18  env:
    19    PKG_NAME: "tofu"
    20  
    21  permissions:
    22    contents: read
    23    statuses: write
    24  
    25  jobs:
    26    get-product-version:
    27      name: "Determine intended OpenTofu version"
    28      runs-on: ubuntu-latest
    29      outputs:
    30        product-version: ${{ steps.get-product-version.outputs.product-version }}
    31        product-version-base: ${{ steps.get-product-version.outputs.base-product-version }}
    32        product-version-pre: ${{ steps.get-product-version.outputs.prerelease-product-version }}
    33        experiments: ${{ steps.get-ldflags.outputs.experiments }}
    34        go-ldflags: ${{ steps.get-ldflags.outputs.go-ldflags }}
    35        pkg-name: ${{ steps.get-pkg-name.outputs.pkg-name }}
    36  
    37      steps:
    38        - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
    39        - name: Get Package Name
    40          id: get-pkg-name
    41          run: |
    42            pkg_name=${{ env.PKG_NAME }}
    43            echo "pkg-name=${pkg_name}" | tee -a "${GITHUB_OUTPUT}"
    44        - name: Decide version number
    45          id: get-product-version
    46          uses: hashicorp/actions-set-product-version@v1
    47        - name: Determine experiments
    48          id: get-ldflags
    49          env:
    50            RAW_VERSION: ${{ steps.get-product-version.outputs.product-version }}
    51          shell: bash
    52          run: .github/scripts/get_product_version.sh
    53        - name: Report chosen version number
    54          run: |
    55            [ -n "${{steps.get-product-version.outputs.product-version}}" ]
    56            echo "::notice title=OpenTofu CLI Version::${{ steps.get-product-version.outputs.product-version }}"
    57  
    58    get-go-version:
    59      name: "Determine Go toolchain version"
    60      runs-on: ubuntu-latest
    61      outputs:
    62        go-version: ${{ steps.get-go-version.outputs.version }}
    63  
    64      steps:
    65        - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
    66        - name: Determine Go version
    67          id: get-go-version
    68          uses: ./.github/actions/go-version
    69  
    70    generate-metadata-file:
    71      name: "Generate release metadata"
    72      runs-on: ubuntu-latest
    73      needs: get-product-version
    74      outputs:
    75        filepath: ${{ steps.generate-metadata-file.outputs.filepath }}
    76  
    77      steps:
    78        - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
    79        - name: Generate package metadata
    80          id: generate-metadata-file
    81          uses: hashicorp/actions-generate-metadata@v1
    82          with:
    83            version: ${{ needs.get-product-version.outputs.product-version }}
    84            product: ${{ env.PKG_NAME }}
    85  
    86        - uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
    87          with:
    88            name: metadata.json
    89            path: ${{ steps.generate-metadata-file.outputs.filepath }}
    90  
    91    build:
    92      name: Build for ${{ matrix.goos }}_${{ matrix.goarch }}
    93      needs:
    94        - get-product-version
    95        - get-go-version
    96      uses: ./.github/workflows/build-opentofu-oss.yml
    97      with:
    98        goarch: ${{ matrix.goarch }}
    99        goos: ${{ matrix.goos }}
   100        go-version: ${{ needs.get-go-version.outputs.go-version }}
   101        package-name: ${{ needs.get-product-version.outputs.pkg-name }}
   102        product-version: ${{ needs.get-product-version.outputs.product-version }}
   103        ld-flags: ${{ needs.get-product-version.outputs.go-ldflags }}
   104        cgo-enabled: ${{ matrix.cgo-enabled }}
   105        runson: ${{ matrix.runson }}
   106      secrets: inherit
   107      strategy:
   108        matrix:
   109          include:
   110            - {goos: "freebsd", goarch: "386", runson: "ubuntu-latest", cgo-enabled: "0"}
   111            - {goos: "freebsd", goarch: "amd64", runson: "ubuntu-latest", cgo-enabled: "0"}
   112            - {goos: "freebsd", goarch: "arm", runson: "ubuntu-latest", cgo-enabled: "0"}
   113            - {goos: "linux", goarch: "386", runson: "ubuntu-latest", cgo-enabled: "0"}
   114            - {goos: "linux", goarch: "amd64", runson: "ubuntu-latest", cgo-enabled: "0"}
   115            - {goos: "linux", goarch: "arm", runson: "ubuntu-latest", cgo-enabled: "0"}
   116            - {goos: "linux", goarch: "arm64", runson: "ubuntu-latest", cgo-enabled: "0"}
   117            - {goos: "openbsd", goarch: "386", runson: "ubuntu-latest", cgo-enabled: "0"}
   118            - {goos: "openbsd", goarch: "amd64", runson: "ubuntu-latest", cgo-enabled: "0"}
   119            - {goos: "solaris", goarch: "amd64", runson: "ubuntu-latest", cgo-enabled: "0"}
   120            - {goos: "windows", goarch: "386", runson: "ubuntu-latest", cgo-enabled: "0"}
   121            - {goos: "windows", goarch: "amd64", runson: "ubuntu-latest", cgo-enabled: "0"}
   122            - {goos: "darwin", goarch: "amd64", runson: "macos-latest", cgo-enabled: "1"}
   123            - {goos: "darwin", goarch: "arm64", runson: "macos-latest", cgo-enabled: "1"}
   124        fail-fast: false
   125  
   126    package-docker:
   127      name: Build Docker image for linux_${{ matrix.arch }}
   128      runs-on: ubuntu-latest
   129      needs:
   130        - get-product-version
   131        - build
   132      strategy:
   133        matrix:
   134          arch: ["amd64", "386", "arm", "arm64"]
   135        fail-fast: false
   136      env:
   137        repo: "opentofu"
   138        version: ${{needs.get-product-version.outputs.product-version}}
   139      steps:
   140        - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
   141        - name: Build Docker images
   142          uses: hashicorp/actions-docker-build@v1
   143          with:
   144            pkg_name: "opentofu_${{env.version}}"
   145            version: ${{env.version}}
   146            bin_name: tofu
   147            target: default
   148            arch: ${{matrix.arch}}
   149            dockerfile: .github/workflows/build-Dockerfile
   150            smoke_test: .github/scripts/verify_docker v${{ env.version }}
   151            tags: |
   152              docker.io/opentofu/${{env.repo}}:${{env.version}}
   153              public.ecr.aws/opentofu/${{env.repo}}:${{env.version}}
   154  
   155    e2etest-build:
   156      name: Build e2etest for ${{ matrix.goos }}_${{ matrix.goarch }}
   157      runs-on: ubuntu-latest
   158      outputs:
   159        e2e-cache-key: ${{ steps.set-cache-values.outputs.e2e-cache-key }}
   160        e2e-cache-path: ${{ steps.set-cache-values.outputs.e2e-cache-path }}
   161      needs:
   162        - get-product-version
   163        - get-go-version
   164      strategy:
   165        matrix:
   166          include:
   167            - {goos: "darwin", goarch: "amd64"}
   168            - {goos: "darwin", goarch: "arm64"}
   169            - {goos: "windows", goarch: "amd64"}
   170            - {goos: "windows", goarch: "386"}
   171            - {goos: "linux", goarch: "386"}
   172            - {goos: "linux", goarch: "amd64"}
   173            - {goos: linux, goarch: "arm"}
   174            - {goos: linux, goarch: "arm64"}
   175        fail-fast: false
   176  
   177      env:
   178        build_script: ./internal/command/e2etest/make-archive.sh
   179  
   180      steps:
   181        - name: Set Cache Values
   182          id: set-cache-values
   183          run: |
   184            cache_key=e2e-cache-${{ github.sha }}
   185            cache_path=internal/command/e2etest/build
   186            echo "e2e-cache-key=${cache_key}" | tee -a "${GITHUB_OUTPUT}"
   187            echo "e2e-cache-path=${cache_path}" | tee -a "${GITHUB_OUTPUT}"
   188        - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
   189  
   190        - name: Install Go toolchain
   191          uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
   192          with:
   193            go-version: ${{ needs.get-go-version.outputs.go-version }}
   194  
   195        - name: Build test harness package
   196          env:
   197            GOOS: ${{ matrix.goos }}
   198            GOARCH: ${{ matrix.goarch }}
   199            GO_LDFLAGS: ${{ needs.get-product-version.outputs.go-ldflags }}
   200          run: |
   201            # NOTE: This script reacts to the GOOS, GOARCH, and GO_LDFLAGS
   202            # environment variables defined above. The e2e test harness
   203            # needs to know the version we're building for so it can verify
   204            # that "tofu version" is returning that version number.
   205            bash ./internal/command/e2etest/make-archive.sh
   206  
   207        - name: Save test harness to cache
   208          uses: actions/cache/save@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
   209          with:
   210            path: ${{ steps.set-cache-values.outputs.e2e-cache-path }}
   211            key: ${{ steps.set-cache-values.outputs.e2e-cache-key }}_${{ matrix.goos }}_${{ matrix.goarch }}
   212  
   213    e2e-test:
   214      name: Run e2e test for ${{ matrix.goos }}_${{ matrix.goarch }}
   215      runs-on: ${{ matrix.runson }}
   216      needs:
   217        - get-product-version
   218        - build
   219        - e2etest-build
   220      strategy:
   221        matrix:
   222          include:
   223            - { runson: ubuntu-latest, goos: linux, goarch: "amd64" }
   224            - { runson: ubuntu-latest, goos: linux, goarch: "386" }
   225            - { runson: ubuntu-latest, goos: linux, goarch: "arm" }
   226            - { runson: ubuntu-latest, goos: linux, goarch: "arm64" }
   227            - { runson: macos-latest, goos: darwin, goarch: "amd64" }
   228            - { runson: windows-latest, goos: windows, goarch: "amd64" }
   229            - { runson: windows-latest, goos: windows, goarch: "386" }
   230        fail-fast: false
   231  
   232      env:
   233        os: ${{ matrix.goos }}
   234        arch: ${{ matrix.goarch }}
   235        version: ${{needs.get-product-version.outputs.product-version}}
   236  
   237      steps:
   238        # NOTE: This intentionally _does not_ check out the source code
   239        # for the commit/tag we're building, because by now we should
   240        # have everything we need in the combination of CLI release package
   241        # and e2etest package for this platform. (This helps ensure that we're
   242        # really testing the release package and not inadvertently testing a
   243        # fresh build from source.)
   244        - name: Checkout repo
   245          if: ${{ (matrix.goos == 'linux') || (matrix.goos == 'darwin') }}
   246          uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
   247        - name: "Restore cache"
   248          uses: actions/cache/restore@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
   249          id: e2etestpkg
   250          with:
   251            path: ${{ needs.e2etest-build.outputs.e2e-cache-path }}
   252            key: ${{ needs.e2etest-build.outputs.e2e-cache-key }}_${{ matrix.goos }}_${{ matrix.goarch }}
   253            fail-on-cache-miss: true
   254            enableCrossOsArchive: true
   255        - name: "Download OpenTofu CLI package"
   256          uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
   257          id: clipkg
   258          with:
   259            name: tofu_${{env.version}}_${{ env.os }}_${{ env.arch }}.zip
   260            path: .
   261        - name: Extract packages
   262          if: ${{ matrix.goos == 'windows' }}
   263          run: |
   264            unzip "${{ needs.e2etest-build.outputs.e2e-cache-path }}/tofu-e2etest_${{ env.os }}_${{ env.arch }}.zip"
   265            unzip "./tofu_${{env.version}}_${{ env.os }}_${{ env.arch }}.zip"
   266        - name: Set up QEMU
   267          uses: docker/setup-qemu-action@2b82ce82d56a2a04d2637cd93a637ae1b359c0a7 # v2.2.0
   268          if: ${{ contains(matrix.goarch, 'arm') }}
   269          with:
   270            platforms: all
   271        - name: Run E2E Tests (Darwin & Linux)
   272          id: get-product-version
   273          shell: bash
   274          if: ${{ (matrix.goos == 'linux') || (matrix.goos == 'darwin') }}
   275          env:
   276            e2e_cache_path: ${{ needs.e2etest-build.outputs.e2e-cache-path }}
   277          run: .github/scripts/e2e_test_linux_darwin.sh
   278        - name: Run E2E Tests (Windows)
   279          if: ${{ matrix.goos == 'windows' }}
   280          env:
   281            TF_ACC: 1
   282          shell: cmd
   283          run: e2etest.exe -test.v
   284  
   285  
   286    e2e-test-exec:
   287      name: Run tofu-exec test for linux amd64
   288      runs-on: ubuntu-latest
   289      needs:
   290        - get-product-version
   291        - get-go-version
   292        - build
   293  
   294      env:
   295        os: ${{ matrix.goos }}
   296        arch: ${{ matrix.goarch }}
   297        version: ${{needs.get-product-version.outputs.product-version}}
   298  
   299      steps:
   300        - name: Install Go toolchain
   301          uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
   302          with:
   303            go-version: ${{ needs.get-go-version.outputs.go-version }}
   304        - name: Download OpenTofu CLI package
   305          uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
   306          id: clipkg
   307          with:
   308            name: tofu_${{ env.version }}_linux_amd64.zip
   309            path: .
   310        - name: Checkout tofu-exec repo
   311          uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
   312          with:
   313            repository: opentofu/tofu-exec
   314            path: tofu-exec
   315        - name: Run tofu-exec end-to-end tests
   316          run: |
   317            FULL_RELEASE_VERSION="${{ env.version }}"
   318            unzip tofu_${FULL_RELEASE_VERSION}_linux_amd64.zip
   319            export TFEXEC_E2ETEST_TERRAFORM_PATH="$(pwd)/tofu"
   320            cd tofu-exec
   321            go test -race -timeout=30m -v ./tfexec/internal/e2etest