mirror of
https://github.com/opentofu/setup-opentofu.git
synced 2025-12-05 23:34:45 +00:00
commit
6b016a1db7
25 changed files with 22588 additions and 1 deletions
6
.github/dependabot.yml
vendored
Normal file
6
.github/dependabot.yml
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "npm"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
19
.github/workflows/continuous-integration.yml
vendored
Normal file
19
.github/workflows/continuous-integration.yml
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
name: 'Continuous Integration'
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
check-dist:
|
||||
name: Check dist/ directory
|
||||
uses: actions/reusable-workflows/.github/workflows/check-dist.yml@967035ce963867fb956a309c9b67512314bc7c1f
|
||||
with:
|
||||
node-version: "20.x"
|
||||
test:
|
||||
name: Test
|
||||
uses: actions/reusable-workflows/.github/workflows/basic-validation.yml@967035ce963867fb956a309c9b67512314bc7c1f
|
||||
with:
|
||||
node-version: "20.x"
|
||||
3
.github/workflows/data/local/main.tf
vendored
Normal file
3
.github/workflows/data/local/main.tf
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
resource "terraform_data" "replacement" {
|
||||
triggers_replace = timestamp()
|
||||
}
|
||||
184
.github/workflows/setup-tofu.yml
vendored
Normal file
184
.github/workflows/setup-tofu.yml
vendored
Normal file
|
|
@ -0,0 +1,184 @@
|
|||
name: 'Setup OpenTofu'
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
jobs:
|
||||
tofu-versions:
|
||||
name: 'OpenTofu Versions'
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
tofu-versions: [1.6.0-alpha1, latest]
|
||||
tofu-wrapper: [true, false]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup OpenTofu - ${{ matrix['tofu-versions'] }}
|
||||
uses: ./
|
||||
with:
|
||||
tofu_version: ${{ matrix['tofu-versions'] }}
|
||||
tofu_wrapper: ${{ matrix['tofu-wrapper'] }}
|
||||
|
||||
- name: Validate that OpenTofu was installed
|
||||
run: tofu version | grep 'OpenTofu v'
|
||||
|
||||
- name: Validate the Version ${{ matrix['tofu-versions'] }} was installed
|
||||
if: ${{ matrix['tofu-versions'] != 'latest' }}
|
||||
run: tofu version | grep ${{ matrix['tofu-versions']}}
|
||||
tofu-arguments:
|
||||
name: 'OpenTofu Arguments'
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
tofu-wrapper: [true, false]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup OpenTofu
|
||||
uses: ./
|
||||
with:
|
||||
tofu_wrapper: ${{ matrix['tofu-wrapper'] }}
|
||||
|
||||
- name: Check No Arguments
|
||||
run: tofu || exit 0
|
||||
|
||||
- name: Check Single Argument
|
||||
run: tofu help || exit 0
|
||||
|
||||
- name: Check Single Argument Hyphen
|
||||
run: tofu -help
|
||||
|
||||
- name: Check Single Argument Double Hyphen
|
||||
run: tofu --help
|
||||
|
||||
- name: Check Single Argument Subcommand
|
||||
run: tofu fmt -check
|
||||
|
||||
- name: Check Multiple Arguments Subcommand
|
||||
run: tofu fmt -check -list=true -no-color
|
||||
tofu-run-local:
|
||||
name: 'OpenTofu Run Local'
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
tofu-wrapper: [true, false]
|
||||
defaults:
|
||||
run:
|
||||
working-directory: ./.github/workflows/data/local
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup OpenTofu
|
||||
uses: ./
|
||||
with:
|
||||
tofu_wrapper: ${{ matrix['tofu-wrapper'] }}
|
||||
|
||||
- name: OpenTofu Init
|
||||
run: tofu init
|
||||
|
||||
- name: OpenTofu Format
|
||||
run: tofu fmt -check
|
||||
|
||||
- name: OpenTofu Plan
|
||||
id: plan
|
||||
run: tofu plan
|
||||
|
||||
- name: Print OpenTofu Plan
|
||||
if: ${{ matrix['tofu-wrapper'] == 'true' }}
|
||||
run: echo "${{ steps.plan.outputs.stdout }}"
|
||||
tofu-credentials-cloud:
|
||||
name: 'OpenTofu Cloud Credentials'
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
env:
|
||||
TF_CLOUD_API_TOKEN: 'XXXXXXXXXXXXXX.atlasv1.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup OpenTofu
|
||||
uses: ./
|
||||
with:
|
||||
cli_config_credentials_token: ${{ env.TF_CLOUD_API_TOKEN }}
|
||||
|
||||
- name: Validate OpenTofu Credentials (Windows)
|
||||
if: runner.os == 'Windows'
|
||||
run: |
|
||||
cat ${APPDATA}/tofu.rc | grep 'credentials "app.terraform.io"'
|
||||
cat ${APPDATA}/tofu.rc | grep 'token = "${{ env.TF_CLOUD_API_TOKEN }}"'
|
||||
|
||||
- name: Validate Teraform Credentials (Linux & macOS)
|
||||
if: runner.os != 'Windows'
|
||||
run: |
|
||||
cat ${HOME}/.tofurc | grep 'credentials "app.terraform.io"'
|
||||
cat ${HOME}/.tofurc | grep 'token = "${{ env.TF_CLOUD_API_TOKEN }}"'
|
||||
|
||||
tofu-credentials-enterprise:
|
||||
name: 'OpenTofu Enterprise Credentials'
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
env:
|
||||
TF_CLOUD_API_TOKEN: 'XXXXXXXXXXXXXX.atlasv1.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup OpenTofu
|
||||
uses: ./
|
||||
with:
|
||||
cli_config_credentials_hostname: 'tofu.example.com'
|
||||
cli_config_credentials_token: ${{ env.TF_CLOUD_API_TOKEN }}
|
||||
|
||||
- name: Validate OpenTofu Credentials (Windows)
|
||||
if: runner.os == 'Windows'
|
||||
run: |
|
||||
cat ${APPDATA}/tofu.rc | grep 'credentials "tofu.example.com"'
|
||||
cat ${APPDATA}/tofu.rc | grep 'token = "${{ env.TF_CLOUD_API_TOKEN }}"'
|
||||
|
||||
- name: Validate Teraform Credentials (Linux & macOS)
|
||||
if: runner.os != 'Windows'
|
||||
run: |
|
||||
cat ${HOME}/.tofurc | grep 'credentials "tofu.example.com"'
|
||||
cat ${HOME}/.tofurc | grep 'token = "${{ env.TF_CLOUD_API_TOKEN }}"'
|
||||
|
||||
tofu-credentials-none:
|
||||
name: 'OpenTofu No Credentials'
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup OpenTofu
|
||||
uses: ./
|
||||
|
||||
- name: Validate OpenTofu Credentials (Windows)
|
||||
if: runner.os == 'Windows'
|
||||
run: |
|
||||
[[ -f ${APPDATA}/tofu.rc ]] || exit 0
|
||||
|
||||
- name: Validate Teraform Credentials (Linux & macOS)
|
||||
if: runner.os != 'Windows'
|
||||
run: |
|
||||
[[ -f ${HOME}/.tofurc ]] || exit 0
|
||||
|
||||
52
.gitignore
vendored
Normal file
52
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
node_modules/
|
||||
|
||||
# Editors
|
||||
.vscode
|
||||
.idea/
|
||||
.iml
|
||||
|
||||
# Logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Other Dependency directories
|
||||
jspm_packages/
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
|
||||
# ./wrapper/dist gets included in top-level ./dist
|
||||
wrapper/dist
|
||||
1
.husky/.gitignore
vendored
Normal file
1
.husky/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
_
|
||||
7
.husky/pre-commit
Executable file
7
.husky/pre-commit
Executable file
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
npm run lint || (npm install && npm run lint)
|
||||
npm run test
|
||||
npm audit --audit-level=high
|
||||
npm run build && git add dist/
|
||||
3
CHANGELOG.md
Normal file
3
CHANGELOG.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
## Unreleased
|
||||
|
||||
Initial release. It provides feature parity with the [setup-terraform](https://github.com/hashicorp/setup-terraform) action.
|
||||
7
CODEOWNERS
Normal file
7
CODEOWNERS
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# Each line is a file pattern followed by one or more owners.
|
||||
# More on CODEOWNERS files: https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners
|
||||
|
||||
# We currently do not have any specific code owners
|
||||
# In the future, we will have a Github team of global code owners of the entire package
|
||||
# Later on, we will start splitting up the responsibilities, and packages will be assigned more specific code owners
|
||||
# * @opentofu-code-owners
|
||||
10
CODE_OF_CONDUCT.md
Normal file
10
CODE_OF_CONDUCT.md
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# Code of Conduct
|
||||
|
||||
We follow the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/main/code-of-conduct.md).
|
||||
|
||||
<!-- TODO: Decide who will handle Code of Conduct reports and replace [INSERT EMAIL ADDRESS]
|
||||
with an email address in the paragraph below. We recommend using a mailing list to handle reports.
|
||||
If your project isn't prepared to handle reports, remove the project email address and just have
|
||||
reporters send to conduct@cncf.io.
|
||||
-->
|
||||
Please contact contact@opentf.org in order to report violations of the Code of Conduct.
|
||||
376
LICENSE
Normal file
376
LICENSE
Normal file
|
|
@ -0,0 +1,376 @@
|
|||
Copyright (c) 2020 HashiCorp, Inc.
|
||||
|
||||
Mozilla Public License Version 2.0
|
||||
==================================
|
||||
|
||||
1. Definitions
|
||||
--------------
|
||||
|
||||
1.1. "Contributor"
|
||||
means each individual or legal entity that creates, contributes to
|
||||
the creation of, or owns Covered Software.
|
||||
|
||||
1.2. "Contributor Version"
|
||||
means the combination of the Contributions of others (if any) used
|
||||
by a Contributor and that particular Contributor's Contribution.
|
||||
|
||||
1.3. "Contribution"
|
||||
means Covered Software of a particular Contributor.
|
||||
|
||||
1.4. "Covered Software"
|
||||
means Source Code Form to which the initial Contributor has attached
|
||||
the notice in Exhibit A, the Executable Form of such Source Code
|
||||
Form, and Modifications of such Source Code Form, in each case
|
||||
including portions thereof.
|
||||
|
||||
1.5. "Incompatible With Secondary Licenses"
|
||||
means
|
||||
|
||||
(a) that the initial Contributor has attached the notice described
|
||||
in Exhibit B to the Covered Software; or
|
||||
|
||||
(b) that the Covered Software was made available under the terms of
|
||||
version 1.1 or earlier of the License, but not also under the
|
||||
terms of a Secondary License.
|
||||
|
||||
1.6. "Executable Form"
|
||||
means any form of the work other than Source Code Form.
|
||||
|
||||
1.7. "Larger Work"
|
||||
means a work that combines Covered Software with other material, in
|
||||
a separate file or files, that is not Covered Software.
|
||||
|
||||
1.8. "License"
|
||||
means this document.
|
||||
|
||||
1.9. "Licensable"
|
||||
means having the right to grant, to the maximum extent possible,
|
||||
whether at the time of the initial grant or subsequently, any and
|
||||
all of the rights conveyed by this License.
|
||||
|
||||
1.10. "Modifications"
|
||||
means any of the following:
|
||||
|
||||
(a) any file in Source Code Form that results from an addition to,
|
||||
deletion from, or modification of the contents of Covered
|
||||
Software; or
|
||||
|
||||
(b) any new file in Source Code Form that contains any Covered
|
||||
Software.
|
||||
|
||||
1.11. "Patent Claims" of a Contributor
|
||||
means any patent claim(s), including without limitation, method,
|
||||
process, and apparatus claims, in any patent Licensable by such
|
||||
Contributor that would be infringed, but for the grant of the
|
||||
License, by the making, using, selling, offering for sale, having
|
||||
made, import, or transfer of either its Contributions or its
|
||||
Contributor Version.
|
||||
|
||||
1.12. "Secondary License"
|
||||
means either the GNU General Public License, Version 2.0, the GNU
|
||||
Lesser General Public License, Version 2.1, the GNU Affero General
|
||||
Public License, Version 3.0, or any later versions of those
|
||||
licenses.
|
||||
|
||||
1.13. "Source Code Form"
|
||||
means the form of the work preferred for making modifications.
|
||||
|
||||
1.14. "You" (or "Your")
|
||||
means an individual or a legal entity exercising rights under this
|
||||
License. For legal entities, "You" includes any entity that
|
||||
controls, is controlled by, or is under common control with You. For
|
||||
purposes of this definition, "control" means (a) the power, direct
|
||||
or indirect, to cause the direction or management of such entity,
|
||||
whether by contract or otherwise, or (b) ownership of more than
|
||||
fifty percent (50%) of the outstanding shares or beneficial
|
||||
ownership of such entity.
|
||||
|
||||
2. License Grants and Conditions
|
||||
--------------------------------
|
||||
|
||||
2.1. Grants
|
||||
|
||||
Each Contributor hereby grants You a world-wide, royalty-free,
|
||||
non-exclusive license:
|
||||
|
||||
(a) under intellectual property rights (other than patent or trademark)
|
||||
Licensable by such Contributor to use, reproduce, make available,
|
||||
modify, display, perform, distribute, and otherwise exploit its
|
||||
Contributions, either on an unmodified basis, with Modifications, or
|
||||
as part of a Larger Work; and
|
||||
|
||||
(b) under Patent Claims of such Contributor to make, use, sell, offer
|
||||
for sale, have made, import, and otherwise transfer either its
|
||||
Contributions or its Contributor Version.
|
||||
|
||||
2.2. Effective Date
|
||||
|
||||
The licenses granted in Section 2.1 with respect to any Contribution
|
||||
become effective for each Contribution on the date the Contributor first
|
||||
distributes such Contribution.
|
||||
|
||||
2.3. Limitations on Grant Scope
|
||||
|
||||
The licenses granted in this Section 2 are the only rights granted under
|
||||
this License. No additional rights or licenses will be implied from the
|
||||
distribution or licensing of Covered Software under this License.
|
||||
Notwithstanding Section 2.1(b) above, no patent license is granted by a
|
||||
Contributor:
|
||||
|
||||
(a) for any code that a Contributor has removed from Covered Software;
|
||||
or
|
||||
|
||||
(b) for infringements caused by: (i) Your and any other third party's
|
||||
modifications of Covered Software, or (ii) the combination of its
|
||||
Contributions with other software (except as part of its Contributor
|
||||
Version); or
|
||||
|
||||
(c) under Patent Claims infringed by Covered Software in the absence of
|
||||
its Contributions.
|
||||
|
||||
This License does not grant any rights in the trademarks, service marks,
|
||||
or logos of any Contributor (except as may be necessary to comply with
|
||||
the notice requirements in Section 3.4).
|
||||
|
||||
2.4. Subsequent Licenses
|
||||
|
||||
No Contributor makes additional grants as a result of Your choice to
|
||||
distribute the Covered Software under a subsequent version of this
|
||||
License (see Section 10.2) or under the terms of a Secondary License (if
|
||||
permitted under the terms of Section 3.3).
|
||||
|
||||
2.5. Representation
|
||||
|
||||
Each Contributor represents that the Contributor believes its
|
||||
Contributions are its original creation(s) or it has sufficient rights
|
||||
to grant the rights to its Contributions conveyed by this License.
|
||||
|
||||
2.6. Fair Use
|
||||
|
||||
This License is not intended to limit any rights You have under
|
||||
applicable copyright doctrines of fair use, fair dealing, or other
|
||||
equivalents.
|
||||
|
||||
2.7. Conditions
|
||||
|
||||
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
|
||||
in Section 2.1.
|
||||
|
||||
3. Responsibilities
|
||||
-------------------
|
||||
|
||||
3.1. Distribution of Source Form
|
||||
|
||||
All distribution of Covered Software in Source Code Form, including any
|
||||
Modifications that You create or to which You contribute, must be under
|
||||
the terms of this License. You must inform recipients that the Source
|
||||
Code Form of the Covered Software is governed by the terms of this
|
||||
License, and how they can obtain a copy of this License. You may not
|
||||
attempt to alter or restrict the recipients' rights in the Source Code
|
||||
Form.
|
||||
|
||||
3.2. Distribution of Executable Form
|
||||
|
||||
If You distribute Covered Software in Executable Form then:
|
||||
|
||||
(a) such Covered Software must also be made available in Source Code
|
||||
Form, as described in Section 3.1, and You must inform recipients of
|
||||
the Executable Form how they can obtain a copy of such Source Code
|
||||
Form by reasonable means in a timely manner, at a charge no more
|
||||
than the cost of distribution to the recipient; and
|
||||
|
||||
(b) You may distribute such Executable Form under the terms of this
|
||||
License, or sublicense it under different terms, provided that the
|
||||
license for the Executable Form does not attempt to limit or alter
|
||||
the recipients' rights in the Source Code Form under this License.
|
||||
|
||||
3.3. Distribution of a Larger Work
|
||||
|
||||
You may create and distribute a Larger Work under terms of Your choice,
|
||||
provided that You also comply with the requirements of this License for
|
||||
the Covered Software. If the Larger Work is a combination of Covered
|
||||
Software with a work governed by one or more Secondary Licenses, and the
|
||||
Covered Software is not Incompatible With Secondary Licenses, this
|
||||
License permits You to additionally distribute such Covered Software
|
||||
under the terms of such Secondary License(s), so that the recipient of
|
||||
the Larger Work may, at their option, further distribute the Covered
|
||||
Software under the terms of either this License or such Secondary
|
||||
License(s).
|
||||
|
||||
3.4. Notices
|
||||
|
||||
You may not remove or alter the substance of any license notices
|
||||
(including copyright notices, patent notices, disclaimers of warranty,
|
||||
or limitations of liability) contained within the Source Code Form of
|
||||
the Covered Software, except that You may alter any license notices to
|
||||
the extent required to remedy known factual inaccuracies.
|
||||
|
||||
3.5. Application of Additional Terms
|
||||
|
||||
You may choose to offer, and to charge a fee for, warranty, support,
|
||||
indemnity or liability obligations to one or more recipients of Covered
|
||||
Software. However, You may do so only on Your own behalf, and not on
|
||||
behalf of any Contributor. You must make it absolutely clear that any
|
||||
such warranty, support, indemnity, or liability obligation is offered by
|
||||
You alone, and You hereby agree to indemnify every Contributor for any
|
||||
liability incurred by such Contributor as a result of warranty, support,
|
||||
indemnity or liability terms You offer. You may include additional
|
||||
disclaimers of warranty and limitations of liability specific to any
|
||||
jurisdiction.
|
||||
|
||||
4. Inability to Comply Due to Statute or Regulation
|
||||
---------------------------------------------------
|
||||
|
||||
If it is impossible for You to comply with any of the terms of this
|
||||
License with respect to some or all of the Covered Software due to
|
||||
statute, judicial order, or regulation then You must: (a) comply with
|
||||
the terms of this License to the maximum extent possible; and (b)
|
||||
describe the limitations and the code they affect. Such description must
|
||||
be placed in a text file included with all distributions of the Covered
|
||||
Software under this License. Except to the extent prohibited by statute
|
||||
or regulation, such description must be sufficiently detailed for a
|
||||
recipient of ordinary skill to be able to understand it.
|
||||
|
||||
5. Termination
|
||||
--------------
|
||||
|
||||
5.1. The rights granted under this License will terminate automatically
|
||||
if You fail to comply with any of its terms. However, if You become
|
||||
compliant, then the rights granted under this License from a particular
|
||||
Contributor are reinstated (a) provisionally, unless and until such
|
||||
Contributor explicitly and finally terminates Your grants, and (b) on an
|
||||
ongoing basis, if such Contributor fails to notify You of the
|
||||
non-compliance by some reasonable means prior to 60 days after You have
|
||||
come back into compliance. Moreover, Your grants from a particular
|
||||
Contributor are reinstated on an ongoing basis if such Contributor
|
||||
notifies You of the non-compliance by some reasonable means, this is the
|
||||
first time You have received notice of non-compliance with this License
|
||||
from such Contributor, and You become compliant prior to 30 days after
|
||||
Your receipt of the notice.
|
||||
|
||||
5.2. If You initiate litigation against any entity by asserting a patent
|
||||
infringement claim (excluding declaratory judgment actions,
|
||||
counter-claims, and cross-claims) alleging that a Contributor Version
|
||||
directly or indirectly infringes any patent, then the rights granted to
|
||||
You by any and all Contributors for the Covered Software under Section
|
||||
2.1 of this License shall terminate.
|
||||
|
||||
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
|
||||
end user license agreements (excluding distributors and resellers) which
|
||||
have been validly granted by You or Your distributors under this License
|
||||
prior to termination shall survive termination.
|
||||
|
||||
************************************************************************
|
||||
* *
|
||||
* 6. Disclaimer of Warranty *
|
||||
* ------------------------- *
|
||||
* *
|
||||
* Covered Software is provided under this License on an "as is" *
|
||||
* basis, without warranty of any kind, either expressed, implied, or *
|
||||
* statutory, including, without limitation, warranties that the *
|
||||
* Covered Software is free of defects, merchantable, fit for a *
|
||||
* particular purpose or non-infringing. The entire risk as to the *
|
||||
* quality and performance of the Covered Software is with You. *
|
||||
* Should any Covered Software prove defective in any respect, You *
|
||||
* (not any Contributor) assume the cost of any necessary servicing, *
|
||||
* repair, or correction. This disclaimer of warranty constitutes an *
|
||||
* essential part of this License. No use of any Covered Software is *
|
||||
* authorized under this License except under this disclaimer. *
|
||||
* *
|
||||
************************************************************************
|
||||
|
||||
************************************************************************
|
||||
* *
|
||||
* 7. Limitation of Liability *
|
||||
* -------------------------- *
|
||||
* *
|
||||
* Under no circumstances and under no legal theory, whether tort *
|
||||
* (including negligence), contract, or otherwise, shall any *
|
||||
* Contributor, or anyone who distributes Covered Software as *
|
||||
* permitted above, be liable to You for any direct, indirect, *
|
||||
* special, incidental, or consequential damages of any character *
|
||||
* including, without limitation, damages for lost profits, loss of *
|
||||
* goodwill, work stoppage, computer failure or malfunction, or any *
|
||||
* and all other commercial damages or losses, even if such party *
|
||||
* shall have been informed of the possibility of such damages. This *
|
||||
* limitation of liability shall not apply to liability for death or *
|
||||
* personal injury resulting from such party's negligence to the *
|
||||
* extent applicable law prohibits such limitation. Some *
|
||||
* jurisdictions do not allow the exclusion or limitation of *
|
||||
* incidental or consequential damages, so this exclusion and *
|
||||
* limitation may not apply to You. *
|
||||
* *
|
||||
************************************************************************
|
||||
|
||||
8. Litigation
|
||||
-------------
|
||||
|
||||
Any litigation relating to this License may be brought only in the
|
||||
courts of a jurisdiction where the defendant maintains its principal
|
||||
place of business and such litigation shall be governed by laws of that
|
||||
jurisdiction, without reference to its conflict-of-law provisions.
|
||||
Nothing in this Section shall prevent a party's ability to bring
|
||||
cross-claims or counter-claims.
|
||||
|
||||
9. Miscellaneous
|
||||
----------------
|
||||
|
||||
This License represents the complete agreement concerning the subject
|
||||
matter hereof. If any provision of this License is held to be
|
||||
unenforceable, such provision shall be reformed only to the extent
|
||||
necessary to make it enforceable. Any law or regulation which provides
|
||||
that the language of a contract shall be construed against the drafter
|
||||
shall not be used to construe this License against a Contributor.
|
||||
|
||||
10. Versions of the License
|
||||
---------------------------
|
||||
|
||||
10.1. New Versions
|
||||
|
||||
Mozilla Foundation is the license steward. Except as provided in Section
|
||||
10.3, no one other than the license steward has the right to modify or
|
||||
publish new versions of this License. Each version will be given a
|
||||
distinguishing version number.
|
||||
|
||||
10.2. Effect of New Versions
|
||||
|
||||
You may distribute the Covered Software under the terms of the version
|
||||
of the License under which You originally received the Covered Software,
|
||||
or under the terms of any subsequent version published by the license
|
||||
steward.
|
||||
|
||||
10.3. Modified Versions
|
||||
|
||||
If you create software not governed by this License, and you want to
|
||||
create a new license for such software, you may create and use a
|
||||
modified version of this License if you rename the license and remove
|
||||
any references to the name of the license steward (except to note that
|
||||
such modified license differs from this License).
|
||||
|
||||
10.4. Distributing Source Code Form that is Incompatible With Secondary
|
||||
Licenses
|
||||
|
||||
If You choose to distribute Source Code Form that is Incompatible With
|
||||
Secondary Licenses under the terms of this version of the License, the
|
||||
notice described in Exhibit B of this License must be attached.
|
||||
|
||||
Exhibit A - Source Code Form License Notice
|
||||
-------------------------------------------
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla Public
|
||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
If it is not possible or desirable to put the notice in a particular
|
||||
file, then You may include the notice in a location (such as a LICENSE
|
||||
file in a relevant directory) where a recipient would be likely to look
|
||||
for such a notice.
|
||||
|
||||
You may add additional accurate notices of copyright ownership.
|
||||
|
||||
Exhibit B - "Incompatible With Secondary Licenses" Notice
|
||||
---------------------------------------------------------
|
||||
|
||||
This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
defined by the Mozilla Public License, v. 2.0.
|
||||
|
||||
277
README.md
277
README.md
|
|
@ -1 +1,276 @@
|
|||
# setup-opentofu WIP repo
|
||||
# setup-opentofu
|
||||
|
||||
The `opentofu/setup-opentofu` action sets up OpenTofu CLI in your GitHub Actions workflow by:
|
||||
|
||||
- Downloading the latest version of OpenTofu CLI and adding it to the `PATH`.
|
||||
- Configuring the [CLI configuration file](https://opentofu.org/docs/cli/config/config-file/) with a Terraform Cloud/Enterprise hostname and API token.
|
||||
- Installing a wrapper script to wrap subsequent calls of the `tofu` binary and expose its STDOUT, STDERR, and exit code as outputs named `stdout`, `stderr`, and `exitcode` respectively. (This can be optionally skipped if subsequent steps in the same job do not need to access the results of
|
||||
OpenTofu commands.)
|
||||
|
||||
After you've used the action, subsequent steps in the same job can run arbitrary OpenTofu commands using [the GitHub Actions `run` syntax](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun). This allows most OpenTofu commands to work exactly
|
||||
like they do on your local command line.
|
||||
|
||||
## Experimental Status
|
||||
|
||||
By using the software in this repository (the "Software"), you acknowledge that: (1) the Software is still in development, may change, and has not been released as a commercial product by OpenTofu; (2) the Software is provided on an "as-is" basis, and may include bugs, errors, or other issues; (3) the Software is NOT INTENDED FOR PRODUCTION USE, use of the Software may result in unexpected results, loss of data, or other unexpected results, and OpenTofu disclaims any and all liability resulting from use of the Software.
|
||||
|
||||
## Usage
|
||||
|
||||
This action can be run on `ubuntu-latest`, `windows-latest`, and `macos-latest` GitHub Actions runners. When running on `windows-latest` the shell should be set to Bash.
|
||||
|
||||
The default configuration installs the latest version of OpenTofu CLI and installs the wrapper script to wrap subsequent calls to the `tofu` binary:
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: opentofu/setup-opentofu
|
||||
```
|
||||
|
||||
A specific version of OpenTofu CLI can be installed:
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: opentofu/setup-opentofu
|
||||
with:
|
||||
tofu_version: 1.6.0-alpha1
|
||||
```
|
||||
|
||||
Credentials for Terraform Cloud ([app.terraform.io](https://app.terraform.io/)) can be configured:
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: opentofu/setup-opentofu
|
||||
with:
|
||||
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
|
||||
```
|
||||
|
||||
Credentials for Terraform Enterprise (TFE) can be configured:
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: opentofu/setup-opentofu
|
||||
with:
|
||||
cli_config_credentials_hostname: 'tofu.example.com'
|
||||
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
|
||||
```
|
||||
|
||||
The wrapper script installation can be skipped by setting the `tofu_wrapper` variable to `false`:
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: opentofu/setup-opentofu
|
||||
with:
|
||||
tofu_wrapper: false
|
||||
```
|
||||
|
||||
Subsequent steps can access outputs when the wrapper script is installed:
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: opentofu/setup-opentofu
|
||||
|
||||
- run: tofu init
|
||||
|
||||
- id: plan
|
||||
run: tofu plan -no-color
|
||||
|
||||
- run: echo ${{ steps.plan.outputs.stdout }}
|
||||
- run: echo ${{ steps.plan.outputs.stderr }}
|
||||
- run: echo ${{ steps.plan.outputs.exitcode }}
|
||||
```
|
||||
|
||||
Outputs can be used in subsequent steps to comment on the pull request:
|
||||
|
||||
> **Notice:** There's a limit to the number of characters inside a GitHub comment (65535).
|
||||
>
|
||||
> Due to that limitation, you might end up with a failed workflow run even if the plan succeeded.
|
||||
>
|
||||
> Another approach is to append your plan into the $GITHUB_STEP_SUMMARY environment variable which supports markdown.
|
||||
|
||||
```yaml
|
||||
defaults:
|
||||
run:
|
||||
working-directory: ${{ env.tf_actions_working_dir }}
|
||||
permissions:
|
||||
pull-requests: write
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: opentofu/setup-opentofu
|
||||
|
||||
- name: OpenTofu fmt
|
||||
id: fmt
|
||||
run: tofu fmt -check
|
||||
continue-on-error: true
|
||||
|
||||
- name: OpenTofu Init
|
||||
id: init
|
||||
run: tofu init
|
||||
|
||||
- name: OpenTofu Validate
|
||||
id: validate
|
||||
run: tofu validate -no-color
|
||||
|
||||
- name: OpenTofu Plan
|
||||
id: plan
|
||||
run: tofu plan -no-color
|
||||
continue-on-error: true
|
||||
|
||||
- uses: actions/github-script@v6
|
||||
if: github.event_name == 'pull_request'
|
||||
env:
|
||||
PLAN: "tofu\n${{ steps.plan.outputs.stdout }}"
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
const output = `#### OpenTofu Format and Style 🖌\`${{ steps.fmt.outcome }}\`
|
||||
#### OpenTofu Initialization ⚙️\`${{ steps.init.outcome }}\`
|
||||
#### OpenTofu Validation 🤖\`${{ steps.validate.outcome }}\`
|
||||
<details><summary>Validation Output</summary>
|
||||
|
||||
\`\`\`\n
|
||||
${{ steps.validate.outputs.stdout }}
|
||||
\`\`\`
|
||||
|
||||
</details>
|
||||
|
||||
#### OpenTofu Plan 📖\`${{ steps.plan.outcome }}\`
|
||||
|
||||
<details><summary>Show Plan</summary>
|
||||
|
||||
\`\`\`\n
|
||||
${process.env.PLAN}
|
||||
\`\`\`
|
||||
|
||||
</details>
|
||||
|
||||
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.tf_actions_working_dir }}\`, Workflow: \`${{ github.workflow }}\`*`;
|
||||
|
||||
github.rest.issues.createComment({
|
||||
issue_number: context.issue.number,
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
body: output
|
||||
})
|
||||
```
|
||||
|
||||
Instead of creating a new comment each time, you can also update an existing one:
|
||||
|
||||
```yaml
|
||||
defaults:
|
||||
run:
|
||||
working-directory: ${{ env.tf_actions_working_dir }}
|
||||
permissions:
|
||||
pull-requests: write
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: opentofu/setup-opentofu
|
||||
|
||||
- name: OpenTofu fmt
|
||||
id: fmt
|
||||
run: tofu fmt -check
|
||||
continue-on-error: true
|
||||
|
||||
- name: OpenTofu Init
|
||||
id: init
|
||||
run: tofu init
|
||||
|
||||
- name: OpenTofu Validate
|
||||
id: validate
|
||||
run: tofu validate -no-color
|
||||
|
||||
- name: OpenTofu Plan
|
||||
id: plan
|
||||
run: tofu plan -no-color
|
||||
continue-on-error: true
|
||||
|
||||
- uses: actions/github-script@v6
|
||||
if: github.event_name == 'pull_request'
|
||||
env:
|
||||
PLAN: "tofu\n${{ steps.plan.outputs.stdout }}"
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
// 1. Retrieve existing bot comments for the PR
|
||||
const { data: comments } = await github.rest.issues.listComments({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: context.issue.number,
|
||||
})
|
||||
const botComment = comments.find(comment => {
|
||||
return comment.user.type === 'Bot' && comment.body.includes('OpenTofu Format and Style')
|
||||
})
|
||||
|
||||
// 2. Prepare format of the comment
|
||||
const output = `#### OpenTofu Format and Style 🖌\`${{ steps.fmt.outcome }}\`
|
||||
#### OpenTofu Initialization ⚙️\`${{ steps.init.outcome }}\`
|
||||
#### OpenTofu Validation 🤖\`${{ steps.validate.outcome }}\`
|
||||
<details><summary>Validation Output</summary>
|
||||
|
||||
\`\`\`\n
|
||||
${{ steps.validate.outputs.stdout }}
|
||||
\`\`\`
|
||||
|
||||
</details>
|
||||
|
||||
#### OpenTofu Plan 📖\`${{ steps.plan.outcome }}\`
|
||||
|
||||
<details><summary>Show Plan</summary>
|
||||
|
||||
\`\`\`\n
|
||||
${process.env.PLAN}
|
||||
\`\`\`
|
||||
|
||||
</details>
|
||||
|
||||
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.tf_actions_working_dir }}\`, Workflow: \`${{ github.workflow }}\`*`;
|
||||
|
||||
// 3. If we have a comment, update it, otherwise create a new one
|
||||
if (botComment) {
|
||||
github.rest.issues.updateComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
comment_id: botComment.id,
|
||||
body: output
|
||||
})
|
||||
} else {
|
||||
github.rest.issues.createComment({
|
||||
issue_number: context.issue.number,
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
body: output
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
## Inputs
|
||||
|
||||
The action supports the following inputs:
|
||||
|
||||
- `cli_config_credentials_hostname` - (optional) The hostname of a Terraform Cloud/Enterprise instance to
|
||||
place within the credentials block of the OpenTofu CLI configuration file. Defaults to `app.terraform.io`.
|
||||
- `cli_config_credentials_token` - (optional) The API token for a Terraform Cloud/Enterprise instance to
|
||||
place within the credentials block of the OpenTofu CLI configuration file.
|
||||
- `tofu_version` - (optional) The version of OpenTofu CLI to install. Instead of a full version string,
|
||||
you can also specify a constraint string (see [Semver Ranges](https://www.npmjs.com/package/semver#ranges)
|
||||
for available range specifications). Examples are: `<1.6.0-beta`, `~1.6.0-alpha`, `1.6.0-alpha2` (all three installing
|
||||
the latest available `1.6.0-alpha2` version). Prerelease versions can be specified and a range will stay within the
|
||||
given tag such as `beta` or `rc`. If no version is given, it will default to `latest`.
|
||||
- `tofu_wrapper` - (optional) Whether to install a wrapper to wrap subsequent calls of
|
||||
the `tofu` binary and expose its STDOUT, STDERR, and exit code as outputs
|
||||
named `stdout`, `stderr`, and `exitcode` respectively. Defaults to `true`.
|
||||
|
||||
## Outputs
|
||||
|
||||
This action does not configure any outputs directly. However, when you set the `tofu_wrapper` input
|
||||
to `true`, the following outputs are available for subsequent steps that call the `tofu` binary:
|
||||
|
||||
- `stdout` - The STDOUT stream of the call to the `tofu` binary.
|
||||
- `stderr` - The STDERR stream of the call to the `tofu` binary.
|
||||
- `exitcode` - The exit code of the call to the `tofu` binary.
|
||||
|
||||
## License
|
||||
|
||||
[Mozilla Public License v2.0](LICENSE)
|
||||
|
||||
## Code of Conduct
|
||||
|
||||
[Code of Conduct](CODE_OF_CONDUCT.md)
|
||||
|
|
|
|||
36
action.yml
Normal file
36
action.yml
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
name: 'OpenTofu - Setup Tofu'
|
||||
description: 'Sets up OpenTofu CLI in your GitHub Actions workflow.'
|
||||
author: 'OpenTofu'
|
||||
inputs:
|
||||
cli_config_credentials_hostname:
|
||||
description: 'The hostname of a Terraform Cloud/Enterprise instance to place within the credentials block of the OpenTofu CLI configuration file. Defaults to `app.terraform.io`.'
|
||||
default: 'app.terraform.io'
|
||||
required: false
|
||||
cli_config_credentials_token:
|
||||
description: 'The API token for a Terraform Cloud/Enterprise instance to place within the credentials block of the OpenTofu CLI configuration file.'
|
||||
required: false
|
||||
tofu_version:
|
||||
description: 'The version of OpenTofu CLI to install. If no version is given, it will default to `latest`.'
|
||||
default: 'latest'
|
||||
required: false
|
||||
tofu_wrapper:
|
||||
description: 'Whether or not to install a wrapper to wrap subsequent calls of the `tofu` binary and expose its STDOUT, STDERR, and exit code as outputs named `stdout`, `stderr`, and `exitcode` respectively. Defaults to `true`.'
|
||||
default: 'true'
|
||||
required: false
|
||||
outputs:
|
||||
stdout:
|
||||
description: 'The STDOUT stream of the call to the `tofu` binary.'
|
||||
value: ''
|
||||
stderr:
|
||||
description: 'The STDERR stream of the call to the `tofu` binary.'
|
||||
value: 'Wrapper was not activated'
|
||||
exitcode:
|
||||
description: 'The exit code of the call to the `tofu` binary.'
|
||||
value: '126'
|
||||
|
||||
branding:
|
||||
icon: 'terminal'
|
||||
color: 'purple'
|
||||
runs:
|
||||
using: 'node20'
|
||||
main: 'dist/index.js'
|
||||
10320
dist/index.js
vendored
Normal file
10320
dist/index.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
4242
dist/index1.js
vendored
Executable file
4242
dist/index1.js
vendored
Executable file
File diff suppressed because it is too large
Load diff
16
index.js
Normal file
16
index.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
const core = require('@actions/core');
|
||||
|
||||
const setup = require('./lib/setup-tofu');
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await setup();
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
})();
|
||||
100
lib/releases.js
Normal file
100
lib/releases.js
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
/**
|
||||
* Copyright (c) OpenTofu
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
class Build {
|
||||
constructor (name, url) {
|
||||
this.name = name;
|
||||
this.url = url;
|
||||
}
|
||||
}
|
||||
|
||||
class Release {
|
||||
constructor (releaseMeta) {
|
||||
this.version = releaseMeta.tag_name.replace('v', '');
|
||||
this.builds = releaseMeta.assets.map(asset => new Build(asset.name, asset.browser_download_url));
|
||||
}
|
||||
|
||||
getBuild (platform, arch) {
|
||||
const requiredName = `tofu_${this.version}_${platform}_${arch}.zip`;
|
||||
return this.builds.find(build => build.name === requiredName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the top 30 releases sorted in desc order.
|
||||
*
|
||||
* @return {Array<Release>} Releases.
|
||||
*/
|
||||
async function fetchReleases () {
|
||||
const url = 'https://api.github.com/repos/opentofu/opentofu/releases';
|
||||
|
||||
const resp = await fetch(url, {
|
||||
headers: {
|
||||
Accept: 'application/vnd.github+json',
|
||||
'X-GitHub-Api-Version': '2022-11-28'
|
||||
}
|
||||
});
|
||||
|
||||
if (!resp.ok) {
|
||||
throw new Error('failed fetching releases');
|
||||
}
|
||||
|
||||
const releasesMeta = await resp.json();
|
||||
|
||||
return releasesMeta.map(releaseMeta => new Release(releaseMeta));
|
||||
}
|
||||
|
||||
const semver = require('semver');
|
||||
|
||||
async function findLatestVersion (versions) {
|
||||
return versions.sort((a, b) => semver.rcompare(a, b))[0];
|
||||
}
|
||||
|
||||
async function findLatestVersionInRange (versions, range) {
|
||||
return semver.maxSatisfying(versions, range, { prerelease: true, loose: true });
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the release given the version.
|
||||
*
|
||||
* @param {string} version: Release version.
|
||||
* @param {function} fetchReleasesFn: Optional function to fetch releases.
|
||||
* @return {Release} Release.
|
||||
*/
|
||||
async function getRelease (version, fetchReleasesFn = fetchReleases) {
|
||||
const latestVersionLabel = 'latest';
|
||||
|
||||
const versionsRange = semver.validRange(version, { prerelease: true, loose: true });
|
||||
if (versionsRange === null && version !== latestVersionLabel) {
|
||||
throw new Error('Input version cannot be used, see semver: https://semver.org/spec/v2.0.0.html');
|
||||
}
|
||||
|
||||
const releases = await fetchReleasesFn();
|
||||
|
||||
if (releases === null || releases.length === 0) {
|
||||
throw new Error('No tofu releases found, please contact OpenTofu');
|
||||
}
|
||||
|
||||
const versionsFound = releases.map(release => release.version);
|
||||
let versionSelected;
|
||||
if (version === latestVersionLabel) {
|
||||
versionSelected = await findLatestVersion(versionsFound);
|
||||
} else {
|
||||
versionSelected = await findLatestVersionInRange(versionsFound, versionsRange);
|
||||
}
|
||||
|
||||
if (versionSelected === null) {
|
||||
throw new Error('No matching version found');
|
||||
}
|
||||
|
||||
return releases.find(release => release.version === versionSelected);
|
||||
}
|
||||
|
||||
// Note that the export is defined as adaptor to replace hashicorp/js-releases
|
||||
// See: https://github.com/hashicorp/setup-terraform/blob/e192cfcbae6c6ed207c277ed7624131996c9bf13/lib/setup-terraform.js#L15
|
||||
module.exports = {
|
||||
getRelease,
|
||||
Release
|
||||
};
|
||||
171
lib/setup-tofu.js
Normal file
171
lib/setup-tofu.js
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* Copyright (c) OpenTofu
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
// Node.js core
|
||||
const fs = require('fs').promises;
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
|
||||
// External
|
||||
const core = require('@actions/core');
|
||||
const tc = require('@actions/tool-cache');
|
||||
const io = require('@actions/io');
|
||||
const releases = require('./releases');
|
||||
|
||||
// arch in [arm, x32, x64...] (https://nodejs.org/api/os.html#os_os_arch)
|
||||
// return value in [amd64, 386, arm]
|
||||
function mapArch (arch) {
|
||||
const mappings = {
|
||||
x32: '386',
|
||||
x64: 'amd64'
|
||||
};
|
||||
return mappings[arch] || arch;
|
||||
}
|
||||
|
||||
// os in [darwin, linux, win32...] (https://nodejs.org/api/os.html#os_os_platform)
|
||||
// return value in [darwin, linux, windows]
|
||||
function mapOS (os) {
|
||||
if (os === 'win32') {
|
||||
return 'windows';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
async function downloadAndExtractCLI (url) {
|
||||
core.debug(`Downloading OpenTofu CLI from ${url}`);
|
||||
const pathToCLIZip = await tc.downloadTool(url);
|
||||
|
||||
if (!pathToCLIZip) {
|
||||
throw new Error(`Unable to download OpenTofu from ${url}`);
|
||||
}
|
||||
|
||||
let pathToCLI;
|
||||
|
||||
core.debug('Extracting OpenTofu CLI zip file');
|
||||
if (os.platform().startsWith('win')) {
|
||||
core.debug(`OpenTofu CLI Download Path is ${pathToCLIZip}`);
|
||||
const fixedPathToCLIZip = `${pathToCLIZip}.zip`;
|
||||
io.mv(pathToCLIZip, fixedPathToCLIZip);
|
||||
core.debug(`Moved download to ${fixedPathToCLIZip}`);
|
||||
pathToCLI = await tc.extractZip(fixedPathToCLIZip);
|
||||
} else {
|
||||
pathToCLI = await tc.extractZip(pathToCLIZip);
|
||||
}
|
||||
|
||||
core.debug(`OpenTofu CLI path is ${pathToCLI}.`);
|
||||
|
||||
if (!pathToCLI) {
|
||||
throw new Error('Unable to unzip OpenTofu');
|
||||
}
|
||||
|
||||
return pathToCLI;
|
||||
}
|
||||
|
||||
async function installWrapper (pathToCLI) {
|
||||
let source, target;
|
||||
|
||||
// If we're on Windows, then the executable ends with .exe
|
||||
const exeSuffix = os.platform().startsWith('win') ? '.exe' : '';
|
||||
|
||||
// Rename tofu(.exe) to tofu-bin(.exe)
|
||||
try {
|
||||
source = [pathToCLI, `tofu${exeSuffix}`].join(path.sep);
|
||||
target = [pathToCLI, `tofu-bin${exeSuffix}`].join(path.sep);
|
||||
core.debug(`Moving ${source} to ${target}.`);
|
||||
await io.mv(source, target);
|
||||
} catch (e) {
|
||||
core.error(`Unable to move ${source} to ${target}.`);
|
||||
throw e;
|
||||
}
|
||||
|
||||
// Install our wrapper as tofu
|
||||
try {
|
||||
source = path.resolve([__dirname, '..', 'wrapper', 'dist', 'index.js'].join(path.sep));
|
||||
target = [pathToCLI, 'tofu'].join(path.sep);
|
||||
core.debug(`Copying ${source} to ${target}.`);
|
||||
await io.cp(source, target);
|
||||
} catch (e) {
|
||||
core.error(`Unable to copy ${source} to ${target}.`);
|
||||
throw e;
|
||||
}
|
||||
|
||||
// Export a new environment variable, so our wrapper can locate the binary
|
||||
core.exportVariable('TOFU_CLI_PATH', pathToCLI);
|
||||
}
|
||||
|
||||
// Add credentials to CLI Configuration File
|
||||
// https://www.tofu.io/docs/commands/cli-config.html
|
||||
async function addCredentials (credentialsHostname, credentialsToken, osPlat) {
|
||||
// format HCL block
|
||||
// eslint-disable
|
||||
const creds = `
|
||||
credentials "${credentialsHostname}" {
|
||||
token = "${credentialsToken}"
|
||||
}`.trim();
|
||||
// eslint-enable
|
||||
|
||||
// default to OS-specific path
|
||||
let credsFile = osPlat === 'win32'
|
||||
? `${process.env.APPDATA}/tofu.rc`
|
||||
: `${process.env.HOME}/.tofurc`;
|
||||
|
||||
// override with TF_CLI_CONFIG_FILE environment variable
|
||||
credsFile = process.env.TF_CLI_CONFIG_FILE ? process.env.TF_CLI_CONFIG_FILE : credsFile;
|
||||
|
||||
// get containing folder
|
||||
const credsFolder = path.dirname(credsFile);
|
||||
|
||||
core.debug(`Creating ${credsFolder}`);
|
||||
await io.mkdirP(credsFolder);
|
||||
|
||||
core.debug(`Adding credentials to ${credsFile}`);
|
||||
await fs.writeFile(credsFile, creds);
|
||||
}
|
||||
|
||||
async function run () {
|
||||
try {
|
||||
// Gather GitHub Actions inputs
|
||||
const version = core.getInput('tofu_version');
|
||||
const credentialsHostname = core.getInput('cli_config_credentials_hostname');
|
||||
const credentialsToken = core.getInput('cli_config_credentials_token');
|
||||
const wrapper = core.getInput('tofu_wrapper') === 'true';
|
||||
|
||||
// Gather OS details
|
||||
const osPlatform = os.platform();
|
||||
const osArch = os.arch();
|
||||
|
||||
core.debug(`Finding releases for OpenTofu version ${version}`);
|
||||
const release = await releases.getRelease(version);
|
||||
const platform = mapOS(osPlatform);
|
||||
const arch = mapArch(osArch);
|
||||
const build = release.getBuild(platform, arch);
|
||||
if (!build) {
|
||||
throw new Error(`OpenTofu version ${version} not available for ${platform} and ${arch}`);
|
||||
}
|
||||
|
||||
// Download requested version
|
||||
const pathToCLI = await downloadAndExtractCLI(build.url);
|
||||
|
||||
// Install our wrapper
|
||||
if (wrapper) {
|
||||
await installWrapper(pathToCLI);
|
||||
}
|
||||
|
||||
// Add to path
|
||||
core.addPath(pathToCLI);
|
||||
|
||||
// Add credentials to file if they are provided
|
||||
if (credentialsHostname && credentialsToken) {
|
||||
await addCredentials(credentialsHostname, credentialsToken, osPlatform);
|
||||
}
|
||||
return release;
|
||||
} catch (error) {
|
||||
core.error(error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = run;
|
||||
219
lib/test/releases.test.js
Normal file
219
lib/test/releases.test.js
Normal file
|
|
@ -0,0 +1,219 @@
|
|||
const pkg = require('../releases');
|
||||
|
||||
describe('getRelease', () => {
|
||||
function mockFetchReleases () {
|
||||
const mockReleasesMeta = [{
|
||||
tag_name: 'v1.6.0-alpha2',
|
||||
assets: [{
|
||||
name: 'tofu_1.6.0-alpha2_386.apk',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_386.apk'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha2_386.deb',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_386.deb'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha2_386.rpm',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_386.rpm'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha2_amd64.apk',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_amd64.apk'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha2_amd64.deb',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_amd64.deb'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha2_amd64.rpm',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_amd64.rpm'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha2_arm.apk',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_arm.apk'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha2_arm.deb',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_arm.deb'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha2_arm.rpm',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_arm.rpm'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha2_arm64.apk',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_arm64.apk'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha2_arm64.deb',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_arm64.deb'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha2_arm64.rpm',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_arm64.rpm'
|
||||
}, {
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_darwin_amd64.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha2_darwin_arm64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_darwin_arm64.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha2_freebsd_386.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_freebsd_386.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha2_freebsd_amd64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_freebsd_amd64.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha2_freebsd_arm.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_freebsd_arm.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha2_linux_386.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_linux_386.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha2_linux_amd64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_linux_amd64.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha2_linux_arm.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_linux_arm.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha2_linux_arm64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_linux_arm64.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha2_openbsd_386.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_openbsd_386.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha2_openbsd_amd64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_openbsd_amd64.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha2_SHA256SUMS',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_SHA256SUMS'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha2_SHA256SUMS.pem',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_SHA256SUMS.pem'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha2_SHA256SUMS.sig',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_SHA256SUMS.sig'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha2_solaris_amd64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_solaris_amd64.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha2_windows_386.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_windows_386.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha2_windows_amd64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_windows_amd64.zip'
|
||||
}]
|
||||
}, {
|
||||
tag_name: 'v1.6.0-alpha1',
|
||||
assets: [{
|
||||
name: 'tofu_1.6.0-alpha1_386.apk',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_386.apk'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha1_386.deb',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_386.deb'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha1_386.rpm',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_386.rpm'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha1_amd64.apk',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_amd64.apk'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha1_amd64.deb',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_amd64.deb'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha1_amd64.rpm',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_amd64.rpm'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha1_arm.apk',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_arm.apk'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha1_arm.deb',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_arm.deb'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha1_arm.rpm',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_arm.rpm'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha1_arm64.apk',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_arm64.apk'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha1_arm64.deb',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_arm64.deb'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha1_arm64.rpm',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_arm64.rpm'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha1_darwin_amd64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_darwin_amd64.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha1_darwin_arm64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_darwin_arm64.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha1_freebsd_386.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_freebsd_386.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha1_freebsd_amd64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_freebsd_amd64.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha1_freebsd_arm.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_freebsd_arm.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha1_linux_386.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_linux_386.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha1_linux_amd64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_linux_amd64.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha1_linux_arm.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_linux_arm.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha1_linux_arm64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_linux_arm64.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha1_openbsd_386.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_openbsd_386.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha1_openbsd_amd64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_openbsd_amd64.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha1_SHA256SUMS',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_SHA256SUMS'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha1_SHA256SUMS.pem',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_SHA256SUMS.pem'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha1_SHA256SUMS.sig',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_SHA256SUMS.sig'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha1_solaris_amd64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_solaris_amd64.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha1_windows_386.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_windows_386.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0-alpha1_windows_amd64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha1/tofu_1.6.0-alpha1_windows_amd64.zip'
|
||||
}]
|
||||
}];
|
||||
|
||||
return mockReleasesMeta.map(el => new pkg.Release(el));
|
||||
}
|
||||
|
||||
it.each(
|
||||
[
|
||||
['latest', '1.6.0-alpha2'],
|
||||
['<1.6.0-beta', '1.6.0-alpha2'],
|
||||
['>1.6.0-alpha1', '1.6.0-alpha2'],
|
||||
['>1.6.0-alpha1 <1.6.0', '1.6.0-alpha2'],
|
||||
['~1.6.0-alpha', '1.6.0-alpha2'],
|
||||
['<=1.6.0-alpha1', '1.6.0-alpha1']
|
||||
]
|
||||
)('happy path: getRelease(\'%s\') -> \'%s\'', async (input, wantVersion) => {
|
||||
const want = mockFetchReleases().find(el => el.version === wantVersion);
|
||||
const gotRelease = await pkg.getRelease(input, mockFetchReleases);
|
||||
expect(gotRelease).toEqual(want);
|
||||
});
|
||||
|
||||
it.each(
|
||||
[
|
||||
['foo', 'Input version cannot be used, see semver: https://semver.org/spec/v2.0.0.html', undefined],
|
||||
['2.0', 'No matching version found', undefined],
|
||||
['latest', 'No tofu releases found, please contact OpenTofu', async () => { return null; }],
|
||||
['latest', 'No tofu releases found, please contact OpenTofu', async () => { return []; }]
|
||||
]
|
||||
)('unhappy path: getRelease(\'%s\') -> throw Error(\'%s\')', async (input, wantErrorMessage, mockFetchReleasesFn) => {
|
||||
try {
|
||||
await pkg.getRelease(input, mockFetchReleasesFn);
|
||||
expect(true).toBe(false);
|
||||
} catch (e) {
|
||||
expect(e.message).toBe(wantErrorMessage);
|
||||
}
|
||||
});
|
||||
});
|
||||
6369
package-lock.json
generated
Normal file
6369
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
40
package.json
Normal file
40
package.json
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
{
|
||||
"name": "setup-opentofu",
|
||||
"version": "0.0.1",
|
||||
"description": "Setup OpenTofu CLI for GitHub Actions",
|
||||
"license": "MPL-2.0",
|
||||
"publisher": "OpenTofu",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/opentofu/setup-opentofu.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "semistandard --env jest && jest --coverage",
|
||||
"lint": "semistandard --env jest --fix",
|
||||
"build": "ncc build wrapper/tofu.js --out wrapper/dist && ncc build index.js --out dist",
|
||||
"prepare": "husky install",
|
||||
"format-check": "echo \"unimplemented for actions/reusable-workflows basic-validation\""
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"dependencies": {
|
||||
"@actions/core": "1.10.1",
|
||||
"@actions/exec": "1.1.1",
|
||||
"@actions/io": "1.1.3",
|
||||
"@actions/tool-cache": "2.0.1",
|
||||
"semver": "7.5.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vercel/ncc": "0.38.0",
|
||||
"husky": "8.0.3",
|
||||
"jest": "29.7.0",
|
||||
"nock": "13.3.3",
|
||||
"semistandard": "17.0.0"
|
||||
},
|
||||
"semistandard": {
|
||||
"ignore": [
|
||||
"**/dist/**"
|
||||
]
|
||||
}
|
||||
}
|
||||
41
wrapper/lib/output-listener.js
Normal file
41
wrapper/lib/output-listener.js
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Acts as a listener for @actions/exec, by capturing STDOUT and STDERR
|
||||
* streams, and exposing them via a contents attribute.
|
||||
*
|
||||
* @example
|
||||
* // Instantiate a new listener
|
||||
* const listener = new OutputListener();
|
||||
* // Register listener against STDOUT stream
|
||||
* await exec.exec('ls', ['-ltr'], {
|
||||
* listeners: {
|
||||
* stdout: listener.listener
|
||||
* }
|
||||
* });
|
||||
* // Log out STDOUT contents
|
||||
* console.log(listener.contents);
|
||||
*/
|
||||
class OutputListener {
|
||||
constructor () {
|
||||
this._buff = [];
|
||||
}
|
||||
|
||||
get listener () {
|
||||
const listen = function listen (data) {
|
||||
this._buff.push(data);
|
||||
};
|
||||
return listen.bind(this);
|
||||
}
|
||||
|
||||
get contents () {
|
||||
return this._buff
|
||||
.map(chunk => chunk.toString())
|
||||
.join('');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = OutputListener;
|
||||
14
wrapper/lib/tofu-bin.js
Normal file
14
wrapper/lib/tofu-bin.js
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = (() => {
|
||||
// If we're on Windows, then the executable ends with .exe
|
||||
const exeSuffix = os.platform().startsWith('win') ? '.exe' : '';
|
||||
|
||||
return [process.env.TOFU_CLI_PATH, `tofu-bin${exeSuffix}`].join(path.sep);
|
||||
})();
|
||||
17
wrapper/test/output-listener.test.js
Normal file
17
wrapper/test/output-listener.test.js
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
const OutputListener = require('../lib/output-listener');
|
||||
|
||||
describe('output-listener', () => {
|
||||
it('receives and exposes data', () => {
|
||||
const listener = new OutputListener();
|
||||
const listen = listener.listener;
|
||||
listen(Buffer.from('foo'));
|
||||
listen(Buffer.from('bar'));
|
||||
listen(Buffer.from('baz'));
|
||||
expect(listener.contents).toEqual('foobarbaz');
|
||||
});
|
||||
});
|
||||
59
wrapper/tofu.js
Executable file
59
wrapper/tofu.js
Executable file
|
|
@ -0,0 +1,59 @@
|
|||
#!/usr/bin/env node
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
const io = require('@actions/io');
|
||||
const core = require('@actions/core');
|
||||
const { exec } = require('@actions/exec');
|
||||
|
||||
const OutputListener = require('./lib/output-listener');
|
||||
const pathToCLI = require('./lib/tofu-bin');
|
||||
|
||||
async function checkTofu () {
|
||||
// Setting check to `true` will cause `which` to throw if tofu isn't found
|
||||
const check = true;
|
||||
return io.which(pathToCLI, check);
|
||||
}
|
||||
|
||||
(async () => {
|
||||
// This will fail if tofu isn't found, which is what we want
|
||||
await checkTofu();
|
||||
|
||||
// Create listeners to receive output (in memory) as well
|
||||
const stdout = new OutputListener();
|
||||
const stderr = new OutputListener();
|
||||
const listeners = {
|
||||
stdout: stdout.listener,
|
||||
stderr: stderr.listener
|
||||
};
|
||||
|
||||
// Execute tofu and capture output
|
||||
const args = process.argv.slice(2);
|
||||
const options = {
|
||||
listeners,
|
||||
ignoreReturnCode: true
|
||||
};
|
||||
const exitCode = await exec(pathToCLI, args, options);
|
||||
core.debug(`OpenTofu exited with code ${exitCode}.`);
|
||||
core.debug(`stdout: ${stdout.contents}`);
|
||||
core.debug(`stderr: ${stderr.contents}`);
|
||||
core.debug(`exitcode: ${exitCode}`);
|
||||
|
||||
// Set outputs, result, exitcode, and stderr
|
||||
core.setOutput('stdout', stdout.contents);
|
||||
core.setOutput('stderr', stderr.contents);
|
||||
core.setOutput('exitcode', exitCode.toString(10));
|
||||
|
||||
if (exitCode === 0 || exitCode === 2) {
|
||||
// A exitCode of 0 is considered a success
|
||||
// An exitCode of 2 may be returned when the '-detailed-exitcode' option
|
||||
// is passed to plan. This denotes Success with non-empty
|
||||
// diff (changes present).
|
||||
return;
|
||||
}
|
||||
|
||||
// A non-zero exitCode is considered an error
|
||||
core.setFailed(`OpenTofu exited with code ${exitCode}.`);
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue