Skip to content

Commit

Permalink
automatically import azs
Browse files Browse the repository at this point in the history
  • Loading branch information
whites11 committed Mar 25, 2024
1 parent dda6332 commit 58f5f06
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 1 deletion.
92 changes: 92 additions & 0 deletions .github/workflows/aws_azs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Update helm/cluster-aws/files/azs-in-region.yaml with new availability zones
on:
schedule:
- cron: '0 0 * * *'

jobs:
import_new_regions_and_zones:
runs-on: ubuntu-20.04
container: quay.io/giantswarm/devctl:6.13.0
steps:
- name: Install dependencies
run: |
apk add --no-cache git
- name: Check out the code
uses: actions/checkout@v4
with:
clean: false
- name: Calculate md5sum of azs-in-region.yaml before the script runs
run: |
md5sum helm/cluster-aws/files/azs-in-region.yaml > /tmp/before
- name: Run azs-getter to update azs-in-region.yaml
env:
AWS_ACCESS_KEY_ID_CHINA: "${{ secrets.AWS_ACCESS_KEY_ID_CHINA }}"
AWS_SECRET_ACCESS_KEY_CHINA: "${{ secrets.AWS_SECRET_ACCESS_KEY_CHINA }}"
AWS_ACCESS_KEY_ID_EUROPE: "${{ secrets.AWS_ACCESS_KEY_ID_EUROPE }}"
AWS_SECRET_ACCESS_KEY_EUROPE: "${{ secrets.AWS_SECRET_ACCESS_KEY_EUROPE }}"
run: |
cd azs-getter
go get
go run main.go --dest-file=../helm/cluster-aws/files/azs-in-region.yaml
- name: Check for changes
id: check_changes
run: |
md5sum helm/cluster-aws/files/azs-in-region.yaml > /tmp/after
if diff /tmp/before /tmp/after
then
echo ::set-output name=needs_pr::true
fi
- name: Add Changelog entry
env:
msg: "Update Availability Zones in helm/cluster-aws/files/azs-in-region.yaml"
if: steps.check_changes.outputs.needs_pr == 'true'
run: |
# Line number containing unreleased tag
unreleased="$(grep -En '^## \[Unreleased\]' CHANGELOG.md | cut -f1 -d:)"
# Line number containing latest release
latest="$(grep -En '^## \[[0-9]+' CHANGELOG.md | head -n 1|cut -f1 -d:)"
# Current changes
current="$(cat CHANGELOG.md | head -n $(($latest - 1))|tail -n $(($latest - $unreleased - 1)))"
# look for "Added" section
added="$(echo "$current" | grep -En '^### Added'|cut -f1 -d:)"
if [ "$added" == "" ]
then
added=2
awk "NR==$(($unreleased + 1)){print \"\n## Added\n\"}7" CHANGELOG.md >changelog.tmp
mv changelog.tmp CHANGELOG.md
fi
# Add new changelog entry
awk "NR==$(($unreleased + $added + 2)){print \"- ${msg}\"}7" CHANGELOG.md >changelog.tmp
mv changelog.tmp CHANGELOG.md
- name: Prepare branch for PR
env:
remote_repo: "https://${{ github.actor }}:${{ secrets.TAYLORBOT_GITHUB_ACTION }}@github.com/${{ github.repository }}.git"
destination_branch_name: "automated-azs"
GITHUB_TOKEN: "${{ secrets.TAYLORBOT_GITHUB_ACTION }}"
base: "${{ github.ref }}"
if: steps.check_changes.outputs.needs_pr == 'true'
run: |
git config --global --add safe.directory "`pwd`"
git config --local user.email "[email protected]"
git config --local user.name "taylorbot"
git add -A
git commit -m "Update Availability Zones in helm/cluster-aws/files/azs-in-region.yaml"
git push "${remote_repo}" HEAD:${destination_branch_name} --force
- name: Create PR
uses: thomaseizinger/[email protected]
if: steps.check_changes.outputs.needs_pr == 'true'
with:
GITHUB_TOKEN: ${{ secrets.TAYLORBOT_GITHUB_ACTION }}
head: "automated-azs"
base: ${{ github.ref }}
title: "Update Availability Zones in helm/cluster-aws/files/azs-in-region.yaml"

18 changes: 17 additions & 1 deletion azs-getter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"flag"
"fmt"
"os"

Expand All @@ -22,6 +23,16 @@ type credentials struct {
func main() {
ctx := context.TODO()

var dest string

flag.StringVar(&dest, "dest-file", "../helm/cluster-aws/files/azs-in-region.yaml", "Path of the yaml file where to write the new AZs")
flag.Parse()

if dest == "" {
fmt.Println("No destination file provided, defaulting to stdout")
dest = "/dev/stdout"
}

creds := []credentials{
{
// EUROPE
Expand Down Expand Up @@ -66,7 +77,12 @@ func main() {
return
}

fmt.Print(string(b))
err = os.WriteFile(dest, b, 0644)
if err != nil {
fmt.Println("error writing azs to file")
fmt.Println(err)
return
}
}

func getAzsFromCredentials(ctx context.Context, sdkConfig aws.Config) (map[string][]string, error) {
Expand Down

0 comments on commit 58f5f06

Please sign in to comment.