From 995d84cb382fa52858a08da3e53c4d73ac95efc2 Mon Sep 17 00:00:00 2001 From: Craig Anderson <1877372+CDA0@users.noreply.github.com> Date: Sat, 23 Dec 2023 12:01:42 +0000 Subject: [PATCH 01/17] initial play --- .editorconfig | 15 + .github/workflows/ci.yml | 45 ++ .github/workflows/release.yml | 48 ++ .gitignore | 9 + .goreleaser.yaml | 45 ++ CHANGELOG.md | 1 + CONTRIBUTING.md | 7 + LICENSE | 674 ++++++++++++++++++++++++++++ MAINTAINERS.md | 10 + Makefile | 8 + README.md | 2 +- SUPPORT.md | 3 + cmd/vertag/vertag.go | 22 + cmd/vertag/vertag_test.go | 1 + config.yaml | 24 + go.mod | 41 ++ go.sum | 283 ++++++++++++ pkg/cmd/app/apply/apply.go | 306 +++++++++++++ pkg/cmd/app/apply/apply_test.go | 1 + pkg/cmd/cli/apply/apply.go | 23 + pkg/cmd/cli/apply/apply_test.go | 13 + pkg/cmd/cli/version/version.go | 31 ++ pkg/cmd/cli/version/version_test.go | 13 + pkg/cmd/vertag/vertag.go | 27 ++ pkg/cmd/vertag/vertag_test.go | 13 + 25 files changed, 1664 insertions(+), 1 deletion(-) create mode 100644 .editorconfig create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml create mode 100644 .gitignore create mode 100644 .goreleaser.yaml create mode 100644 CHANGELOG.md create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE create mode 100644 MAINTAINERS.md create mode 100644 Makefile create mode 100644 SUPPORT.md create mode 100644 cmd/vertag/vertag.go create mode 100644 cmd/vertag/vertag_test.go create mode 100644 config.yaml create mode 100644 go.mod create mode 100644 go.sum create mode 100644 pkg/cmd/app/apply/apply.go create mode 100644 pkg/cmd/app/apply/apply_test.go create mode 100644 pkg/cmd/cli/apply/apply.go create mode 100644 pkg/cmd/cli/apply/apply_test.go create mode 100644 pkg/cmd/cli/version/version.go create mode 100644 pkg/cmd/cli/version/version_test.go create mode 100644 pkg/cmd/vertag/vertag.go create mode 100644 pkg/cmd/vertag/vertag_test.go diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..90ec23f --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +root = true + +[*] +charset = utf-8 +indent_size = 2 +indent_style = space +insert_final_newline = true +tab_width = 4 +trim_trailing_whitespace = true + +[*.go] +indent_style = tab + +[Makefile] +indent_style = tab diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7876bf6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,45 @@ +--- + name: CI + + on: + push: + branches: + - "**" + pull_request: + branches: + - "**" + workflow_dispatch: + + jobs: + preflight: + runs-on: ubuntu-latest + outputs: + go_version: ${{ steps.get_go_version.outputs.go_version }} + steps: + - uses: actions/checkout@v3 + + - id: get_go_version + name: Get Golang version + run: | + set -euo pipefail + + go_version=$(sed -n 3p ${GITHUB_WORKSPACE}/go.mod | cut -d " " -f2) + echo "Golang version: ${go_version}" + echo "go_version=$go_version" >> "$GITHUB_OUTPUT" + + build: + needs: preflight + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: ${{ needs.preflight.outputs.go_version }} + + - name: Build + run: make build + + - name: Test + run: make test diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..cf13b50 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,48 @@ +name: Release + +on: + push: + tags: + - "**" + +permissions: + contents: write + +jobs: + preflight: + runs-on: ubuntu-latest + outputs: + go_version: ${{ steps.get_go_version.outputs.go_version }} + steps: + - uses: actions/checkout@v3 + + - id: get_go_version + name: Get Golang version + run: | + set -euo pipefail + + go_version=$(sed -n 3p ${GITHUB_WORKSPACE}/go.mod | cut -d " " -f2) + echo "Golang version: ${go_version}" + echo "go_version=$go_version" >> "$GITHUB_OUTPUT" + + release: + needs: preflight + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - run: git fetch --force --tags + + - uses: actions/setup-go@v4 + with: + go-version: ${{ needs.preflight.outputs.go_version }} + + - uses: goreleaser/goreleaser-action@v4 + with: + distribution: goreleaser + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..261efb4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +# ide +.env +.vscode + +# go +/vertag + +# other +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..eb6dcc5 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,45 @@ +# This is an example .goreleaser.yml file with some sensible defaults. +# Make sure to check the documentation at https://goreleaser.com +before: + hooks: + # You may remove this if you don't use go modules. + - go mod tidy + # you may remove this if you don't need go generate + - go generate ./... +builds: + - main: ./cmd/vertag/vertag.go + env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + +archives: + - format: tar.gz + # this name template makes the OS and Arch compatible with the results of uname. + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + # use zip for windows archives + format_overrides: + - goos: windows + format: zip +checksum: + name_template: "checksums.txt" +snapshot: + name_template: "{{ incpatch .Version }}-next" +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" +# The lines beneath this are called `modelines`. See `:help modeline` +# Feel free to remove those if you don't want/use them. +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..450ac30 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1 @@ +# vertag Changelog diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..74ad21d --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,7 @@ +# Contributing + +1. Ensure the correct version of Golang is installed. The version can be found in `./go.mod`. +1. Install the dependencies with `go install`. +1. Compile the code with `go build`. +1. Print the help text with `vertag --help`. +1. Run the tests with `go test -v ./...`. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f288702 --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/MAINTAINERS.md b/MAINTAINERS.md new file mode 100644 index 0000000..c56ee84 --- /dev/null +++ b/MAINTAINERS.md @@ -0,0 +1,10 @@ +# vertag Maintainers + +## Maintainers + +| Maintainer | GitHub ID | Affiliation | +| --------------- | --------- | ----------- | +| Anthony Gibbons | [tonipepperoniuk](https://github.com/tonipepperoniuk) | [Frontier Digital](https://github.com/frontierdigital/) | +| Craig Anderson | [cda0](https://github.com/cda0) | [Frontier Digital](https://github.com/frontierdigital/) | +| Fraser Davidson | [frasdav](https://github.com/frasdav) | [Frontier Digital](https://github.com/frontierdigital/) | +| Neil Cowlin | [n-cow](https://github.com/n-cow) | [Frontier Digital](https://github.com/frontierdigital/) | diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7c31a75 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +build: + go build cmd/vertag/vertag.go + +install: + go install cmd/vertag/vertag.go + +test: + go test -v ./... diff --git a/README.md b/README.md index 30cf6ab..db31e88 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# vertag \ No newline at end of file +# vertag diff --git a/SUPPORT.md b/SUPPORT.md new file mode 100644 index 0000000..65bb123 --- /dev/null +++ b/SUPPORT.md @@ -0,0 +1,3 @@ +# vertag Support + +Thanks for trying out vertag! We're setting up an IRC channel, but please raise a GitHub issue in the meantime if you've got any questions. diff --git a/cmd/vertag/vertag.go b/cmd/vertag/vertag.go new file mode 100644 index 0000000..ca39044 --- /dev/null +++ b/cmd/vertag/vertag.go @@ -0,0 +1,22 @@ +package main + +import ( + "os" + + "github.com/frontierdigital/utils/output" + "github.com/frontierdigital/vertag/pkg/cmd/vertag" +) + +var ( + version = "dev" + commit = "none" + date = "unknown" +) + +func main() { + command := vertag.NewRootCmd(version, commit, date) + if err := command.Execute(); err != nil { + output.PrintlnError(err) + os.Exit(1) + } +} diff --git a/cmd/vertag/vertag_test.go b/cmd/vertag/vertag_test.go new file mode 100644 index 0000000..06ab7d0 --- /dev/null +++ b/cmd/vertag/vertag_test.go @@ -0,0 +1 @@ +package main diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..595a50c --- /dev/null +++ b/config.yaml @@ -0,0 +1,24 @@ +deploy: + credential: + - cred_GUPCOM + factory: + - '*' + pipeline: + - p_CDI-SFDC_CONTACT + +changes: + integrationRuntime: + - name: Lansing + patch: + properties: + typeProperties: + linkedInfo: + authorizationType: Rbac + resourceId: "/subscriptions/b362fbc7-82bd-4c39-b979-bea67f8e1178/resourcegroups/rg-ct-fat-weu-devgup/providers/Microsoft.DataFactory/factories/adf-ct-fat-weu-devgup/integrationruntimes/Lansing" + factory: + - name: adf-ct-fat-weu-devgup + patch: + properties: + globalParameters: + CRM_DB_PORT: + value: "1532" diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..b40f98a --- /dev/null +++ b/go.mod @@ -0,0 +1,41 @@ +module github.com/frontierdigital/vertag + +go 1.20 + +require ( + github.com/frontierdigital/utils v0.0.10 + github.com/go-git/go-git/v5 v5.11.0 + github.com/spf13/cobra v1.6.1 + go.hein.dev/go-version v0.1.0 +) + +require ( + dario.cat/mergo v1.0.0 // indirect + github.com/Microsoft/go-winio v0.6.1 // indirect + github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect + github.com/cloudflare/circl v1.3.3 // indirect + github.com/cyphar/filepath-securejoin v0.2.4 // indirect + github.com/emirpasic/gods v1.18.1 // indirect + github.com/fatih/color v1.13.0 // indirect + github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect + github.com/go-git/go-billy/v5 v5.5.0 // indirect + github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect + github.com/inconshreveable/mousetrap v1.0.1 // indirect + github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect + github.com/kevinburke/ssh_config v1.2.0 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.16 // indirect + github.com/pjbgf/sha1cd v0.3.0 // indirect + github.com/sergi/go-diff v1.1.0 // indirect + github.com/skeema/knownhosts v1.2.1 // indirect + github.com/spf13/pflag v1.0.5 // indirect + github.com/xanzy/ssh-agent v0.3.3 // indirect + golang.org/x/crypto v0.16.0 // indirect + golang.org/x/mod v0.14.0 // indirect + golang.org/x/net v0.19.0 // indirect + golang.org/x/sys v0.15.0 // indirect + golang.org/x/tools v0.16.0 // indirect + gopkg.in/warnings.v0 v0.1.2 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + sigs.k8s.io/yaml v1.1.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..c2f3858 --- /dev/null +++ b/go.sum @@ -0,0 +1,283 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= +dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= +github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= +github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 h1:kkhsdkhsCvIsutKu5zLMgWtgh9YxGCNAw8Ad8hjwfYg= +github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= +github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= +github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs= +github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= +github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= +github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= +github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= +github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= +github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= +github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcejNsXKSkQ6lcIaNec2nyfOdlTBR2lU= +github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= +github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= +github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= +github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= +github.com/frontierdigital/utils v0.0.10 h1:uDebdnrqAw6RT4/6y1gVVEKnA7+32ULqw2PgFc7ZHdc= +github.com/frontierdigital/utils v0.0.10/go.mod h1:iz+lbB9iGA9ZsVbber/tPosKC9HFTgKTDP8/UC6XxBY= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY= +github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= +github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= +github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU= +github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow= +github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4= +github.com/go-git/go-git/v5 v5.11.0 h1:XIZc1p+8YzypNr34itUfSvYJcv+eYdTnTvOZ2vD3cA4= +github.com/go-git/go-git/v5 v5.11.0/go.mod h1:6GFcX2P3NM7FPBfpePbpLd21XxsgdAt+lKqXmCUiUCY= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= +github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc= +github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= +github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= +github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= +github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= +github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= +github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= +github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= +github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= +github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/skeema/knownhosts v1.2.1 h1:SHWdIUa82uGZz+F+47k8SY4QhhI291cXCpopT1lK2AQ= +github.com/skeema/knownhosts v1.2.1/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo= +github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= +github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA= +github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY= +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= +github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= +github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= +github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= +github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.hein.dev/go-version v0.1.0 h1:hz3epLdx+cim8EN9XRt6pqAHxwWVW0D87Xm3mUbvKvI= +go.hein.dev/go-version v0.1.0/go.mod h1:WOEm7DWMroRe5GdUgHMvx+Pji5WWIpMuXmK/3foylXs= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= +golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= +golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= +golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= +golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= +golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= +golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190812172437-4e8604ab3aff/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= +golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190812233024-afc3694995b6/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/tools v0.16.0 h1:GO788SKMRunPIBCXiQyo2AaexLstOrVhuAL5YwsckQM= +golang.org/x/tools v0.16.0/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= +gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= +gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= +gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs= +sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= diff --git a/pkg/cmd/app/apply/apply.go b/pkg/cmd/app/apply/apply.go new file mode 100644 index 0000000..f0a2660 --- /dev/null +++ b/pkg/cmd/app/apply/apply.go @@ -0,0 +1,306 @@ +package apply + +import ( + "fmt" + "io" + "os" + "path" + "strconv" + "strings" + "time" + + "github.com/frontierdigital/utils/output" + "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/config" + "github.com/go-git/go-git/v5/plumbing" + "github.com/go-git/go-git/v5/plumbing/object" +) + +// LatestTag returns the most recent tag on the repository. +func latestStableTag(r *git.Repository) (string, error) { + tagRefs, err := r.Tags() + if err != nil { + return "", err + } + + var latestTagCommit *object.Commit + var latestTagName string + err = tagRefs.ForEach(func(tagRef *plumbing.Reference) error { + if strings.Contains(tagRef.Name().String(), "-unstable") { + return nil + } + revision := plumbing.Revision(tagRef.Name().String()) + tagCommitHash, err := r.ResolveRevision(revision) + if err != nil { + return err + } + + commit, err := r.CommitObject(*tagCommitHash) + if err != nil { + return err + } + + if latestTagCommit == nil { + latestTagCommit = commit + latestTagName = tagRef.Name().String() + } + + if commit.Committer.When.After(latestTagCommit.Committer.When) { + latestTagCommit = commit + latestTagName = tagRef.Name().String() + } + + return nil + }) + if err != nil { + return "", err + } + + return latestTagName, nil +} + +func latestTagContains(r *git.Repository, tagContains string) (string, error) { + tagRefs, err := r.Tags() + if err != nil { + return "", err + } + + var latestTagCommit *object.Commit + var latestTagName string + err = tagRefs.ForEach(func(tagRef *plumbing.Reference) error { + if strings.Contains(tagRef.Name().String(), tagContains) { + revision := plumbing.Revision(tagRef.Name().String()) + tagCommitHash, err := r.ResolveRevision(revision) + if err != nil { + return err + } + + commit, err := r.CommitObject(*tagCommitHash) + if err != nil { + return err + } + + if latestTagCommit == nil { + latestTagCommit = commit + latestTagName = tagRef.Name().String() + } + + if commit.Committer.When.After(latestTagCommit.Committer.When) { + latestTagCommit = commit + latestTagName = tagRef.Name().String() + } + } + return nil + }) + if err != nil { + return "", err + } + + return latestTagName, nil +} + +func branchName(r *git.Repository) (string, error) { + + head, err := r.Head() + if err != nil { + return "", err + } + + return head.Name().String(), nil +} + +func initalCommitHash(r *git.Repository) string { + commits, _ := r.CommitObjects() + var initialHash plumbing.Hash + _ = commits.ForEach(func(c *object.Commit) error { + if c.NumParents() == 0 { + initialHash = c.Hash + } + return nil + }) + return initialHash.String() +} + +func getDiffRefs(r *git.Repository) (string, string) { + cb, err := branchName(r) + if err != nil { + fmt.Println(err) + } + + lt, err := latestStableTag(r) + if err != nil { + fmt.Println("getDiffRefs:LatestTagError") + fmt.Println(err) + } + if lt == "" { + lt = initalCommitHash(r) + } + + return cb, lt +} + +func diff(r *git.Repository, tag string) (*object.Patch, error) { + revision := plumbing.Revision(tag) + tagCommitHash, err := r.ResolveRevision(revision) + if err != nil { + return nil, err + } + + tagCommit, err := r.CommitObject(*tagCommitHash) + headRef, _ := r.Head() + + headHash := headRef.Hash() + headCommit, _ := r.CommitObject(headHash) + return tagCommit.Patch(headCommit) +} + +func removeFromSlice(s []string, r string) []string { + for i, v := range s { + if v == r { + return append(s[:i], s[i+1:]...) + } + } + return s +} + +func changedFiles(r *git.Repository, latestTagOrHash string) []string { + fileschanged := make([]string, 0) + diff, _ := diff(r, latestTagOrHash) + stats := diff.Stats() + + for _, stat := range stats { + fileschanged = append(fileschanged, stat.Name) + } + + fps := diff.FilePatches() + for _, fp := range fps { + f, t := fp.Files() + if t == nil { + fileschanged = removeFromSlice(fileschanged, f.Path()) + } + } + + return fileschanged +} + +func changedDirs(filesChanged []string) []string { + dirschanged := make([]string, 0) + for _, fc := range filesChanged { + a := strings.Split(fc, "/") + if len(a) > 2 { // make sure the changed file is of the form [azure resource-group main.tf] + inDirschanged := false + for _, dir := range dirschanged { + if dir == a[1] { + inDirschanged = true + } + } + if inDirschanged == false { + dirschanged = append(dirschanged, a[1]) + } + } + } + return dirschanged +} + +func getVersion(dir string) (string, error) { + file, err := os.Open(path.Join(dir, "VERSION")) + if err != nil { + return "", err + } + defer file.Close() + + // Read the file's contents + bytes, err := io.ReadAll(file) + if err != nil { + return "", err + } + retval := strings.TrimSuffix(string(bytes), "\n") + + return retval, nil +} + +func getTagSuffix(r *git.Repository) string { + cb, err := branchName(r) + if err != nil { + fmt.Println(err) + } + if cb != "main" && cb != "master" { + return "-unstable" + } + return "" +} + +func Tag(r *git.Repository, tag string, authorName string, authorEmail string) error { + headRef, _ := r.Head() + headHash := headRef.Hash() + tagger := &object.Signature{ + Name: authorName, + Email: authorEmail, + When: time.Now(), + } + _, err := r.CreateTag(tag, headHash, &git.CreateTagOptions{ + Tagger: tagger, + Message: tag, + }) + return err +} + +func PushWithTags(r *git.Repository) error { + rs := config.RefSpec("refs/tags/*:refs/tags/*") + return r.Push(&git.PushOptions{ + RefSpecs: []config.RefSpec{rs}, + }) +} + +func Apply() error { + + modulesdir := "/Users/craig/Projects/github/azurerm-terraform-modules" + + output.PrintlnfInfo("Apply here we go") + + r, err := git.PlainOpen(modulesdir) + if err != nil { + output.PrintlnError(err) + } + + tagrefs, err := r.Tags() + err = tagrefs.ForEach(func(t *plumbing.Reference) error { + fmt.Println(t) + return nil + }) + + cb, lt := getDiffRefs(r) + fmt.Printf("Current Branch: %s\nLatest Tag: %s\n", cb, lt) + + fileschanged := changedFiles(r, lt) + fmt.Println("Files changed: ", fileschanged) + dirschanged := changedDirs(fileschanged) + fmt.Println("Dirs changed: ", dirschanged) + + for _, d := range dirschanged { + ltc, err := latestTagContains(r, d) + if err != nil { + output.PrintlnError(err) + } + fmt.Println("Latest Tag Contains: ", ltc) + patchVersion := 0 + versionFromFile, _ := getVersion(path.Join(modulesdir, "modules", d)) + ns := d + if ltc != "" { + ltcSplit := strings.Split(ltc, "/") + ns = ltcSplit[2] + versionFromTag := ltcSplit[3] + latestPatch, _ := strconv.Atoi(strings.Split(ltcSplit[3], ".")[2]) + if versionFromFile == versionFromTag { + patchVersion = latestPatch + 1 + } else { + patchVersion = 0 + } + } + suffix := getTagSuffix(r) + fmt.Println("new tag: ", fmt.Sprintf("%s/%s.%d%s", ns, versionFromFile, patchVersion, suffix)) + } + + return nil + +} diff --git a/pkg/cmd/app/apply/apply_test.go b/pkg/cmd/app/apply/apply_test.go new file mode 100644 index 0000000..743a9c2 --- /dev/null +++ b/pkg/cmd/app/apply/apply_test.go @@ -0,0 +1 @@ +package apply diff --git a/pkg/cmd/cli/apply/apply.go b/pkg/cmd/cli/apply/apply.go new file mode 100644 index 0000000..11ea7fb --- /dev/null +++ b/pkg/cmd/cli/apply/apply.go @@ -0,0 +1,23 @@ +package apply + +import ( + "github.com/frontierdigital/vertag/pkg/cmd/app/apply" + "github.com/spf13/cobra" +) + +// NewCmdApply creates a command to apply config +func NewCmdApply() *cobra.Command { + cmd := &cobra.Command{ + Use: "apply", + Short: "Apply config", + RunE: func(_ *cobra.Command, _ []string) error { + if err := apply.Apply(); err != nil { + return err + } + + return nil + }, + } + + return cmd +} diff --git a/pkg/cmd/cli/apply/apply_test.go b/pkg/cmd/cli/apply/apply_test.go new file mode 100644 index 0000000..f953e0b --- /dev/null +++ b/pkg/cmd/cli/apply/apply_test.go @@ -0,0 +1,13 @@ +package apply + +import ( + "testing" +) + +func TestNewCmdApply(t *testing.T) { + cmd := NewCmdApply() + + if cmd.Use != "apply" { + t.Errorf("Use is not correct") + } +} diff --git a/pkg/cmd/cli/version/version.go b/pkg/cmd/cli/version/version.go new file mode 100644 index 0000000..405174f --- /dev/null +++ b/pkg/cmd/cli/version/version.go @@ -0,0 +1,31 @@ +package version + +import ( + "github.com/frontierdigital/utils/output" + "github.com/spf13/cobra" + goVersion "go.hein.dev/go-version" +) + +var ( + outputFmt string + shortened bool +) + +// NewCmdVersion creates a command to output the current version +func NewCmdVersion(version string, commit string, date string) *cobra.Command { + cmd := &cobra.Command{ + Use: "version", + Short: "Output version information", + RunE: func(_ *cobra.Command, _ []string) error { + resp := goVersion.FuncWithOutput(shortened, version, commit, date, outputFmt) + output.PrintfInfo(resp) + + return nil + }, + } + + cmd.Flags().BoolVarP(&shortened, "short", "s", false, "Print just the version number") + cmd.Flags().StringVarP(&outputFmt, "output", "o", "json", "Output format") + + return cmd +} diff --git a/pkg/cmd/cli/version/version_test.go b/pkg/cmd/cli/version/version_test.go new file mode 100644 index 0000000..a6ecc89 --- /dev/null +++ b/pkg/cmd/cli/version/version_test.go @@ -0,0 +1,13 @@ +package version + +import ( + "testing" +) + +func TestNewCmdVersion(t *testing.T) { + cmd := NewCmdVersion("0.0.0", "commitid", "date") + + if cmd.Use != "version" { + t.Errorf("Use is not correct") + } +} diff --git a/pkg/cmd/vertag/vertag.go b/pkg/cmd/vertag/vertag.go new file mode 100644 index 0000000..12db22f --- /dev/null +++ b/pkg/cmd/vertag/vertag.go @@ -0,0 +1,27 @@ +package vertag + +import ( + "github.com/frontierdigital/vertag/pkg/cmd/cli/apply" + vers "github.com/frontierdigital/vertag/pkg/cmd/cli/version" + "github.com/spf13/cobra" +) + +func NewRootCmd(version string, commit string, date string) *cobra.Command { + rootCmd := &cobra.Command{ + Use: "vertag", + DisableFlagsInUseLine: true, + Short: "vertag is the command line tool for vertag", + RunE: func(cmd *cobra.Command, args []string) error { + if err := cmd.Help(); err != nil { + return err + } + + return nil + }, + } + + rootCmd.AddCommand(apply.NewCmdApply()) + rootCmd.AddCommand(vers.NewCmdVersion(version, commit, date)) + + return rootCmd +} diff --git a/pkg/cmd/vertag/vertag_test.go b/pkg/cmd/vertag/vertag_test.go new file mode 100644 index 0000000..a4d2a8c --- /dev/null +++ b/pkg/cmd/vertag/vertag_test.go @@ -0,0 +1,13 @@ +package vertag + +import ( + "testing" +) + +func TestNewCmdRoot(t *testing.T) { + cmd := NewRootCmd("0.0.0", "commitid", "date") + + if cmd.Use != "vertag" { + t.Errorf("Use is not correct") + } +} From f379f82544af933ceebd192d7233759bbd6be2cd Mon Sep 17 00:00:00 2001 From: Craig Anderson <1877372+CDA0@users.noreply.github.com> Date: Sat, 23 Dec 2023 12:37:40 +0000 Subject: [PATCH 02/17] cli args --- pkg/cmd/app/apply/apply.go | 9 +++------ pkg/cmd/cli/apply/apply.go | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/pkg/cmd/app/apply/apply.go b/pkg/cmd/app/apply/apply.go index f0a2660..c74704d 100644 --- a/pkg/cmd/app/apply/apply.go +++ b/pkg/cmd/app/apply/apply.go @@ -252,13 +252,11 @@ func PushWithTags(r *git.Repository) error { }) } -func Apply() error { - - modulesdir := "/Users/craig/Projects/github/azurerm-terraform-modules" +func Apply(modulesDir string, authorName string, authorEmail string) error { output.PrintlnfInfo("Apply here we go") - r, err := git.PlainOpen(modulesdir) + r, err := git.PlainOpen(modulesDir) if err != nil { output.PrintlnError(err) } @@ -284,7 +282,7 @@ func Apply() error { } fmt.Println("Latest Tag Contains: ", ltc) patchVersion := 0 - versionFromFile, _ := getVersion(path.Join(modulesdir, "modules", d)) + versionFromFile, _ := getVersion(path.Join(modulesDir, "modules", d)) ns := d if ltc != "" { ltcSplit := strings.Split(ltc, "/") @@ -302,5 +300,4 @@ func Apply() error { } return nil - } diff --git a/pkg/cmd/cli/apply/apply.go b/pkg/cmd/cli/apply/apply.go index 11ea7fb..3053a91 100644 --- a/pkg/cmd/cli/apply/apply.go +++ b/pkg/cmd/cli/apply/apply.go @@ -1,23 +1,38 @@ package apply import ( + "os" + "github.com/frontierdigital/vertag/pkg/cmd/app/apply" "github.com/spf13/cobra" ) +var ( + modulesRoot string + authorName string + authorEmail string +) + // NewCmdApply creates a command to apply config func NewCmdApply() *cobra.Command { cmd := &cobra.Command{ Use: "apply", Short: "Apply config", RunE: func(_ *cobra.Command, _ []string) error { - if err := apply.Apply(); err != nil { + if err := apply.Apply(modulesRoot, authorName, authorEmail); err != nil { return err } return nil }, } + wd, err := os.Getwd() + if err != nil { + panic(err) + } + cmd.Flags().StringVarP(&modulesRoot, "modules-dir", "m", wd, "Root directory for modules") + cmd.Flags().StringVarP(&authorName, "author-name", "n", wd, "Name of the commiter") + cmd.Flags().StringVarP(&authorEmail, "author-email", "e", wd, "Email of the commiter") return cmd } From de5efaeac9c5f228a623c01d4603b62b54d45051 Mon Sep 17 00:00:00 2001 From: Craig Anderson <1877372+CDA0@users.noreply.github.com> Date: Sat, 23 Dec 2023 12:44:55 +0000 Subject: [PATCH 03/17] tidy --- pkg/cmd/app/apply/apply.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/cmd/app/apply/apply.go b/pkg/cmd/app/apply/apply.go index c74704d..bd5cff4 100644 --- a/pkg/cmd/app/apply/apply.go +++ b/pkg/cmd/app/apply/apply.go @@ -16,7 +16,7 @@ import ( "github.com/go-git/go-git/v5/plumbing/object" ) -// LatestTag returns the most recent tag on the repository. +// latestStableTag returns the most recent tag on the repository. func latestStableTag(r *git.Repository) (string, error) { tagRefs, err := r.Tags() if err != nil { @@ -124,13 +124,12 @@ func initalCommitHash(r *git.Repository) string { func getDiffRefs(r *git.Repository) (string, string) { cb, err := branchName(r) if err != nil { - fmt.Println(err) + return "", "" } lt, err := latestStableTag(r) if err != nil { - fmt.Println("getDiffRefs:LatestTagError") - fmt.Println(err) + return "", "" } if lt == "" { lt = initalCommitHash(r) @@ -209,7 +208,6 @@ func getVersion(dir string) (string, error) { } defer file.Close() - // Read the file's contents bytes, err := io.ReadAll(file) if err != nil { return "", err From c1d862e0bc2da613f61d52c05243ea44d0207221 Mon Sep 17 00:00:00 2001 From: Craig Anderson <1877372+CDA0@users.noreply.github.com> Date: Sat, 23 Dec 2023 15:33:18 +0000 Subject: [PATCH 04/17] utils --- MAINTAINERS.md | 8 ++++---- cmd/vertag/vertag.go | 4 ++-- go.mod | 4 ++-- go.sum | 4 ++-- pkg/cmd/app/apply/apply.go | 2 +- pkg/cmd/cli/apply/apply.go | 2 +- pkg/cmd/cli/version/version.go | 2 +- pkg/cmd/vertag/vertag.go | 4 ++-- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/MAINTAINERS.md b/MAINTAINERS.md index c56ee84..3595cbf 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -4,7 +4,7 @@ | Maintainer | GitHub ID | Affiliation | | --------------- | --------- | ----------- | -| Anthony Gibbons | [tonipepperoniuk](https://github.com/tonipepperoniuk) | [Frontier Digital](https://github.com/frontierdigital/) | -| Craig Anderson | [cda0](https://github.com/cda0) | [Frontier Digital](https://github.com/frontierdigital/) | -| Fraser Davidson | [frasdav](https://github.com/frasdav) | [Frontier Digital](https://github.com/frontierdigital/) | -| Neil Cowlin | [n-cow](https://github.com/n-cow) | [Frontier Digital](https://github.com/frontierdigital/) | +| Anthony Gibbons | [tonipepperoniuk](https://github.com/tonipepperoniuk) | [Frontier Digital](https://github.com/gofrontier-com/) | +| Craig Anderson | [cda0](https://github.com/cda0) | [Frontier Digital](https://github.com/gofrontier-com/) | +| Fraser Davidson | [frasdav](https://github.com/frasdav) | [Frontier Digital](https://github.com/gofrontier-com/) | +| Neil Cowlin | [n-cow](https://github.com/n-cow) | [Frontier Digital](https://github.com/gofrontier-com/) | diff --git a/cmd/vertag/vertag.go b/cmd/vertag/vertag.go index ca39044..49299e1 100644 --- a/cmd/vertag/vertag.go +++ b/cmd/vertag/vertag.go @@ -3,8 +3,8 @@ package main import ( "os" - "github.com/frontierdigital/utils/output" - "github.com/frontierdigital/vertag/pkg/cmd/vertag" + "github.com/gofrontier-com/go-utils/output" + "github.com/gofrontier-com/vertag/pkg/cmd/vertag" ) var ( diff --git a/go.mod b/go.mod index b40f98a..00a7ac2 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,10 @@ -module github.com/frontierdigital/vertag +module github.com/gofrontier-com/vertag go 1.20 require ( - github.com/frontierdigital/utils v0.0.10 github.com/go-git/go-git/v5 v5.11.0 + github.com/gofrontier-com/go-utils v0.1.0 github.com/spf13/cobra v1.6.1 go.hein.dev/go-version v0.1.0 ) diff --git a/go.sum b/go.sum index c2f3858..2e00586 100644 --- a/go.sum +++ b/go.sum @@ -40,8 +40,6 @@ github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= -github.com/frontierdigital/utils v0.0.10 h1:uDebdnrqAw6RT4/6y1gVVEKnA7+32ULqw2PgFc7ZHdc= -github.com/frontierdigital/utils v0.0.10/go.mod h1:iz+lbB9iGA9ZsVbber/tPosKC9HFTgKTDP8/UC6XxBY= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY= @@ -56,6 +54,8 @@ github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2 github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gofrontier-com/go-utils v0.1.0 h1:n/PzHfokrWD7Z1Pr8JLwazNu5JTzUwUtkXk3FK34KoU= +github.com/gofrontier-com/go-utils v0.1.0/go.mod h1:iNQRvodEbHcUj2pRQcayq+anXy30/UKhAKU/smz5i/8= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= diff --git a/pkg/cmd/app/apply/apply.go b/pkg/cmd/app/apply/apply.go index bd5cff4..2d801fa 100644 --- a/pkg/cmd/app/apply/apply.go +++ b/pkg/cmd/app/apply/apply.go @@ -9,11 +9,11 @@ import ( "strings" "time" - "github.com/frontierdigital/utils/output" "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/config" "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/object" + "github.com/gofrontier-com/go-utils/output" ) // latestStableTag returns the most recent tag on the repository. diff --git a/pkg/cmd/cli/apply/apply.go b/pkg/cmd/cli/apply/apply.go index 3053a91..7bd12c6 100644 --- a/pkg/cmd/cli/apply/apply.go +++ b/pkg/cmd/cli/apply/apply.go @@ -3,7 +3,7 @@ package apply import ( "os" - "github.com/frontierdigital/vertag/pkg/cmd/app/apply" + "github.com/gofrontier-com/vertag/pkg/cmd/app/apply" "github.com/spf13/cobra" ) diff --git a/pkg/cmd/cli/version/version.go b/pkg/cmd/cli/version/version.go index 405174f..6933a9c 100644 --- a/pkg/cmd/cli/version/version.go +++ b/pkg/cmd/cli/version/version.go @@ -1,7 +1,7 @@ package version import ( - "github.com/frontierdigital/utils/output" + "github.com/gofrontier-com/go-utils/output" "github.com/spf13/cobra" goVersion "go.hein.dev/go-version" ) diff --git a/pkg/cmd/vertag/vertag.go b/pkg/cmd/vertag/vertag.go index 12db22f..0534363 100644 --- a/pkg/cmd/vertag/vertag.go +++ b/pkg/cmd/vertag/vertag.go @@ -1,8 +1,8 @@ package vertag import ( - "github.com/frontierdigital/vertag/pkg/cmd/cli/apply" - vers "github.com/frontierdigital/vertag/pkg/cmd/cli/version" + "github.com/gofrontier-com/vertag/pkg/cmd/cli/apply" + vers "github.com/gofrontier-com/vertag/pkg/cmd/cli/version" "github.com/spf13/cobra" ) From b3a42c3409ddd80ad7ec1e46d4302a909aff77e8 Mon Sep 17 00:00:00 2001 From: Craig Anderson <1877372+CDA0@users.noreply.github.com> Date: Sat, 23 Dec 2023 16:14:02 +0000 Subject: [PATCH 05/17] debug --- pkg/cmd/app/apply/apply.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/cmd/app/apply/apply.go b/pkg/cmd/app/apply/apply.go index 2d801fa..1dc051d 100644 --- a/pkg/cmd/app/apply/apply.go +++ b/pkg/cmd/app/apply/apply.go @@ -27,6 +27,7 @@ func latestStableTag(r *git.Repository) (string, error) { var latestTagName string err = tagRefs.ForEach(func(tagRef *plumbing.Reference) error { if strings.Contains(tagRef.Name().String(), "-unstable") { + fmt.Println("Skipping unstable tag: ", tagRef.Name().String()) return nil } revision := plumbing.Revision(tagRef.Name().String()) @@ -49,10 +50,13 @@ func latestStableTag(r *git.Repository) (string, error) { latestTagCommit = commit latestTagName = tagRef.Name().String() } + fmt.Println(latestTagName) + fmt.Println(latestTagCommit) return nil }) if err != nil { + fmt.Println(err) return "", err } From da37fc0d0ed494f9bb0a2782873a1c38b1c7b3fc Mon Sep 17 00:00:00 2001 From: Craig Anderson <1877372+CDA0@users.noreply.github.com> Date: Wed, 27 Dec 2023 14:07:09 +0000 Subject: [PATCH 06/17] working, maybe --- go.mod | 1 + go.sum | 2 + pkg/cmd/app/apply/apply.go | 128 +++++++++++++++++++++++-------------- pkg/cmd/cli/apply/apply.go | 11 +++- 4 files changed, 91 insertions(+), 51 deletions(-) diff --git a/go.mod b/go.mod index 00a7ac2..ee66964 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,7 @@ require ( github.com/Microsoft/go-winio v0.6.1 // indirect github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect github.com/cloudflare/circl v1.3.3 // indirect + github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be // indirect github.com/cyphar/filepath-securejoin v0.2.4 // indirect github.com/emirpasic/gods v1.18.1 // indirect github.com/fatih/color v1.13.0 // indirect diff --git a/go.sum b/go.sum index 2e00586..93dcff2 100644 --- a/go.sum +++ b/go.sum @@ -20,6 +20,8 @@ github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghf github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs= github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= +github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be h1:J5BL2kskAlV9ckgEsNQXscjIaLiOYiZ75d4e94E6dcQ= +github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be/go.mod h1:mk5IQ+Y0ZeO87b858TlA645sVcEcbiX6YqP98kt+7+w= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= diff --git a/pkg/cmd/app/apply/apply.go b/pkg/cmd/app/apply/apply.go index 1dc051d..c9cf007 100644 --- a/pkg/cmd/app/apply/apply.go +++ b/pkg/cmd/app/apply/apply.go @@ -9,6 +9,7 @@ import ( "strings" "time" + "github.com/common-nighthawk/go-figure" "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/config" "github.com/go-git/go-git/v5/plumbing" @@ -27,7 +28,7 @@ func latestStableTag(r *git.Repository) (string, error) { var latestTagName string err = tagRefs.ForEach(func(tagRef *plumbing.Reference) error { if strings.Contains(tagRef.Name().String(), "-unstable") { - fmt.Println("Skipping unstable tag: ", tagRef.Name().String()) + // output.PrintlnInfo("Skipping unstable tag: ", tagRef.Name().String()) return nil } revision := plumbing.Revision(tagRef.Name().String()) @@ -50,13 +51,10 @@ func latestStableTag(r *git.Repository) (string, error) { latestTagCommit = commit latestTagName = tagRef.Name().String() } - fmt.Println(latestTagName) - fmt.Println(latestTagCommit) return nil }) if err != nil { - fmt.Println(err) return "", err } @@ -182,26 +180,28 @@ func changedFiles(r *git.Repository, latestTagOrHash string) []string { fileschanged = removeFromSlice(fileschanged, f.Path()) } } - return fileschanged } -func changedDirs(filesChanged []string) []string { +func changedDirs(filesChanged []string, modulesDir string) []string { dirschanged := make([]string, 0) for _, fc := range filesChanged { - a := strings.Split(fc, "/") - if len(a) > 2 { // make sure the changed file is of the form [azure resource-group main.tf] - inDirschanged := false - for _, dir := range dirschanged { - if dir == a[1] { - inDirschanged = true + if strings.HasPrefix(fc, modulesDir) { + a := strings.Split(fc, "/") + if len(a) > 2 { // make sure the changed file is of the form [azure resource-group main.tf] + inDirschanged := false + for _, dir := range dirschanged { + if dir == a[1] { + inDirschanged = true + } + } + if inDirschanged == false { + dirschanged = append(dirschanged, a[1]) } - } - if inDirschanged == false { - dirschanged = append(dirschanged, a[1]) } } } + return dirschanged } @@ -226,13 +226,13 @@ func getTagSuffix(r *git.Repository) string { if err != nil { fmt.Println(err) } - if cb != "main" && cb != "master" { + if cb != "refs/heads/main" && cb != "refs/heads/master" { return "-unstable" } return "" } -func Tag(r *git.Repository, tag string, authorName string, authorEmail string) error { +func createTag(r *git.Repository, tag string, authorName string, authorEmail string) error { headRef, _ := r.Head() headHash := headRef.Hash() tagger := &object.Signature{ @@ -244,62 +244,94 @@ func Tag(r *git.Repository, tag string, authorName string, authorEmail string) e Tagger: tagger, Message: tag, }) + output.PrintlnInfo("Created tag: ", tag) return err } -func PushWithTags(r *git.Repository) error { +func pushWithTags(r *git.Repository) error { rs := config.RefSpec("refs/tags/*:refs/tags/*") return r.Push(&git.PushOptions{ RefSpecs: []config.RefSpec{rs}, }) } -func Apply(modulesDir string, authorName string, authorEmail string) error { - - output.PrintlnfInfo("Apply here we go") - - r, err := git.PlainOpen(modulesDir) - if err != nil { - output.PrintlnError(err) - } - - tagrefs, err := r.Tags() - err = tagrefs.ForEach(func(t *plumbing.Reference) error { - fmt.Println(t) - return nil - }) - - cb, lt := getDiffRefs(r) - fmt.Printf("Current Branch: %s\nLatest Tag: %s\n", cb, lt) - - fileschanged := changedFiles(r, lt) - fmt.Println("Files changed: ", fileschanged) - dirschanged := changedDirs(fileschanged) - fmt.Println("Dirs changed: ", dirschanged) +func findNextTags(repo *git.Repository, dirschanged []string, modulesFullPath string) ([]string, error) { + tags := make([]string, 0) for _, d := range dirschanged { - ltc, err := latestTagContains(r, d) + ltc, err := latestTagContains(repo, d) if err != nil { output.PrintlnError(err) } - fmt.Println("Latest Tag Contains: ", ltc) + patchVersion := 0 - versionFromFile, _ := getVersion(path.Join(modulesDir, "modules", d)) + versionFromFile, _ := getVersion(path.Join(modulesFullPath, d)) ns := d if ltc != "" { - ltcSplit := strings.Split(ltc, "/") + ltcSplit := strings.Split(ltc, "/") // gives /refs/tags// ns = ltcSplit[2] - versionFromTag := ltcSplit[3] - latestPatch, _ := strconv.Atoi(strings.Split(ltcSplit[3], ".")[2]) + versionFromTagSplit := strings.Split(ltcSplit[3], ".") + versionFromTag := versionFromTagSplit[0] + "." + versionFromTagSplit[1] + patchFromTagIncSuffix := versionFromTagSplit[2] + patchFromTag := strings.TrimSuffix(patchFromTagIncSuffix, "-unstable") + latestPatch, _ := strconv.Atoi(patchFromTag) if versionFromFile == versionFromTag { patchVersion = latestPatch + 1 } else { patchVersion = 0 } } - suffix := getTagSuffix(r) - fmt.Println("new tag: ", fmt.Sprintf("%s/%s.%d%s", ns, versionFromFile, patchVersion, suffix)) + + suffix := getTagSuffix(repo) + tags = append(tags, fmt.Sprintf("%s/%s.%d%s", ns, versionFromFile, patchVersion, suffix)) } + return tags, nil +} + +func createTags(r *git.Repository, nextTags []string, dryRun bool, authorName string, authorEmail string) error { + for _, tag := range nextTags { + if dryRun { + fmt.Println("[Dry run] Would have created tag: ", tag) + } else { + err := createTag(r, tag, authorName, authorEmail) + if err != nil { + return err + } + err = pushWithTags(r) + if err != nil { + return err + } + } + } + + return nil +} + +func Apply(repoRoot string, modulesDir string, authorName string, authorEmail string, dryRun bool) error { + + myFigure := figure.NewFigure("VerTag", "", true) + myFigure.Print() + + r, err := git.PlainOpen(repoRoot) + if err != nil { + output.PrintlnError(err) + } + + cb, lt := getDiffRefs(r) + output.PrintfInfo("Comparing\n\tCurrent Branch: %s\nto\n\tLatest Tag: %s\n\n", cb, lt) + + fileschanged := changedFiles(r, lt) + dirschanged := changedDirs(fileschanged, modulesDir) + output.PrintlnInfo("Modules changed") + for _, d := range dirschanged { + output.PrintfInfo("\t%s\n", d) + } + output.PrintlnInfo("") + + nextTags, err := findNextTags(r, dirschanged, path.Join(repoRoot, modulesDir)) + + createTags(r, nextTags, dryRun, authorName, authorEmail) + return nil } diff --git a/pkg/cmd/cli/apply/apply.go b/pkg/cmd/cli/apply/apply.go index 7bd12c6..0e622e7 100644 --- a/pkg/cmd/cli/apply/apply.go +++ b/pkg/cmd/cli/apply/apply.go @@ -2,15 +2,18 @@ package apply import ( "os" + "path" "github.com/gofrontier-com/vertag/pkg/cmd/app/apply" "github.com/spf13/cobra" ) var ( - modulesRoot string + modulesDir string + repoRoot string authorName string authorEmail string + dryRun bool ) // NewCmdApply creates a command to apply config @@ -19,7 +22,7 @@ func NewCmdApply() *cobra.Command { Use: "apply", Short: "Apply config", RunE: func(_ *cobra.Command, _ []string) error { - if err := apply.Apply(modulesRoot, authorName, authorEmail); err != nil { + if err := apply.Apply(repoRoot, modulesDir, authorName, authorEmail, dryRun); err != nil { return err } @@ -31,8 +34,10 @@ func NewCmdApply() *cobra.Command { panic(err) } - cmd.Flags().StringVarP(&modulesRoot, "modules-dir", "m", wd, "Root directory for modules") + cmd.Flags().StringVarP(&modulesDir, "modules-dir", "m", path.Join(wd, "modules"), "Directory of the modules") + cmd.Flags().StringVarP(&repoRoot, "repo", "r", wd, "Root directory of the repo") cmd.Flags().StringVarP(&authorName, "author-name", "n", wd, "Name of the commiter") cmd.Flags().StringVarP(&authorEmail, "author-email", "e", wd, "Email of the commiter") + cmd.Flags().BoolVarP(&dryRun, "dry-run", "d", false, "Email of the commiter") return cmd } From e643a779d2268a7b9d040dd5913723d319d649d7 Mon Sep 17 00:00:00 2001 From: Craig Anderson <1877372+CDA0@users.noreply.github.com> Date: Wed, 27 Dec 2023 14:38:49 +0000 Subject: [PATCH 07/17] debug --- pkg/cmd/app/apply/apply.go | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/pkg/cmd/app/apply/apply.go b/pkg/cmd/app/apply/apply.go index c9cf007..62744f8 100644 --- a/pkg/cmd/app/apply/apply.go +++ b/pkg/cmd/app/apply/apply.go @@ -101,6 +101,16 @@ func latestTagContains(r *git.Repository, tagContains string) (string, error) { return latestTagName, nil } +func tagToSha(r *git.Repository, tag string) (string, error) { + revision := plumbing.Revision(tag) + tagCommitHash, err := r.ResolveRevision(revision) + if err != nil { + return "", err + } + + return tagCommitHash.String(), nil +} + func branchName(r *git.Repository) (string, error) { head, err := r.Head() @@ -244,8 +254,11 @@ func createTag(r *git.Repository, tag string, authorName string, authorEmail str Tagger: tagger, Message: tag, }) + if err != nil { + return err + } output.PrintlnInfo("Created tag: ", tag) - return err + return nil } func pushWithTags(r *git.Repository) error { @@ -292,14 +305,16 @@ func findNextTags(repo *git.Repository, dirschanged []string, modulesFullPath st func createTags(r *git.Repository, nextTags []string, dryRun bool, authorName string, authorEmail string) error { for _, tag := range nextTags { if dryRun { - fmt.Println("[Dry run] Would have created tag: ", tag) + output.Println("[Dry run] Would have created tag: ", tag) } else { err := createTag(r, tag, authorName, authorEmail) if err != nil { + output.PrintlnError(err) return err } err = pushWithTags(r) if err != nil { + output.PrintlnError(err) return err } } @@ -319,7 +334,8 @@ func Apply(repoRoot string, modulesDir string, authorName string, authorEmail st } cb, lt := getDiffRefs(r) - output.PrintfInfo("Comparing\n\tCurrent Branch: %s\nto\n\tLatest Tag: %s\n\n", cb, lt) + ltsha, _ := tagToSha(r, lt) + output.PrintfInfo("Comparing\n\tCurrent Branch: %s\nto\n\tLatest Tagged SHA: %s\n\n", cb, ltsha) fileschanged := changedFiles(r, lt) dirschanged := changedDirs(fileschanged, modulesDir) @@ -330,6 +346,9 @@ func Apply(repoRoot string, modulesDir string, authorName string, authorEmail st output.PrintlnInfo("") nextTags, err := findNextTags(r, dirschanged, path.Join(repoRoot, modulesDir)) + if err != nil { + output.PrintlnError(err) + } createTags(r, nextTags, dryRun, authorName, authorEmail) From 47613d3d6f0eb4edf055b04e8633ba9518483f38 Mon Sep 17 00:00:00 2001 From: Craig Anderson <1877372+CDA0@users.noreply.github.com> Date: Wed, 27 Dec 2023 14:51:14 +0000 Subject: [PATCH 08/17] remote-url --- pkg/cmd/app/apply/apply.go | 15 ++++++++++++--- pkg/cmd/cli/apply/apply.go | 4 +++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/pkg/cmd/app/apply/apply.go b/pkg/cmd/app/apply/apply.go index 62744f8..360ab5a 100644 --- a/pkg/cmd/app/apply/apply.go +++ b/pkg/cmd/app/apply/apply.go @@ -302,11 +302,20 @@ func findNextTags(repo *git.Repository, dirschanged []string, modulesFullPath st return tags, nil } -func createTags(r *git.Repository, nextTags []string, dryRun bool, authorName string, authorEmail string) error { +// AddRemove will add a named remote +func addRemote(r *git.Repository, name string, url string) { + r.CreateRemote(&config.RemoteConfig{ + Name: name, + URLs: []string{url}, + }) +} + +func createTags(r *git.Repository, nextTags []string, dryRun bool, authorName string, authorEmail string, remoteUrl string) error { for _, tag := range nextTags { if dryRun { output.Println("[Dry run] Would have created tag: ", tag) } else { + addRemote(r, "ci", remoteUrl) err := createTag(r, tag, authorName, authorEmail) if err != nil { output.PrintlnError(err) @@ -323,7 +332,7 @@ func createTags(r *git.Repository, nextTags []string, dryRun bool, authorName st return nil } -func Apply(repoRoot string, modulesDir string, authorName string, authorEmail string, dryRun bool) error { +func Apply(repoRoot string, modulesDir string, authorName string, authorEmail string, dryRun bool, remoteUrl string) error { myFigure := figure.NewFigure("VerTag", "", true) myFigure.Print() @@ -350,7 +359,7 @@ func Apply(repoRoot string, modulesDir string, authorName string, authorEmail st output.PrintlnError(err) } - createTags(r, nextTags, dryRun, authorName, authorEmail) + createTags(r, nextTags, dryRun, authorName, authorEmail, remoteUrl) return nil } diff --git a/pkg/cmd/cli/apply/apply.go b/pkg/cmd/cli/apply/apply.go index 0e622e7..f2af30d 100644 --- a/pkg/cmd/cli/apply/apply.go +++ b/pkg/cmd/cli/apply/apply.go @@ -13,6 +13,7 @@ var ( repoRoot string authorName string authorEmail string + remoteUrl string dryRun bool ) @@ -22,7 +23,7 @@ func NewCmdApply() *cobra.Command { Use: "apply", Short: "Apply config", RunE: func(_ *cobra.Command, _ []string) error { - if err := apply.Apply(repoRoot, modulesDir, authorName, authorEmail, dryRun); err != nil { + if err := apply.Apply(repoRoot, modulesDir, authorName, authorEmail, dryRun, remoteUrl); err != nil { return err } @@ -38,6 +39,7 @@ func NewCmdApply() *cobra.Command { cmd.Flags().StringVarP(&repoRoot, "repo", "r", wd, "Root directory of the repo") cmd.Flags().StringVarP(&authorName, "author-name", "n", wd, "Name of the commiter") cmd.Flags().StringVarP(&authorEmail, "author-email", "e", wd, "Email of the commiter") + cmd.Flags().StringVarP(&remoteUrl, "remote-url", "u", "", "CI Remote URL") cmd.Flags().BoolVarP(&dryRun, "dry-run", "d", false, "Email of the commiter") return cmd } From 0358c725e4326a739a716ae0afb17201bc55716e Mon Sep 17 00:00:00 2001 From: Craig Anderson <1877372+CDA0@users.noreply.github.com> Date: Wed, 27 Dec 2023 15:13:53 +0000 Subject: [PATCH 09/17] push to --- pkg/cmd/app/apply/apply.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/cmd/app/apply/apply.go b/pkg/cmd/app/apply/apply.go index 360ab5a..f2b0c6b 100644 --- a/pkg/cmd/app/apply/apply.go +++ b/pkg/cmd/app/apply/apply.go @@ -268,6 +268,14 @@ func pushWithTags(r *git.Repository) error { }) } +func pushWithTagsTo(r *git.Repository, remoteName string) error { + rs := config.RefSpec("refs/tags/*:refs/tags/*") + return r.Push(&git.PushOptions{ + RefSpecs: []config.RefSpec{rs}, + RemoteName: remoteName, + }) +} + func findNextTags(repo *git.Repository, dirschanged []string, modulesFullPath string) ([]string, error) { tags := make([]string, 0) @@ -321,7 +329,7 @@ func createTags(r *git.Repository, nextTags []string, dryRun bool, authorName st output.PrintlnError(err) return err } - err = pushWithTags(r) + err = pushWithTagsTo(r, "ci") if err != nil { output.PrintlnError(err) return err From 0626fcb4db9645a72ba6fa4e90d5543196a2fdc8 Mon Sep 17 00:00:00 2001 From: Craig Anderson <1877372+CDA0@users.noreply.github.com> Date: Wed, 27 Dec 2023 17:13:58 +0000 Subject: [PATCH 10/17] tidied up --- go.mod | 2 +- pkg/cmd/app/apply/apply.go | 359 ++----------------------------------- pkg/core/git.go | 162 +++++++++++++++++ pkg/core/types.go | 29 +++ pkg/core/util.go | 55 ++++++ pkg/core/vertag.go | 184 +++++++++++++++++++ 6 files changed, 444 insertions(+), 347 deletions(-) create mode 100644 pkg/core/git.go create mode 100644 pkg/core/types.go create mode 100644 pkg/core/util.go create mode 100644 pkg/core/vertag.go diff --git a/go.mod b/go.mod index ee66964..19e5fb7 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/gofrontier-com/vertag go 1.20 require ( + github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be github.com/go-git/go-git/v5 v5.11.0 github.com/gofrontier-com/go-utils v0.1.0 github.com/spf13/cobra v1.6.1 @@ -14,7 +15,6 @@ require ( github.com/Microsoft/go-winio v0.6.1 // indirect github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect github.com/cloudflare/circl v1.3.3 // indirect - github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be // indirect github.com/cyphar/filepath-securejoin v0.2.4 // indirect github.com/emirpasic/gods v1.18.1 // indirect github.com/fatih/color v1.13.0 // indirect diff --git a/pkg/cmd/app/apply/apply.go b/pkg/cmd/app/apply/apply.go index f2b0c6b..8839761 100644 --- a/pkg/cmd/app/apply/apply.go +++ b/pkg/cmd/app/apply/apply.go @@ -1,373 +1,40 @@ package apply import ( - "fmt" - "io" - "os" - "path" - "strconv" - "strings" - "time" - "github.com/common-nighthawk/go-figure" - "github.com/go-git/go-git/v5" - "github.com/go-git/go-git/v5/config" - "github.com/go-git/go-git/v5/plumbing" - "github.com/go-git/go-git/v5/plumbing/object" "github.com/gofrontier-com/go-utils/output" + "github.com/gofrontier-com/vertag/pkg/core" ) -// latestStableTag returns the most recent tag on the repository. -func latestStableTag(r *git.Repository) (string, error) { - tagRefs, err := r.Tags() - if err != nil { - return "", err - } - - var latestTagCommit *object.Commit - var latestTagName string - err = tagRefs.ForEach(func(tagRef *plumbing.Reference) error { - if strings.Contains(tagRef.Name().String(), "-unstable") { - // output.PrintlnInfo("Skipping unstable tag: ", tagRef.Name().String()) - return nil - } - revision := plumbing.Revision(tagRef.Name().String()) - tagCommitHash, err := r.ResolveRevision(revision) - if err != nil { - return err - } - - commit, err := r.CommitObject(*tagCommitHash) - if err != nil { - return err - } - - if latestTagCommit == nil { - latestTagCommit = commit - latestTagName = tagRef.Name().String() - } - - if commit.Committer.When.After(latestTagCommit.Committer.When) { - latestTagCommit = commit - latestTagName = tagRef.Name().String() - } - - return nil - }) - if err != nil { - return "", err - } - - return latestTagName, nil -} - -func latestTagContains(r *git.Repository, tagContains string) (string, error) { - tagRefs, err := r.Tags() - if err != nil { - return "", err - } - - var latestTagCommit *object.Commit - var latestTagName string - err = tagRefs.ForEach(func(tagRef *plumbing.Reference) error { - if strings.Contains(tagRef.Name().String(), tagContains) { - revision := plumbing.Revision(tagRef.Name().String()) - tagCommitHash, err := r.ResolveRevision(revision) - if err != nil { - return err - } - - commit, err := r.CommitObject(*tagCommitHash) - if err != nil { - return err - } - - if latestTagCommit == nil { - latestTagCommit = commit - latestTagName = tagRef.Name().String() - } - - if commit.Committer.When.After(latestTagCommit.Committer.When) { - latestTagCommit = commit - latestTagName = tagRef.Name().String() - } - } - return nil - }) - if err != nil { - return "", err - } - - return latestTagName, nil -} - -func tagToSha(r *git.Repository, tag string) (string, error) { - revision := plumbing.Revision(tag) - tagCommitHash, err := r.ResolveRevision(revision) - if err != nil { - return "", err - } - - return tagCommitHash.String(), nil -} - -func branchName(r *git.Repository) (string, error) { - - head, err := r.Head() - if err != nil { - return "", err - } - - return head.Name().String(), nil -} - -func initalCommitHash(r *git.Repository) string { - commits, _ := r.CommitObjects() - var initialHash plumbing.Hash - _ = commits.ForEach(func(c *object.Commit) error { - if c.NumParents() == 0 { - initialHash = c.Hash - } - return nil - }) - return initialHash.String() -} - -func getDiffRefs(r *git.Repository) (string, string) { - cb, err := branchName(r) - if err != nil { - return "", "" - } - - lt, err := latestStableTag(r) - if err != nil { - return "", "" - } - if lt == "" { - lt = initalCommitHash(r) - } - - return cb, lt -} - -func diff(r *git.Repository, tag string) (*object.Patch, error) { - revision := plumbing.Revision(tag) - tagCommitHash, err := r.ResolveRevision(revision) - if err != nil { - return nil, err - } - - tagCommit, err := r.CommitObject(*tagCommitHash) - headRef, _ := r.Head() - - headHash := headRef.Hash() - headCommit, _ := r.CommitObject(headHash) - return tagCommit.Patch(headCommit) -} - -func removeFromSlice(s []string, r string) []string { - for i, v := range s { - if v == r { - return append(s[:i], s[i+1:]...) - } - } - return s -} - -func changedFiles(r *git.Repository, latestTagOrHash string) []string { - fileschanged := make([]string, 0) - diff, _ := diff(r, latestTagOrHash) - stats := diff.Stats() - - for _, stat := range stats { - fileschanged = append(fileschanged, stat.Name) - } - - fps := diff.FilePatches() - for _, fp := range fps { - f, t := fp.Files() - if t == nil { - fileschanged = removeFromSlice(fileschanged, f.Path()) - } - } - return fileschanged -} - -func changedDirs(filesChanged []string, modulesDir string) []string { - dirschanged := make([]string, 0) - for _, fc := range filesChanged { - if strings.HasPrefix(fc, modulesDir) { - a := strings.Split(fc, "/") - if len(a) > 2 { // make sure the changed file is of the form [azure resource-group main.tf] - inDirschanged := false - for _, dir := range dirschanged { - if dir == a[1] { - inDirschanged = true - } - } - if inDirschanged == false { - dirschanged = append(dirschanged, a[1]) - } - } - } - } - - return dirschanged -} - -func getVersion(dir string) (string, error) { - file, err := os.Open(path.Join(dir, "VERSION")) - if err != nil { - return "", err - } - defer file.Close() +func Apply(repoRoot string, modulesDir string, authorName string, authorEmail string, dryRun bool, remoteUrl string) error { + myFigure := figure.NewFigure("VerTag", "", true) + myFigure.Print() - bytes, err := io.ReadAll(file) + vt := core.NewVertag(repoRoot, modulesDir, authorName, authorEmail, dryRun, remoteUrl) + err := vt.Init() if err != nil { - return "", err + output.PrintlnError(err) } - retval := strings.TrimSuffix(string(bytes), "\n") - return retval, nil -} - -func getTagSuffix(r *git.Repository) string { - cb, err := branchName(r) + err = vt.GetRefs() if err != nil { - fmt.Println(err) - } - if cb != "refs/heads/main" && cb != "refs/heads/master" { - return "-unstable" + output.PrintlnError(err) } - return "" -} -func createTag(r *git.Repository, tag string, authorName string, authorEmail string) error { - headRef, _ := r.Head() - headHash := headRef.Hash() - tagger := &object.Signature{ - Name: authorName, - Email: authorEmail, - When: time.Now(), - } - _, err := r.CreateTag(tag, headHash, &git.CreateTagOptions{ - Tagger: tagger, - Message: tag, - }) + err = vt.GetChanges() if err != nil { - return err - } - output.PrintlnInfo("Created tag: ", tag) - return nil -} - -func pushWithTags(r *git.Repository) error { - rs := config.RefSpec("refs/tags/*:refs/tags/*") - return r.Push(&git.PushOptions{ - RefSpecs: []config.RefSpec{rs}, - }) -} - -func pushWithTagsTo(r *git.Repository, remoteName string) error { - rs := config.RefSpec("refs/tags/*:refs/tags/*") - return r.Push(&git.PushOptions{ - RefSpecs: []config.RefSpec{rs}, - RemoteName: remoteName, - }) -} - -func findNextTags(repo *git.Repository, dirschanged []string, modulesFullPath string) ([]string, error) { - tags := make([]string, 0) - - for _, d := range dirschanged { - ltc, err := latestTagContains(repo, d) - if err != nil { - output.PrintlnError(err) - } - - patchVersion := 0 - versionFromFile, _ := getVersion(path.Join(modulesFullPath, d)) - ns := d - if ltc != "" { - ltcSplit := strings.Split(ltc, "/") // gives /refs/tags// - ns = ltcSplit[2] - versionFromTagSplit := strings.Split(ltcSplit[3], ".") - versionFromTag := versionFromTagSplit[0] + "." + versionFromTagSplit[1] - patchFromTagIncSuffix := versionFromTagSplit[2] - patchFromTag := strings.TrimSuffix(patchFromTagIncSuffix, "-unstable") - latestPatch, _ := strconv.Atoi(patchFromTag) - if versionFromFile == versionFromTag { - patchVersion = latestPatch + 1 - } else { - patchVersion = 0 - } - } - - suffix := getTagSuffix(repo) - tags = append(tags, fmt.Sprintf("%s/%s.%d%s", ns, versionFromFile, patchVersion, suffix)) - } - - return tags, nil -} - -// AddRemove will add a named remote -func addRemote(r *git.Repository, name string, url string) { - r.CreateRemote(&config.RemoteConfig{ - Name: name, - URLs: []string{url}, - }) -} - -func createTags(r *git.Repository, nextTags []string, dryRun bool, authorName string, authorEmail string, remoteUrl string) error { - for _, tag := range nextTags { - if dryRun { - output.Println("[Dry run] Would have created tag: ", tag) - } else { - addRemote(r, "ci", remoteUrl) - err := createTag(r, tag, authorName, authorEmail) - if err != nil { - output.PrintlnError(err) - return err - } - err = pushWithTagsTo(r, "ci") - if err != nil { - output.PrintlnError(err) - return err - } - } + output.PrintlnError(err) } - return nil -} - -func Apply(repoRoot string, modulesDir string, authorName string, authorEmail string, dryRun bool, remoteUrl string) error { - - myFigure := figure.NewFigure("VerTag", "", true) - myFigure.Print() - - r, err := git.PlainOpen(repoRoot) + err = vt.CalculateNextTags() if err != nil { output.PrintlnError(err) } - cb, lt := getDiffRefs(r) - ltsha, _ := tagToSha(r, lt) - output.PrintfInfo("Comparing\n\tCurrent Branch: %s\nto\n\tLatest Tagged SHA: %s\n\n", cb, ltsha) - - fileschanged := changedFiles(r, lt) - dirschanged := changedDirs(fileschanged, modulesDir) - output.PrintlnInfo("Modules changed") - for _, d := range dirschanged { - output.PrintfInfo("\t%s\n", d) - } - output.PrintlnInfo("") - - nextTags, err := findNextTags(r, dirschanged, path.Join(repoRoot, modulesDir)) + err = vt.WriteTags() if err != nil { output.PrintlnError(err) } - createTags(r, nextTags, dryRun, authorName, authorEmail, remoteUrl) - return nil } diff --git a/pkg/core/git.go b/pkg/core/git.go new file mode 100644 index 0000000..5cd4e51 --- /dev/null +++ b/pkg/core/git.go @@ -0,0 +1,162 @@ +package core + +import ( + "fmt" + "strings" + "time" + + "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/config" + "github.com/go-git/go-git/v5/plumbing" + "github.com/go-git/go-git/v5/plumbing/object" + "github.com/gofrontier-com/go-utils/output" +) + +// AddRemote will add a named remote +func (r *GitRepo) AddRemote(name string, url string) { + r.Repo.CreateRemote(&config.RemoteConfig{ + Name: name, + URLs: []string{url}, + }) +} + +func (r *GitRepo) PushWithTags() error { + rs := config.RefSpec("refs/tags/*:refs/tags/*") + return r.Repo.Push(&git.PushOptions{ + RefSpecs: []config.RefSpec{rs}, + }) +} + +func (r *GitRepo) PushWithTagsTo(remoteName string) error { + rs := config.RefSpec("refs/tags/*:refs/tags/*") + return r.Repo.Push(&git.PushOptions{ + RefSpecs: []config.RefSpec{rs}, + RemoteName: remoteName, + }) +} + +func (r *GitRepo) CreateTag(tag string) error { + headRef, _ := r.Repo.Head() + headHash := headRef.Hash() + tagger := &object.Signature{ + Name: r.Author.Name, + Email: r.Author.Email, + When: time.Now(), + } + _, err := r.Repo.CreateTag(tag, headHash, &git.CreateTagOptions{ + Tagger: tagger, + Message: tag, + }) + if err != nil { + return err + } + + output.PrintlnInfo("Created tag: ", tag) + return nil +} + +func (r *GitRepo) diff(tag string) (*object.Patch, error) { + revision := plumbing.Revision(tag) + tagCommitHash, err := r.Repo.ResolveRevision(revision) + if err != nil { + return nil, err + } + + tagCommit, err := r.Repo.CommitObject(*tagCommitHash) + headRef, _ := r.Repo.Head() + + headHash := headRef.Hash() + headCommit, _ := r.Repo.CommitObject(headHash) + return tagCommit.Patch(headCommit) +} + +func (r *GitRepo) branchName() (string, error) { + head, err := r.Repo.Head() + if err != nil { + return "", err + } + + return head.Name().String(), nil +} + +func (r *GitRepo) initalCommitHash() string { + commits, _ := r.Repo.CommitObjects() + var initialHash plumbing.Hash + _ = commits.ForEach(func(c *object.Commit) error { + if c.NumParents() == 0 { + initialHash = c.Hash + } + return nil + }) + return initialHash.String() +} + +func (r *GitRepo) changedFiles(latestTagOrHash string) []string { + fileschanged := make([]string, 0) + diff, _ := r.diff(latestTagOrHash) + stats := diff.Stats() + + for _, stat := range stats { + fileschanged = append(fileschanged, stat.Name) + } + + fps := diff.FilePatches() + for _, fp := range fps { + f, t := fp.Files() + if t == nil { + fileschanged = removeFromSlice(fileschanged, f.Path()) + } + } + return fileschanged +} + +func (r *GitRepo) latestTagContains(tagContains string) (string, error) { + tagRefs, err := r.Repo.Tags() + if err != nil { + return "", err + } + + var latestTagCommit *object.Commit + var latestTagName string + err = tagRefs.ForEach(func(tagRef *plumbing.Reference) error { + if strings.Contains(tagRef.Name().String(), tagContains) { + revision := plumbing.Revision(tagRef.Name().String()) + tagCommitHash, err := r.Repo.ResolveRevision(revision) + if err != nil { + return err + } + + commit, err := r.Repo.CommitObject(*tagCommitHash) + if err != nil { + return err + } + + if latestTagCommit == nil { + latestTagCommit = commit + latestTagName = tagRef.Name().String() + } + + if commit.Committer.When.After(latestTagCommit.Committer.When) { + latestTagCommit = commit + latestTagName = tagRef.Name().String() + } + } + return nil + }) + if err != nil { + return "", err + } + + return latestTagName, nil +} + +func (r *GitRepo) getTagSuffix() string { + cb, err := r.branchName() + if err != nil { + fmt.Println(err) + } + if cb != "refs/heads/main" && cb != "refs/heads/master" { + return "-unstable" + } + return "" +} diff --git a/pkg/core/types.go b/pkg/core/types.go new file mode 100644 index 0000000..8816f30 --- /dev/null +++ b/pkg/core/types.go @@ -0,0 +1,29 @@ +package core + +import ( + "github.com/go-git/go-git/v5" +) + +type Vertag struct { + Repo *GitRepo + RepoRoot string + ModulesDir string + ModulesFullPath string + DryRun bool + LatestStableTag string + LatestStableSHA string + CurrentBranch string + ModulesChanged []string + NextTags []string +} + +type GitRepo struct { + Repo *git.Repository + Author *GitAuthor + RemoteUrl string +} + +type GitAuthor struct { + Name string + Email string +} diff --git a/pkg/core/util.go b/pkg/core/util.go new file mode 100644 index 0000000..f9f437e --- /dev/null +++ b/pkg/core/util.go @@ -0,0 +1,55 @@ +package core + +import ( + "io" + "os" + "path" + "strings" +) + +func removeFromSlice(s []string, r string) []string { + for i, v := range s { + if v == r { + return append(s[:i], s[i+1:]...) + } + } + return s +} + +func changedDirs(filesChanged []string, modulesDir string) []string { + dirschanged := make([]string, 0) + for _, fc := range filesChanged { + if strings.HasPrefix(fc, modulesDir) { + a := strings.Split(fc, "/") + if len(a) > 2 { // make sure the changed file is of the form [azure resource-group main.tf] + inDirschanged := false + for _, dir := range dirschanged { + if dir == a[1] { + inDirschanged = true + } + } + if inDirschanged == false { + dirschanged = append(dirschanged, a[1]) + } + } + } + } + + return dirschanged +} + +func getVersion(dir string) (string, error) { + file, err := os.Open(path.Join(dir, "VERSION")) + if err != nil { + return "", err + } + defer file.Close() + + bytes, err := io.ReadAll(file) + if err != nil { + return "", err + } + retval := strings.TrimSuffix(string(bytes), "\n") + + return retval, nil +} diff --git a/pkg/core/vertag.go b/pkg/core/vertag.go new file mode 100644 index 0000000..77104fe --- /dev/null +++ b/pkg/core/vertag.go @@ -0,0 +1,184 @@ +package core + +import ( + "fmt" + "path" + "strconv" + "strings" + + "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/plumbing" + "github.com/go-git/go-git/v5/plumbing/object" + "github.com/gofrontier-com/go-utils/output" +) + +func NewVertag(repoRoot string, modulesDir string, authorName string, authorEmail string, dryRun bool, remoteUrl string) *Vertag { + r := &GitRepo{ + Author: &GitAuthor{ + Name: authorName, + Email: authorEmail, + }, + RemoteUrl: remoteUrl, + } + + return &Vertag{ + Repo: r, + RepoRoot: repoRoot, + ModulesDir: modulesDir, + ModulesFullPath: path.Join(repoRoot, modulesDir), + DryRun: dryRun, + } +} + +func (v *Vertag) Init() error { + r, err := git.PlainOpen(v.RepoRoot) + if err != nil { + return err + } + v.Repo.Repo = r + + return nil +} + +// GetLatestStableTag returns the most recent tag on the repository. +func (v *Vertag) GetLatestStableTag() error { + tagRefs, err := v.Repo.Repo.Tags() + if err != nil { + v.LatestStableSHA = v.Repo.initalCommitHash() + return err + } + + var latestTagCommit *object.Commit + var latestTagName string + err = tagRefs.ForEach(func(tagRef *plumbing.Reference) error { + if strings.Contains(tagRef.Name().String(), "-unstable") { + // output.PrintlnInfo("Skipping unstable tag: ", tagRef.Name().String()) + return nil + } + revision := plumbing.Revision(tagRef.Name().String()) + tagCommitHash, err := v.Repo.Repo.ResolveRevision(revision) + if err != nil { + return err + } + + commit, err := v.Repo.Repo.CommitObject(*tagCommitHash) + if err != nil { + return err + } + + if latestTagCommit == nil { + latestTagCommit = commit + latestTagName = tagRef.Name().String() + } + + if commit.Committer.When.After(latestTagCommit.Committer.When) { + latestTagCommit = commit + latestTagName = tagRef.Name().String() + } + + return nil + }) + if err != nil { + return err + } + + v.LatestStableTag = latestTagName + v.LatestStableSHA = latestTagCommit.Hash.String() + return nil +} + +func (v *Vertag) GetRefs() error { + err := v.getDiffRefs() + if err != nil { + return err + } + + output.PrintfInfo("Comparing\n\tCurrent Branch: %s\nto\n\tLatest Tagged SHA: %s\n\n", v.CurrentBranch, v.LatestStableSHA) + + return nil +} + +func (v *Vertag) getDiffRefs() error { + cb, err := v.Repo.branchName() + if err != nil { + return err + } + v.CurrentBranch = cb + + err = v.GetLatestStableTag() + if err != nil { + return err + } + + return nil +} + +func (v *Vertag) GetChanges() error { + fileschanged := v.Repo.changedFiles(v.LatestStableSHA) + dirschanged := changedDirs(fileschanged, v.ModulesDir) + output.PrintlnInfo("Modules changed") + for _, d := range dirschanged { + output.PrintfInfo("\t%s\n", d) + } + output.PrintlnInfo("") + v.ModulesChanged = dirschanged + return nil +} + +func (v *Vertag) CalculateNextTags() error { + tags := make([]string, 0) + + for _, d := range v.ModulesChanged { + ltc, err := v.Repo.latestTagContains(d) + if err != nil { + output.PrintlnError(err) + } + + patchVersion := 0 + versionFromFile, _ := getVersion(path.Join(v.ModulesFullPath, d)) + ns := d + if ltc != "" { + ltcSplit := strings.Split(ltc, "/") // gives /refs/tags// + ns = ltcSplit[2] + versionFromTagSplit := strings.Split(ltcSplit[3], ".") + versionFromTag := versionFromTagSplit[0] + "." + versionFromTagSplit[1] + patchFromTagIncSuffix := versionFromTagSplit[2] + patchFromTag := strings.TrimSuffix(patchFromTagIncSuffix, "-unstable") + latestPatch, _ := strconv.Atoi(patchFromTag) + if versionFromFile == versionFromTag { + patchVersion = latestPatch + 1 + } else { + patchVersion = 0 + } + } + + suffix := v.Repo.getTagSuffix() + tags = append(tags, fmt.Sprintf("%s/%s.%d%s", ns, versionFromFile, patchVersion, suffix)) + } + + v.NextTags = tags + + return nil +} + +func (v *Vertag) WriteTags() error { + for _, tag := range v.NextTags { + if v.DryRun { + output.Println("[Dry run] Would have created tag: ", tag) + } else { + v.Repo.AddRemote("ci", v.Repo.RemoteUrl) + err := v.Repo.CreateTag(tag) + if err != nil { + output.PrintlnError(err) + return err + } + err = v.Repo.PushWithTagsTo("ci") + if err != nil { + output.PrintlnError(err) + return err + } + } + } + + return nil +} From 2824a10d9966b5722757127f4ddc9502bc6bbd75 Mon Sep 17 00:00:00 2001 From: Craig Anderson <1877372+CDA0@users.noreply.github.com> Date: Fri, 29 Dec 2023 11:07:26 +0000 Subject: [PATCH 11/17] initial commit hash --- pkg/core/git.go | 2 +- pkg/core/vertag.go | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/core/git.go b/pkg/core/git.go index 5cd4e51..8539d38 100644 --- a/pkg/core/git.go +++ b/pkg/core/git.go @@ -79,7 +79,7 @@ func (r *GitRepo) branchName() (string, error) { return head.Name().String(), nil } -func (r *GitRepo) initalCommitHash() string { +func (r *GitRepo) initialCommitHash() string { commits, _ := r.Repo.CommitObjects() var initialHash plumbing.Hash _ = commits.ForEach(func(c *object.Commit) error { diff --git a/pkg/core/vertag.go b/pkg/core/vertag.go index 77104fe..7a402f7 100644 --- a/pkg/core/vertag.go +++ b/pkg/core/vertag.go @@ -44,7 +44,6 @@ func (v *Vertag) Init() error { func (v *Vertag) GetLatestStableTag() error { tagRefs, err := v.Repo.Repo.Tags() if err != nil { - v.LatestStableSHA = v.Repo.initalCommitHash() return err } @@ -83,7 +82,11 @@ func (v *Vertag) GetLatestStableTag() error { } v.LatestStableTag = latestTagName - v.LatestStableSHA = latestTagCommit.Hash.String() + if latestTagCommit == nil { + v.LatestStableSHA = v.Repo.initialCommitHash() + } else { + v.LatestStableSHA = latestTagCommit.Hash.String() + } return nil } From 05821fa985910cb22129ce62e7529314c3e51666 Mon Sep 17 00:00:00 2001 From: Craig Anderson <1877372+CDA0@users.noreply.github.com> Date: Sun, 31 Dec 2023 10:05:38 +0000 Subject: [PATCH 12/17] fix a couple of issues --- pkg/core/git.go | 41 --------------------------------- pkg/core/types.go | 1 + pkg/core/vertag.go | 56 +++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 54 insertions(+), 44 deletions(-) diff --git a/pkg/core/git.go b/pkg/core/git.go index 8539d38..13ea7b0 100644 --- a/pkg/core/git.go +++ b/pkg/core/git.go @@ -2,7 +2,6 @@ package core import ( "fmt" - "strings" "time" "github.com/go-git/go-git/v5" @@ -110,46 +109,6 @@ func (r *GitRepo) changedFiles(latestTagOrHash string) []string { return fileschanged } -func (r *GitRepo) latestTagContains(tagContains string) (string, error) { - tagRefs, err := r.Repo.Tags() - if err != nil { - return "", err - } - - var latestTagCommit *object.Commit - var latestTagName string - err = tagRefs.ForEach(func(tagRef *plumbing.Reference) error { - if strings.Contains(tagRef.Name().String(), tagContains) { - revision := plumbing.Revision(tagRef.Name().String()) - tagCommitHash, err := r.Repo.ResolveRevision(revision) - if err != nil { - return err - } - - commit, err := r.Repo.CommitObject(*tagCommitHash) - if err != nil { - return err - } - - if latestTagCommit == nil { - latestTagCommit = commit - latestTagName = tagRef.Name().String() - } - - if commit.Committer.When.After(latestTagCommit.Committer.When) { - latestTagCommit = commit - latestTagName = tagRef.Name().String() - } - } - return nil - }) - if err != nil { - return "", err - } - - return latestTagName, nil -} - func (r *GitRepo) getTagSuffix() string { cb, err := r.branchName() if err != nil { diff --git a/pkg/core/types.go b/pkg/core/types.go index 8816f30..1b8981b 100644 --- a/pkg/core/types.go +++ b/pkg/core/types.go @@ -12,6 +12,7 @@ type Vertag struct { DryRun bool LatestStableTag string LatestStableSHA string + LatestTag string CurrentBranch string ModulesChanged []string NextTags []string diff --git a/pkg/core/vertag.go b/pkg/core/vertag.go index 7a402f7..b34533f 100644 --- a/pkg/core/vertag.go +++ b/pkg/core/vertag.go @@ -90,6 +90,55 @@ func (v *Vertag) GetLatestStableTag() error { return nil } +func (v *Vertag) latestTagContains(tagContains string) error { + tagRefs, err := v.Repo.Repo.Tags() + if err != nil { + return err + } + + var latestTagCommit *object.Commit + var latestTagName string + err = tagRefs.ForEach(func(tagRef *plumbing.Reference) error { + if strings.Contains(tagRef.Name().String(), tagContains) { + revision := plumbing.Revision(tagRef.Name().String()) + tagCommitHash, err := v.Repo.Repo.ResolveRevision(revision) + if err != nil { + return err + } + + commit, err := v.Repo.Repo.CommitObject(*tagCommitHash) + if err != nil { + return err + } + + if latestTagCommit == nil { + latestTagCommit = commit + latestTagName = tagRef.Name().String() + } + + if commit.Committer.When.After(latestTagCommit.Committer.When) { + latestTagCommit = commit + latestTagName = tagRef.Name().String() + } + + if commit.Committer.When.Equal(latestTagCommit.Committer.When) { + if !strings.Contains(tagRef.Name().String(), "-unstable") { + latestTagCommit = commit + latestTagName = tagRef.Name().String() + } + } + } + return nil + }) + if err != nil { + return err + } + + v.LatestTag = latestTagName + + return nil +} + func (v *Vertag) GetRefs() error { err := v.getDiffRefs() if err != nil { @@ -132,7 +181,7 @@ func (v *Vertag) CalculateNextTags() error { tags := make([]string, 0) for _, d := range v.ModulesChanged { - ltc, err := v.Repo.latestTagContains(d) + err := v.latestTagContains(d) if err != nil { output.PrintlnError(err) } @@ -140,8 +189,9 @@ func (v *Vertag) CalculateNextTags() error { patchVersion := 0 versionFromFile, _ := getVersion(path.Join(v.ModulesFullPath, d)) ns := d - if ltc != "" { - ltcSplit := strings.Split(ltc, "/") // gives /refs/tags// + + if v.LatestTag != "" { + ltcSplit := strings.Split(v.LatestTag, "/") // gives /refs/tags// ns = ltcSplit[2] versionFromTagSplit := strings.Split(ltcSplit[3], ".") versionFromTag := versionFromTagSplit[0] + "." + versionFromTagSplit[1] From 1e3a7cd4c55e954c9e3e982b1e4ca3a50b76cde6 Mon Sep 17 00:00:00 2001 From: Craig Anderson <1877372+CDA0@users.noreply.github.com> Date: Sun, 31 Dec 2023 15:09:25 +0000 Subject: [PATCH 13/17] single push --- pkg/core/vertag.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/pkg/core/vertag.go b/pkg/core/vertag.go index b34533f..a50b90e 100644 --- a/pkg/core/vertag.go +++ b/pkg/core/vertag.go @@ -215,21 +215,35 @@ func (v *Vertag) CalculateNextTags() error { } func (v *Vertag) WriteTags() error { + if len(v.NextTags) == 0 { + output.PrintlnInfo("No tags to write and push") + return nil + } + for _, tag := range v.NextTags { if v.DryRun { output.Println("[Dry run] Would have created tag: ", tag) } else { - v.Repo.AddRemote("ci", v.Repo.RemoteUrl) err := v.Repo.CreateTag(tag) if err != nil { output.PrintlnError(err) return err } - err = v.Repo.PushWithTagsTo("ci") - if err != nil { - output.PrintlnError(err) - return err - } + } + } + + if v.Repo.RemoteUrl != "" { + v.Repo.AddRemote("ci", v.Repo.RemoteUrl) + err := v.Repo.PushWithTagsTo("ci") + if err != nil { + output.PrintlnError(err) + return err + } + } else { + err := v.Repo.PushWithTags() + if err != nil { + output.PrintlnError(err) + return err } } From 52ac5fab852d9380dc03eba95873aba28c6b7fb3 Mon Sep 17 00:00:00 2001 From: Craig Anderson <1877372+CDA0@users.noreply.github.com> Date: Wed, 3 Jan 2024 15:09:00 +0000 Subject: [PATCH 14/17] simplify --- pkg/cmd/app/apply/apply.go | 40 ----------- pkg/cmd/app/apply/apply_test.go | 1 - pkg/cmd/cli/apply/apply.go | 45 ------------- pkg/cmd/cli/apply/apply_test.go | 13 ---- pkg/cmd/cli/version/version.go | 31 --------- pkg/cmd/cli/version/version_test.go | 13 ---- pkg/cmd/vertag/vertag.go | 101 +++++++++++++++++++++++++--- pkg/core/vertag.go | 3 - 8 files changed, 91 insertions(+), 156 deletions(-) delete mode 100644 pkg/cmd/app/apply/apply.go delete mode 100644 pkg/cmd/app/apply/apply_test.go delete mode 100644 pkg/cmd/cli/apply/apply.go delete mode 100644 pkg/cmd/cli/apply/apply_test.go delete mode 100644 pkg/cmd/cli/version/version.go delete mode 100644 pkg/cmd/cli/version/version_test.go diff --git a/pkg/cmd/app/apply/apply.go b/pkg/cmd/app/apply/apply.go deleted file mode 100644 index 8839761..0000000 --- a/pkg/cmd/app/apply/apply.go +++ /dev/null @@ -1,40 +0,0 @@ -package apply - -import ( - "github.com/common-nighthawk/go-figure" - "github.com/gofrontier-com/go-utils/output" - "github.com/gofrontier-com/vertag/pkg/core" -) - -func Apply(repoRoot string, modulesDir string, authorName string, authorEmail string, dryRun bool, remoteUrl string) error { - myFigure := figure.NewFigure("VerTag", "", true) - myFigure.Print() - - vt := core.NewVertag(repoRoot, modulesDir, authorName, authorEmail, dryRun, remoteUrl) - err := vt.Init() - if err != nil { - output.PrintlnError(err) - } - - err = vt.GetRefs() - if err != nil { - output.PrintlnError(err) - } - - err = vt.GetChanges() - if err != nil { - output.PrintlnError(err) - } - - err = vt.CalculateNextTags() - if err != nil { - output.PrintlnError(err) - } - - err = vt.WriteTags() - if err != nil { - output.PrintlnError(err) - } - - return nil -} diff --git a/pkg/cmd/app/apply/apply_test.go b/pkg/cmd/app/apply/apply_test.go deleted file mode 100644 index 743a9c2..0000000 --- a/pkg/cmd/app/apply/apply_test.go +++ /dev/null @@ -1 +0,0 @@ -package apply diff --git a/pkg/cmd/cli/apply/apply.go b/pkg/cmd/cli/apply/apply.go deleted file mode 100644 index f2af30d..0000000 --- a/pkg/cmd/cli/apply/apply.go +++ /dev/null @@ -1,45 +0,0 @@ -package apply - -import ( - "os" - "path" - - "github.com/gofrontier-com/vertag/pkg/cmd/app/apply" - "github.com/spf13/cobra" -) - -var ( - modulesDir string - repoRoot string - authorName string - authorEmail string - remoteUrl string - dryRun bool -) - -// NewCmdApply creates a command to apply config -func NewCmdApply() *cobra.Command { - cmd := &cobra.Command{ - Use: "apply", - Short: "Apply config", - RunE: func(_ *cobra.Command, _ []string) error { - if err := apply.Apply(repoRoot, modulesDir, authorName, authorEmail, dryRun, remoteUrl); err != nil { - return err - } - - return nil - }, - } - wd, err := os.Getwd() - if err != nil { - panic(err) - } - - cmd.Flags().StringVarP(&modulesDir, "modules-dir", "m", path.Join(wd, "modules"), "Directory of the modules") - cmd.Flags().StringVarP(&repoRoot, "repo", "r", wd, "Root directory of the repo") - cmd.Flags().StringVarP(&authorName, "author-name", "n", wd, "Name of the commiter") - cmd.Flags().StringVarP(&authorEmail, "author-email", "e", wd, "Email of the commiter") - cmd.Flags().StringVarP(&remoteUrl, "remote-url", "u", "", "CI Remote URL") - cmd.Flags().BoolVarP(&dryRun, "dry-run", "d", false, "Email of the commiter") - return cmd -} diff --git a/pkg/cmd/cli/apply/apply_test.go b/pkg/cmd/cli/apply/apply_test.go deleted file mode 100644 index f953e0b..0000000 --- a/pkg/cmd/cli/apply/apply_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package apply - -import ( - "testing" -) - -func TestNewCmdApply(t *testing.T) { - cmd := NewCmdApply() - - if cmd.Use != "apply" { - t.Errorf("Use is not correct") - } -} diff --git a/pkg/cmd/cli/version/version.go b/pkg/cmd/cli/version/version.go deleted file mode 100644 index 6933a9c..0000000 --- a/pkg/cmd/cli/version/version.go +++ /dev/null @@ -1,31 +0,0 @@ -package version - -import ( - "github.com/gofrontier-com/go-utils/output" - "github.com/spf13/cobra" - goVersion "go.hein.dev/go-version" -) - -var ( - outputFmt string - shortened bool -) - -// NewCmdVersion creates a command to output the current version -func NewCmdVersion(version string, commit string, date string) *cobra.Command { - cmd := &cobra.Command{ - Use: "version", - Short: "Output version information", - RunE: func(_ *cobra.Command, _ []string) error { - resp := goVersion.FuncWithOutput(shortened, version, commit, date, outputFmt) - output.PrintfInfo(resp) - - return nil - }, - } - - cmd.Flags().BoolVarP(&shortened, "short", "s", false, "Print just the version number") - cmd.Flags().StringVarP(&outputFmt, "output", "o", "json", "Output format") - - return cmd -} diff --git a/pkg/cmd/cli/version/version_test.go b/pkg/cmd/cli/version/version_test.go deleted file mode 100644 index a6ecc89..0000000 --- a/pkg/cmd/cli/version/version_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package version - -import ( - "testing" -) - -func TestNewCmdVersion(t *testing.T) { - cmd := NewCmdVersion("0.0.0", "commitid", "date") - - if cmd.Use != "version" { - t.Errorf("Use is not correct") - } -} diff --git a/pkg/cmd/vertag/vertag.go b/pkg/cmd/vertag/vertag.go index 0534363..075d165 100644 --- a/pkg/cmd/vertag/vertag.go +++ b/pkg/cmd/vertag/vertag.go @@ -1,18 +1,86 @@ package vertag import ( - "github.com/gofrontier-com/vertag/pkg/cmd/cli/apply" - vers "github.com/gofrontier-com/vertag/pkg/cmd/cli/version" + "os" + "path" + + "github.com/common-nighthawk/go-figure" + "github.com/gofrontier-com/go-utils/output" + "github.com/gofrontier-com/vertag/pkg/core" "github.com/spf13/cobra" + goVersion "go.hein.dev/go-version" +) + +var ( + outputFmt string + shortened bool + modulesDir string + repoRoot string + authorName string + authorEmail string + remoteUrl string + dryRun bool + vers bool + help bool ) +func Apply(repoRoot string, modulesDir string, authorName string, authorEmail string, dryRun bool, remoteUrl string) error { + myFigure := figure.NewFigure("VerTag", "", true) + myFigure.Print() + + vt := core.NewVertag(repoRoot, modulesDir, authorName, authorEmail, dryRun, remoteUrl) + err := vt.Init() + if err != nil { + output.PrintlnError(err) + return err + } + + err = vt.GetRefs() + if err != nil { + output.PrintlnError(err) + return err + } + + err = vt.GetChanges() + if err != nil { + output.PrintlnError(err) + return err + } + + err = vt.CalculateNextTags() + if err != nil { + output.PrintlnError(err) + return err + } + + err = vt.WriteTags() + if err != nil { + output.PrintlnError(err) + return err + } + + return nil +} + func NewRootCmd(version string, commit string, date string) *cobra.Command { - rootCmd := &cobra.Command{ - Use: "vertag", - DisableFlagsInUseLine: true, - Short: "vertag is the command line tool for vertag", + cmd := &cobra.Command{ + Use: "vertag", + Short: "vertag is the command line tool for vertag", RunE: func(cmd *cobra.Command, args []string) error { - if err := cmd.Help(); err != nil { + if help { + if err := cmd.Help(); err != nil { + return err + } + } + + if vers { + resp := goVersion.FuncWithOutput(shortened, version, commit, date, outputFmt) + output.PrintfInfo(resp) + + return nil + } + + if err := Apply(repoRoot, modulesDir, authorName, authorEmail, dryRun, remoteUrl); err != nil { return err } @@ -20,8 +88,21 @@ func NewRootCmd(version string, commit string, date string) *cobra.Command { }, } - rootCmd.AddCommand(apply.NewCmdApply()) - rootCmd.AddCommand(vers.NewCmdVersion(version, commit, date)) + wd, err := os.Getwd() + if err != nil { + panic(err) + } + + cmd.Flags().StringVarP(&modulesDir, "modules-dir", "m", path.Join(wd, "modules"), "Directory of the modules") + cmd.Flags().StringVarP(&repoRoot, "repo", "r", wd, "Root directory of the repo") + cmd.Flags().StringVarP(&authorName, "author-name", "n", wd, "Name of the commiter") + cmd.Flags().StringVarP(&authorEmail, "author-email", "e", wd, "Email of the commiter") + cmd.Flags().StringVarP(&remoteUrl, "remote-url", "u", "", "CI Remote URL") + cmd.Flags().BoolVarP(&dryRun, "dry-run", "d", false, "Email of the commiter") + cmd.Flags().BoolVarP(&vers, "version", "v", false, "Version") + cmd.Flags().BoolVarP(&shortened, "short", "s", false, "Print just the version number") + cmd.Flags().StringVarP(&outputFmt, "output", "o", "json", "Output format") + cmd.Flags().BoolVarP(&help, "help", "h", false, "Version") - return rootCmd + return cmd } diff --git a/pkg/core/vertag.go b/pkg/core/vertag.go index a50b90e..c87e5c1 100644 --- a/pkg/core/vertag.go +++ b/pkg/core/vertag.go @@ -226,7 +226,6 @@ func (v *Vertag) WriteTags() error { } else { err := v.Repo.CreateTag(tag) if err != nil { - output.PrintlnError(err) return err } } @@ -236,13 +235,11 @@ func (v *Vertag) WriteTags() error { v.Repo.AddRemote("ci", v.Repo.RemoteUrl) err := v.Repo.PushWithTagsTo("ci") if err != nil { - output.PrintlnError(err) return err } } else { err := v.Repo.PushWithTags() if err != nil { - output.PrintlnError(err) return err } } From d2fe8e0bd40c70c220d8945046e6067f97f3ce7f Mon Sep 17 00:00:00 2001 From: Craig Anderson <1877372+CDA0@users.noreply.github.com> Date: Wed, 3 Jan 2024 17:36:07 +0000 Subject: [PATCH 15/17] readme docs --- README.md | 1 - README.rst | 59 ++++++++++++++++++++++++++++++++++++++++ pkg/cmd/vertag/vertag.go | 2 +- 3 files changed, 60 insertions(+), 2 deletions(-) delete mode 100644 README.md create mode 100644 README.rst diff --git a/README.md b/README.md deleted file mode 100644 index db31e88..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -# vertag diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..d14bf36 --- /dev/null +++ b/README.rst @@ -0,0 +1,59 @@ +.. image:: https://pkg.go.dev/badge/github.com/gofrontier-com/vertag.svg + :target: https://pkg.go.dev/github.com/gofrontier-com/vertag +.. image:: https://github.com/gofrontier-com/vertag/actions/workflows/ci.yml/badge.svg + :target: https://github.com/gofrontier-com/vertag/actions/workflows/ci.yml + +======= +Vertag +======= + +Vertag is a command line tool to manage versions of terraform modules with semver where the modules +are stored in the same repository. + +.. contents:: Table of Contents + :local: + +----- +About +----- + +~~~~~~~ +Vertag +~~~~~~~ + +Vertag has been built to assist with the management of terraform modules that are stored in the same +repository. It is designed to be used as part of a CI/CD pipeline. + +-------- +Download +-------- + +~~~~~~~ +Release +~~~~~~~ + +Binaries and packages of the latest stable release are available at `https://github.com/gofrontier-com/vertag/releases `_. + +----- +Usage +----- + +.. code:: bash + + $ vertag --help + Vertag is the command line tool for managing terraform modules versioning + + Usage: + vertag [flags] + + Flags: + -e, --author-email string Email of the commiter + -n, --author-name string Name of the commiter + -d, --dry-run Email of the commiter + -h, --help Version + -m, --modules-dir string Directory of the modules + -o, --output string Output format (default "json") + -u, --remote-url string CI Remote URL + -r, --repo string Root directory of the repo + -s, --short Print just the version number + -v, --version Version diff --git a/pkg/cmd/vertag/vertag.go b/pkg/cmd/vertag/vertag.go index 075d165..bcbb0eb 100644 --- a/pkg/cmd/vertag/vertag.go +++ b/pkg/cmd/vertag/vertag.go @@ -65,7 +65,7 @@ func Apply(repoRoot string, modulesDir string, authorName string, authorEmail st func NewRootCmd(version string, commit string, date string) *cobra.Command { cmd := &cobra.Command{ Use: "vertag", - Short: "vertag is the command line tool for vertag", + Short: "Vertag is the command line tool for managing terraform modules versioning", RunE: func(cmd *cobra.Command, args []string) error { if help { if err := cmd.Help(); err != nil { From 04dc1035cfba0742948d0d6dcb636ef1e8a683a0 Mon Sep 17 00:00:00 2001 From: Craig Anderson <1877372+CDA0@users.noreply.github.com> Date: Wed, 3 Jan 2024 17:45:40 +0000 Subject: [PATCH 16/17] docs --- README.rst | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index d14bf36..4cbcb7f 100644 --- a/README.rst +++ b/README.rst @@ -17,10 +17,6 @@ are stored in the same repository. About ----- -~~~~~~~ -Vertag -~~~~~~~ - Vertag has been built to assist with the management of terraform modules that are stored in the same repository. It is designed to be used as part of a CI/CD pipeline. @@ -28,10 +24,6 @@ repository. It is designed to be used as part of a CI/CD pipeline. Download -------- -~~~~~~~ -Release -~~~~~~~ - Binaries and packages of the latest stable release are available at `https://github.com/gofrontier-com/vertag/releases `_. ----- @@ -57,3 +49,9 @@ Usage -r, --repo string Root directory of the repo -s, --short Print just the version number -v, --version Version + +------------ +Contributing +------------ + +We welcome contributions to this repository. Please see `CONTRIBUTING.md `_ for more information. From d56da835f135a0fe08a3ba7d0474c871661bf202 Mon Sep 17 00:00:00 2001 From: Craig Anderson <1877372+CDA0@users.noreply.github.com> Date: Thu, 4 Jan 2024 12:16:08 +0000 Subject: [PATCH 17/17] bugfix --- pkg/core/util.go | 9 +++++++-- pkg/core/vertag.go | 24 +++++++++++++----------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/pkg/core/util.go b/pkg/core/util.go index f9f437e..bcce09c 100644 --- a/pkg/core/util.go +++ b/pkg/core/util.go @@ -16,19 +16,24 @@ func removeFromSlice(s []string, r string) []string { return s } -func changedDirs(filesChanged []string, modulesDir string) []string { +func changedDirs(filesChanged []string, modulesDir string, modulesPath string) []string { dirschanged := make([]string, 0) for _, fc := range filesChanged { if strings.HasPrefix(fc, modulesDir) { a := strings.Split(fc, "/") if len(a) > 2 { // make sure the changed file is of the form [azure resource-group main.tf] + dirExists := true + _, err := os.Stat(path.Join(modulesPath, a[1])) + if os.IsNotExist(err) { + dirExists = false + } inDirschanged := false for _, dir := range dirschanged { if dir == a[1] { inDirschanged = true } } - if inDirschanged == false { + if inDirschanged == false && dirExists == true { dirschanged = append(dirschanged, a[1]) } } diff --git a/pkg/core/vertag.go b/pkg/core/vertag.go index c87e5c1..505cb31 100644 --- a/pkg/core/vertag.go +++ b/pkg/core/vertag.go @@ -167,7 +167,7 @@ func (v *Vertag) getDiffRefs() error { func (v *Vertag) GetChanges() error { fileschanged := v.Repo.changedFiles(v.LatestStableSHA) - dirschanged := changedDirs(fileschanged, v.ModulesDir) + dirschanged := changedDirs(fileschanged, v.ModulesDir, v.ModulesFullPath) output.PrintlnInfo("Modules changed") for _, d := range dirschanged { output.PrintfInfo("\t%s\n", d) @@ -231,16 +231,18 @@ func (v *Vertag) WriteTags() error { } } - if v.Repo.RemoteUrl != "" { - v.Repo.AddRemote("ci", v.Repo.RemoteUrl) - err := v.Repo.PushWithTagsTo("ci") - if err != nil { - return err - } - } else { - err := v.Repo.PushWithTags() - if err != nil { - return err + if !v.DryRun { + if v.Repo.RemoteUrl != "" { + v.Repo.AddRemote("ci", v.Repo.RemoteUrl) + err := v.Repo.PushWithTagsTo("ci") + if err != nil { + return err + } + } else { + err := v.Repo.PushWithTags() + if err != nil { + return err + } } }