Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/release and promote cou #21

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/terraform-apply.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
jneo8 marked this conversation as resolved.
Show resolved Hide resolved
steps:
- name: Checkout branch
uses: actions/checkout@v4
Expand Down
22 changes: 22 additions & 0 deletions terraform-plans/configs/charmed-openstack-upgrader_main.tfvars
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
8 changes: 0 additions & 8 deletions terraform-plans/configs/soleng-tf-test-repo.tfvars

This file was deleted.

34 changes: 34 additions & 0 deletions terraform-plans/files/github/snap_promote.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
34 changes: 34 additions & 0 deletions terraform-plans/files/github/snap_release.yaml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions terraform-plans/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
3 changes: 2 additions & 1 deletion terraform-plans/modules/GitHub/settings/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions terraform-plans/modules/GitHub/settings/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ variable "repository" {
description = "GitHub repository name"
}

variable "repository_description" {
type = string
description = "GitHub repository description"
jneo8 marked this conversation as resolved.
Show resolved Hide resolved
}

variable "branch" {
type = string
description = "Branch name"
Expand Down
8 changes: 4 additions & 4 deletions terraform-plans/modules/GitHub/workflows/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
])
Expand All @@ -44,15 +44,15 @@ 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, "")
}
}

# Compare the fetched content with the local content to create a map of changed files
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]
}
}

Expand All @@ -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

Expand Down
3 changes: 2 additions & 1 deletion terraform-plans/modules/GitHub/workflows/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
8 changes: 7 additions & 1 deletion terraform-plans/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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."
}