From 8e7b2472e2d0b1a63898eab0c9afe4db749f6203 Mon Sep 17 00:00:00 2001 From: chaseshak Date: Thu, 10 Aug 2023 09:20:45 -0500 Subject: [PATCH 1/7] Add Bamboo support --- lib/models/bamboo/audit.rb | 18 ++++++++++++++++ lib/models/bamboo/dry_run.rb | 20 ++++++++++++++++++ lib/models/bamboo/migrate.rb | 22 ++++++++++++++++++++ spec/models/bamboo/audit_spec.rb | 29 ++++++++++++++++++++++++++ spec/models/bamboo/dry_run_spec.rb | 27 ++++++++++++++++++++++++ spec/models/bamboo/migrate_spec.rb | 33 ++++++++++++++++++++++++++++++ 6 files changed, 149 insertions(+) create mode 100644 lib/models/bamboo/audit.rb create mode 100644 lib/models/bamboo/dry_run.rb create mode 100644 lib/models/bamboo/migrate.rb create mode 100644 spec/models/bamboo/audit_spec.rb create mode 100644 spec/models/bamboo/dry_run_spec.rb create mode 100644 spec/models/bamboo/migrate_spec.rb diff --git a/lib/models/bamboo/audit.rb b/lib/models/bamboo/audit.rb new file mode 100644 index 0000000..11c8103 --- /dev/null +++ b/lib/models/bamboo/audit.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Bamboo + class Audit + include IssueParser + + def initialize(issue_content, _) + @project = parameter_from_issue("Project", issue_content) + end + + def to_a + args = [] + args.push(["--project", @project]) unless @project.nil? + + return args unless args.empty? + end + end +end diff --git a/lib/models/bamboo/dry_run.rb b/lib/models/bamboo/dry_run.rb new file mode 100644 index 0000000..57e50b2 --- /dev/null +++ b/lib/models/bamboo/dry_run.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Bamboo + class DryRun + include IssueParser + + def initialize(issue_content, command) + @plan_slug = parameter_from_issue("Plan Slug", issue_content) + + @plan_type = command.options.fetch("plan-type", "build") + end + + def to_a + args = [@plan_type] + args.push(["--plan-slug", @plan_slug]) unless @plan_slug.nil? + + return args unless args.empty? + end + end +end diff --git a/lib/models/bamboo/migrate.rb b/lib/models/bamboo/migrate.rb new file mode 100644 index 0000000..25f5698 --- /dev/null +++ b/lib/models/bamboo/migrate.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module Bamboo + class Migrate + include IssueParser + + def initialize(issue_content, command) + @plan_slug = parameter_from_issue("Plan Slug", issue_content) + + @plan_type = command.options.fetch("plan-type", "build") + @target_url = command.options["target-url"] + end + + def to_a + args = [@plan_type] + args.push(["--plan-slug", @plan_slug]) unless @plan_slug.nil? + args.push(["--target-url", @target_url]) unless @target_url.nil? + + return args unless args.empty? + end + end +end diff --git a/spec/models/bamboo/audit_spec.rb b/spec/models/bamboo/audit_spec.rb new file mode 100644 index 0000000..a7c5121 --- /dev/null +++ b/spec/models/bamboo/audit_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +RSpec.describe Bamboo::Audit do + let(:audit) { described_class.new(issue_content, nil) } + + describe "#to_a" do + subject { audit.to_a } + + context "when issue_content contains no args" do + let(:issue_content) do + <<~ISSUE + Project: + ISSUE + end + + it { is_expected.to be_nil } + end + + context "when issue_content contains a project" do + let(:issue_content) do + <<~ISSUE + Project: Demo + ISSUE + end + + it { is_expected.to eq([["--project", "Demo"]]) } + end + end +end diff --git a/spec/models/bamboo/dry_run_spec.rb b/spec/models/bamboo/dry_run_spec.rb new file mode 100644 index 0000000..1061838 --- /dev/null +++ b/spec/models/bamboo/dry_run_spec.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +RSpec.describe Bamboo::DryRun do + let(:dry_run) { described_class.new(issue_content, command) } + let(:command) { Command.new(comment_body) } + + describe "#to_a" do + subject { dry_run.to_a } + let(:issue_content) do + <<~ISSUE + Plan Slug: PAN-PLAN + ISSUE + end + + context "when the comment body does not contain a plan type" do + let(:comment_body) { "/dry-run" } + + it { is_expected.to eq(["build", ["--plan-slug", "PAN-PLAN"]]) } + end + + context "when the comment body contains a plan type" do + let(:comment_body) { "/dry-run --plan-type deployment" } + + it { is_expected.to eq(["deployment", ["--plan-slug", "PAN-PLAN"]]) } + end + end +end diff --git a/spec/models/bamboo/migrate_spec.rb b/spec/models/bamboo/migrate_spec.rb new file mode 100644 index 0000000..39b5d32 --- /dev/null +++ b/spec/models/bamboo/migrate_spec.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +RSpec.describe Bamboo::Migrate do + let(:dry_run) { described_class.new(issue_content, command) } + let(:command) { Command.new(comment_body) } + + describe "#to_a" do + subject { dry_run.to_a } + let(:issue_content) do + <<~ISSUE + Plan Slug: PAN-PLAN + ISSUE + end + + context "when the comment body does not contain a pipeline type" do + let(:comment_body) { "/migrate" } + + it { is_expected.to eq(["build", ["--plan-slug", "PAN-PLAN"]]) } + end + + context "when the comment body contains a plan type" do + let(:comment_body) { "/dry-run --plan-type deployment" } + + it { is_expected.to eq(["deployment", ["--plan-slug", "PAN-PLAN"]]) } + end + + context "with a target-url" do + let(:comment_body) { "/migrate --target-url https://github.com/valet" } + + it { is_expected.to eq(["build", ["--plan-slug", "PAN-PLAN"], ["--target-url", "https://github.com/valet"]]) } + end + end +end From 40e55b9860c3148e2fd6a7a08fa8c8eab4827427 Mon Sep 17 00:00:00 2001 From: chaseshak Date: Thu, 10 Aug 2023 09:36:18 -0500 Subject: [PATCH 2/7] Add Bamboo documentation --- .github/ISSUE_TEMPLATE/bamboo.md | 21 +++++++++++++++++++++ Readme.md | 9 ++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 .github/ISSUE_TEMPLATE/bamboo.md diff --git a/.github/ISSUE_TEMPLATE/bamboo.md b/.github/ISSUE_TEMPLATE/bamboo.md new file mode 100644 index 0000000..32d4083 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bamboo.md @@ -0,0 +1,21 @@ +--- +name: Bamboo +about: Migrate Bamboo pipelines to GitHub Actions +title: "[Bamboo]:" +labels: bamboo +assignees: "" +--- + +## Inputs + +Plan Slug: _Replace this text with the Bamboo plan slug (e.g. PAN-SLUG) to migrate pipelines from._ + +## Available commands + +The following commands can be executed by adding a comment to this issue: + +- `/audit` +- `/dry-run --plan-type build|deployment` +- `/migrate --plan-type pipeline|deployment --target-url :github-repository-url` + +**Note:** The `plan-type` option will default to `build` if omitted. If any remaining options are missing, the command will not be successful. diff --git a/Readme.md b/Readme.md index 7f1aa62..9c9984b 100644 --- a/Readme.md +++ b/Readme.md @@ -22,7 +22,7 @@ The repository that is created from this template must have one of the following - Any action or reusable workflow can be used, regardless of who authored it or where it is defined. - Any action or reusable workflow that matches the specified criteria, plus those defined in a repository within the enterprise, can be used. - - Allow actions created by GitHub + - Allow actions created by GitHub - Allow actions by marketplace verified creators or icnlude `ruby/setup-ruby@v1` in the allowed list of actions and reusable workflows. See the [documentation](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository#managing-github-actions-permissions-for-your-repository) for more information related to these settings. @@ -95,6 +95,13 @@ Optionally, the following secrets can be set: - `TRAVIS_CI_INSTANCE_URL`: The base URL of your Travis CI instance (only required if it is **not** ). +### Bamboo + +The following secrets are required: + +- `BAMBOO_ACCESS_TOKEN`: The personal access token to access the Bamboo instance. +- `BAMBOO_INSTANCE_URL`: The base URL of your Bamboo instance. + ## Pipeline migration Once configured, pipelines can be migrated to GitHub Actions by opening an issue with the relevant issue template and following the instructions. From d80fecd8bbf84aff0ed613f29f28e2a8ffb55eeb Mon Sep 17 00:00:00 2001 From: chaseshak Date: Thu, 10 Aug 2023 09:39:07 -0500 Subject: [PATCH 3/7] Update workflows with Bamboo info --- .github/workflows/issue_ops.yml | 2 ++ .github/workflows/template-deploy.yml | 1 + 2 files changed, 3 insertions(+) diff --git a/.github/workflows/issue_ops.yml b/.github/workflows/issue_ops.yml index 66d2de3..e6b1514 100644 --- a/.github/workflows/issue_ops.yml +++ b/.github/workflows/issue_ops.yml @@ -26,6 +26,8 @@ env: GITLAB_INSTANCE_URL: ${{ secrets.gitlab_instance_url || 'https://gitlab.com' }} CIRCLE_CI_ACCESS_TOKEN: ${{ secrets.circle_ci_access_token }} CIRCLE_CI_SOURCE_GITHUB_ACCESS_TOKEN: ${{ secrets.circle_ci_source_github_access_token }} + BAMBOO_ACCESS_TOKEN: ${{ secrets.bamboo_access_token }} + BAMBOO_INSTANCE_URL: ${{ secrets.bamboo_instance_url }} jobs: execute-actions-importer: diff --git a/.github/workflows/template-deploy.yml b/.github/workflows/template-deploy.yml index 0375dbf..cee30a2 100644 --- a/.github/workflows/template-deploy.yml +++ b/.github/workflows/template-deploy.yml @@ -26,6 +26,7 @@ jobs: 'circle-ci', 'gitlab', 'travis-ci', + 'bamboo', 'actions-importer-running' ]; From 1284889e8f182f7d462bfcec21ccdff3f67d7a51 Mon Sep 17 00:00:00 2001 From: chaseshak Date: Thu, 10 Aug 2023 09:43:42 -0500 Subject: [PATCH 4/7] Add Bamboo to provider map --- lib/models/provider.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/models/provider.rb b/lib/models/provider.rb index 0d8258e..52ce6bf 100644 --- a/lib/models/provider.rb +++ b/lib/models/provider.rb @@ -14,7 +14,8 @@ class Provider "circle-ci" => ::CircleCI, "gitlab" => ::GitlabCI, "jenkins" => ::Jenkins, - "travis-ci" => ::TravisCI + "travis-ci" => ::TravisCI, + "bamboo" => ::Bamboo }.freeze def initialize(labels) From 252ef879514adba4c9f625f3a0134413df439d29 Mon Sep 17 00:00:00 2001 From: chaseshak Date: Thu, 10 Aug 2023 09:59:02 -0500 Subject: [PATCH 5/7] Fix typo in issue template --- .github/ISSUE_TEMPLATE/bamboo.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bamboo.md b/.github/ISSUE_TEMPLATE/bamboo.md index 32d4083..85d25cb 100644 --- a/.github/ISSUE_TEMPLATE/bamboo.md +++ b/.github/ISSUE_TEMPLATE/bamboo.md @@ -16,6 +16,6 @@ The following commands can be executed by adding a comment to this issue: - `/audit` - `/dry-run --plan-type build|deployment` -- `/migrate --plan-type pipeline|deployment --target-url :github-repository-url` +- `/migrate --plan-type build|deployment --target-url :github-repository-url` **Note:** The `plan-type` option will default to `build` if omitted. If any remaining options are missing, the command will not be successful. From 1fc3b251d6de1440d58877224f34b5519b3b31fb Mon Sep 17 00:00:00 2001 From: chaseshak Date: Thu, 10 Aug 2023 12:39:34 -0500 Subject: [PATCH 6/7] Add missing references for Bamboo --- Readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index 9c9984b..7e19318 100644 --- a/Readme.md +++ b/Readme.md @@ -2,7 +2,7 @@ The GitHub Actions Importer IssueOps repository demonstrates the functionality necessary to run GitHub Actions Importer commands through Actions and Issues, allowing you to migrate your CI/CD workflows without needing to install software on your local machine. This approach is especially useful for organizations that want to enable self-service migrations to GitHub Actions. -[GitHub Actions Importer](https://docs.github.com/en/actions/migrating-to-github-actions/automating-migration-with-github-actions-importer) helps plan, forecast, and automate the migration of Azure DevOps, CircleCI, GitLab, Jenkins, and Travis CI pipelines to GitHub Actions. GitHub Actions Importer is distributed as a CLI and offers various commands you can use to migrate pipelines: +[GitHub Actions Importer](https://docs.github.com/en/actions/migrating-to-github-actions/automating-migration-with-github-actions-importer) helps plan, forecast, and automate the migration of Azure DevOps, CircleCI, GitLab, Jenkins, Bamboo, and Travis CI pipelines to GitHub Actions. GitHub Actions Importer is distributed as a CLI and offers various commands you can use to migrate pipelines: - `audit`: An audit will fetch all the pipelines defined in an existing CI server, convert each pipeline to its equivalent in GitHub Actions, and write a report that summarizes how complete of a migration the GitHub Actions Importer can provide. - `dry-run`: A dry run will fetch a single pipeline definition, convert it to its equivalent in GitHub Actions, and write a file (or files) to disk containing the converted workflow. @@ -13,7 +13,7 @@ The GitHub Actions Importer IssueOps repository demonstrates the functionality n Complete the following steps: 1. Create a new repository using this repository as the template by clicking [here](https://github.com/actions/importer-issue-ops/generate). -2. Create the following labels in this new repository, if they are not already present: `jenkins`, `azure-devops`, `circle-ci`, `gitlab`, `travis-ci`, and `actions-importer-running`. +2. Create the following labels in this new repository, if they are not already present: `jenkins`, `azure-devops`, `circle-ci`, `gitlab`, `travis-ci`, `bamboo`, and `actions-importer-running`. 3. Add the repository secrets described below that are relevant to the CI/CD providers being migrated. ### Repository settings From 1fba0e7cd020d8c9682cb651ff56bda05bab094c Mon Sep 17 00:00:00 2001 From: Ethan Dennis Date: Thu, 10 Aug 2023 12:46:17 -0700 Subject: [PATCH 7/7] Update Readme.md --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 7e19318..e6759da 100644 --- a/Readme.md +++ b/Readme.md @@ -2,7 +2,7 @@ The GitHub Actions Importer IssueOps repository demonstrates the functionality necessary to run GitHub Actions Importer commands through Actions and Issues, allowing you to migrate your CI/CD workflows without needing to install software on your local machine. This approach is especially useful for organizations that want to enable self-service migrations to GitHub Actions. -[GitHub Actions Importer](https://docs.github.com/en/actions/migrating-to-github-actions/automating-migration-with-github-actions-importer) helps plan, forecast, and automate the migration of Azure DevOps, CircleCI, GitLab, Jenkins, Bamboo, and Travis CI pipelines to GitHub Actions. GitHub Actions Importer is distributed as a CLI and offers various commands you can use to migrate pipelines: +[GitHub Actions Importer](https://docs.github.com/en/actions/migrating-to-github-actions/automating-migration-with-github-actions-importer) helps plan, forecast, and automate the migration of Azure DevOps, Bamboo, CircleCI, GitLab, Jenkins, and Travis CI pipelines to GitHub Actions. GitHub Actions Importer is distributed as a CLI and offers various commands you can use to migrate pipelines: - `audit`: An audit will fetch all the pipelines defined in an existing CI server, convert each pipeline to its equivalent in GitHub Actions, and write a report that summarizes how complete of a migration the GitHub Actions Importer can provide. - `dry-run`: A dry run will fetch a single pipeline definition, convert it to its equivalent in GitHub Actions, and write a file (or files) to disk containing the converted workflow.