diff --git a/.github/workflows/terraform-apply.yaml b/.github/workflows/terraform-apply.yaml index 864c227..fdc2cea 100644 --- a/.github/workflows/terraform-apply.yaml +++ b/.github/workflows/terraform-apply.yaml @@ -21,7 +21,8 @@ jobs: fail-fast: false matrix: repository: - - soleng-tf-test-repo + # The naming of the files should be $REPO_$BRANCH.tfvars + - charmed-openstack-upgrader_main steps: - name: Checkout branch uses: actions/checkout@v4 diff --git a/terraform-plans/configs/charmed-openstack-upgrader_main.tfvars b/terraform-plans/configs/charmed-openstack-upgrader_main.tfvars new file mode 100644 index 0000000..aa0d613 --- /dev/null +++ b/terraform-plans/configs/charmed-openstack-upgrader_main.tfvars @@ -0,0 +1,22 @@ +repository = "charmed-openstack-upgrader" +repository_description = "Automatic upgrade tool for Charmed Openstack" +branch = "main" +workflow_files = { + codeowners = { + source = "./files/github/CODEOWNERS" + destination = ".github/CODEOWNERS" + variables = {} + } + promote = { + source = "./files/github/snap_promote.yaml" + destination = ".github/workflows/promote.yaml" + variables = {} + } + release = { + source = "./files/github/snap_release.yaml" + destination = ".github/workflows/release.yaml" + variables = { + branch = "main" + } + } +} diff --git a/terraform-plans/configs/soleng-tf-test-repo.tfvars b/terraform-plans/configs/soleng-tf-test-repo.tfvars deleted file mode 100644 index 4fbb1a1..0000000 --- a/terraform-plans/configs/soleng-tf-test-repo.tfvars +++ /dev/null @@ -1,8 +0,0 @@ -repository = "soleng-tf-test-repo" -branch = "main" -workflow_files = { - codeowners = { - source = "./files/github/CODEOWNERS" - destination = ".github/CODEOWNERS" - } -} diff --git a/terraform-plans/files/github/snap_promote.yaml b/terraform-plans/files/github/snap_promote.yaml new file mode 100644 index 0000000..21b0aa0 --- /dev/null +++ b/terraform-plans/files/github/snap_promote.yaml @@ -0,0 +1,34 @@ +name: Promote snap to other tracks and channels + +on: + workflow_dispatch: + inputs: + destination-channel: + description: 'Destination Channel, e.g. latest/candidate' + required: true + origin-channel: + description: 'Origin Channel, e.g. latest/edge' + required: true + +jobs: + promote-snap: + name: Promote snap + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Snapcraft install + run: sudo snap install --classic snapcraft + - name: Get snap name + id: snap + run: echo "name=$(awk '/^name:/ {print $2}' snap/snapcraft.yaml)" >> "$GITHUB_OUTPUT" + - name: Snapcraft promote snap + env: + SNAPCRAFT_STORE_CREDENTIALS: $${{ secrets.STORE_LOGIN }} + SNAPCRAFT_HAS_TTY: "true" # this is necessary because snapcraft will not allow --yes for promotions of the edge channel https://github.com/canonical/snapcraft/issues/4439 + run: | + # Note: using `yes |` instead of `--yes` because snapcraft will + # refuse to non-interactively promote a snap from the edge + # channel if it is done without any branch qualifiers + yes | snapcraft promote $${{ steps.snap.outputs.name }} \ + --from-channel $${{ github.event.inputs.origin-channel }} \ + --to-channel $${{ github.event.inputs.destination-channel }} diff --git a/terraform-plans/files/github/snap_release.yaml b/terraform-plans/files/github/snap_release.yaml new file mode 100644 index 0000000..3ec75fd --- /dev/null +++ b/terraform-plans/files/github/snap_release.yaml @@ -0,0 +1,34 @@ +name: Publish snap + +on: + push: + branches: [ ${vars.branch} ] + release: + types: [ published ] + +jobs: + check: + uses: ./.github/workflows/check.yaml + secrets: inherit + + release: + runs-on: ubuntu-latest + needs: check + outputs: + snap: $${{ steps.build.outputs.snap }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Complete git history is required to generate the version from git tags. + - uses: snapcore/action-build@v1 + id: build + - uses: actions/upload-artifact@v4 + with: + name: snap + path: $${{ steps.build.outputs.snap }} + - uses: snapcore/action-publish@v1 + env: + SNAPCRAFT_STORE_CREDENTIALS: $${{ secrets.STORE_LOGIN }} + with: + snap: $${{ steps.build.outputs.snap }} + release: latest/edge diff --git a/terraform-plans/main.tf b/terraform-plans/main.tf index c258a45..aa76eb9 100644 --- a/terraform-plans/main.tf +++ b/terraform-plans/main.tf @@ -2,6 +2,7 @@ module "github_settings" { source = "./modules/GitHub/settings" owner = var.owner repository = var.repository + repository_description = var.repository_description branch = var.branch force_push_bypassers = ["${var.owner}/soleng-admin"] dismissal_restrictions = ["${var.owner}/soleng-admin", "${var.owner}/soleng-reviewers"] diff --git a/terraform-plans/modules/GitHub/settings/main.tf b/terraform-plans/modules/GitHub/settings/main.tf index c1ff943..ee7f60d 100644 --- a/terraform-plans/modules/GitHub/settings/main.tf +++ b/terraform-plans/modules/GitHub/settings/main.tf @@ -13,7 +13,8 @@ provider "github" { } resource "github_repository" "repo" { - name = var.repository + name = var.repository + description = var.repository_description has_issues = true has_projects = false diff --git a/terraform-plans/modules/GitHub/settings/variables.tf b/terraform-plans/modules/GitHub/settings/variables.tf index 8c5c75a..ba0378a 100644 --- a/terraform-plans/modules/GitHub/settings/variables.tf +++ b/terraform-plans/modules/GitHub/settings/variables.tf @@ -8,6 +8,11 @@ variable "repository" { description = "GitHub repository name" } +variable "repository_description" { + type = string + description = "GitHub repository description" +} + variable "branch" { type = string description = "Branch name" diff --git a/terraform-plans/modules/GitHub/workflows/main.tf b/terraform-plans/modules/GitHub/workflows/main.tf index 3d900d8..e8c6ceb 100644 --- a/terraform-plans/modules/GitHub/workflows/main.tf +++ b/terraform-plans/modules/GitHub/workflows/main.tf @@ -23,7 +23,7 @@ resource "random_string" "update_uid" { locals { repo_files = flatten([ for file_key, file_info in var.workflow_files : { - file = file_info.destination + file = file_info.destination source = file_info.source } ]) @@ -44,7 +44,7 @@ data "github_repository_file" "files" { locals { repository_files_content = { for file_key, file_info in var.workflow_files : file_info.destination => - try(data.github_repository_file.files["${file_info.destination}"].content, "") + try(data.github_repository_file.files["${file_info.destination}"].content, "") } } @@ -52,7 +52,7 @@ locals { locals { changed_files = { for file_key, file_info in var.workflow_files : file_key => file_info - if file(file_info.source) != local.repository_files_content[file_info.destination] + if file(file_info.source) != local.repository_files_content[file_info.destination] } } @@ -72,7 +72,7 @@ resource "github_repository_file" "workflows_files" { repository = var.repository branch = github_branch.workflows_branch[0].branch file = each.value.destination - content = file(each.value.source) + content = templatefile(each.value.source, { vars = each.value.variables }) commit_message = "update ${each.value.destination}" overwrite_on_create = true diff --git a/terraform-plans/modules/GitHub/workflows/variables.tf b/terraform-plans/modules/GitHub/workflows/variables.tf index 7a84ea7..ab280ae 100644 --- a/terraform-plans/modules/GitHub/workflows/variables.tf +++ b/terraform-plans/modules/GitHub/workflows/variables.tf @@ -36,6 +36,7 @@ variable "workflow_files" { type = map(object({ source = string destination = string + variables = map(string) })) - description = "GitHub workflow files" + description = "GitHub workflow file. The source is the file path of the template file." } diff --git a/terraform-plans/variables.tf b/terraform-plans/variables.tf index 574e5ed..b4ff9e9 100644 --- a/terraform-plans/variables.tf +++ b/terraform-plans/variables.tf @@ -8,6 +8,11 @@ variable "repository" { description = "GitHub repository name" } +variable "repository_description" { + type = string + description = "GitHub repository description" +} + variable "branch" { type = string description = "git branch name" @@ -18,6 +23,7 @@ variable "workflow_files" { type = map(object({ source = string destination = string + variables = map(string) })) - description = "GitHub workflow files" + description = "GitHub workflow file. The source is the file path of the template file." }