Skip to content

Commit 238b17c

Browse files
committed
Created Project
0 parents  commit 238b17c

35 files changed

Lines changed: 113946 additions & 0 deletions

.github/workflows/go.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Go
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
lint:
11+
name: Lint
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v4
18+
with:
19+
go-version: '1.24'
20+
21+
- name: golangci-lint
22+
uses: golangci/golangci-lint-action@v3
23+
with:
24+
version: latest
25+
26+
test:
27+
name: Test
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@v4
31+
32+
- name: Set up Go
33+
uses: actions/setup-go@v4
34+
with:
35+
go-version: '1.24'
36+
37+
- name: Install dependencies
38+
run: go mod download
39+
40+
- name: Run tests with coverage
41+
run: go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
42+
43+
- name: Upload coverage report
44+
uses: codecov/codecov-action@v3
45+
with:
46+
file: ./coverage.txt
47+
fail_ci_if_error: false
48+
49+
build:
50+
name: Build
51+
runs-on: ubuntu-latest
52+
needs: [lint, test]
53+
steps:
54+
- uses: actions/checkout@v4
55+
56+
- name: Set up Go
57+
uses: actions/setup-go@v4
58+
with:
59+
go-version: '1.24'
60+
61+
- name: Install dependencies
62+
run: go mod download
63+
64+
- name: Build
65+
run: go build -v -o aws-meta .
66+
67+
- name: Upload build artifact
68+
uses: actions/upload-artifact@v4
69+
with:
70+
name: aws-meta
71+
path: aws-meta

.github/workflows/release.yml

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
name: Nightly Release
2+
3+
on:
4+
schedule:
5+
# Run at midnight UTC every day
6+
- cron: '0 0 * * *'
7+
# Allow manual triggering
8+
workflow_dispatch:
9+
10+
jobs:
11+
generate:
12+
runs-on: ubuntu-latest
13+
outputs:
14+
changes_made: ${{ steps.commit_changes.outputs.changes_made }}
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Set up Go
22+
uses: actions/setup-go@v4
23+
with:
24+
go-version: '1.24'
25+
26+
- name: Run generate command
27+
run: go run . generate
28+
29+
- name: Check for changes
30+
id: check_for_changes
31+
run: |
32+
if [[ -n "$(git status --porcelain)" ]]; then
33+
echo "Changes detected after running generate command"
34+
echo "CHANGES_DETECTED=true" >> $GITHUB_ENV
35+
else
36+
echo "No changes detected after running generate command"
37+
echo "CHANGES_DETECTED=false" >> $GITHUB_ENV
38+
fi
39+
40+
- name: Commit changes
41+
id: commit_changes
42+
if: env.CHANGES_DETECTED == 'true'
43+
run: |
44+
git config --local user.email "action@github.com"
45+
git config --local user.name "GitHub Action"
46+
git add .
47+
git commit -m "Nightly update: $(date +'%Y-%m-%d')"
48+
git push
49+
echo "changes_made=true" >> $GITHUB_OUTPUT
50+
51+
- name: No changes to commit
52+
if: env.CHANGES_DETECTED == 'false'
53+
run: |
54+
echo "No changes to commit"
55+
echo "changes_made=false" >> $GITHUB_OUTPUT
56+
57+
check-for-changes:
58+
needs: generate
59+
runs-on: ubuntu-latest
60+
outputs:
61+
has_changes: ${{ steps.check_changes.outputs.has_changes }}
62+
new_tag: ${{ steps.create_tag.outputs.new_tag }}
63+
steps:
64+
- name: Checkout
65+
uses: actions/checkout@v4
66+
with:
67+
fetch-depth: 0
68+
69+
- name: Get latest release
70+
id: latest_release
71+
run: |
72+
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
73+
echo "latest_tag=${LATEST_TAG}" >> $GITHUB_OUTPUT
74+
echo "Latest tag: ${LATEST_TAG}"
75+
continue-on-error: true
76+
77+
- name: Check for changes since last release
78+
id: check_changes
79+
run: |
80+
LATEST_TAG="${{ steps.latest_release.outputs.latest_tag }}"
81+
82+
# Check if the tag exists in the repository
83+
if [ "$LATEST_TAG" = "v0.0.0" ] || ! git rev-parse --verify "$LATEST_TAG" &>/dev/null; then
84+
echo "No valid previous tag found, creating first release"
85+
echo "has_changes=true" >> $GITHUB_OUTPUT
86+
else
87+
CHANGES=$(git log --oneline ${LATEST_TAG}..HEAD)
88+
if [ -n "$CHANGES" ]; then
89+
echo "Changes found since last release"
90+
echo "has_changes=true" >> $GITHUB_OUTPUT
91+
else
92+
echo "No changes since last release"
93+
echo "has_changes=false" >> $GITHUB_OUTPUT
94+
fi
95+
fi
96+
97+
- name: Create new tag
98+
id: create_tag
99+
if: steps.check_changes.outputs.has_changes == 'true'
100+
run: |
101+
LATEST_TAG="${{ steps.latest_release.outputs.latest_tag }}"
102+
if [ -z "$LATEST_TAG" ] || [ "$LATEST_TAG" == "v0.0.0" ]; then
103+
NEW_TAG="v0.1.0"
104+
else
105+
# Extract version components
106+
MAJOR=$(echo $LATEST_TAG | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\1/')
107+
MINOR=$(echo $LATEST_TAG | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\2/')
108+
PATCH=$(echo $LATEST_TAG | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\3/')
109+
110+
# Increment patch version
111+
PATCH=$((PATCH + 1))
112+
NEW_TAG="v${MAJOR}.${MINOR}.${PATCH}"
113+
fi
114+
115+
echo "Creating new tag: ${NEW_TAG}"
116+
echo "new_tag=${NEW_TAG}" >> $GITHUB_OUTPUT
117+
118+
# Configure git
119+
git config --local user.email "action@github.com"
120+
git config --local user.name "GitHub Action"
121+
122+
# Create and push tag
123+
git tag $NEW_TAG
124+
git push origin $NEW_TAG
125+
126+
build:
127+
needs: check-for-changes
128+
if: needs.check-for-changes.outputs.has_changes == 'true'
129+
runs-on: ubuntu-latest
130+
steps:
131+
- name: Checkout
132+
uses: actions/checkout@v4
133+
with:
134+
fetch-depth: 0
135+
136+
- name: Set up Go
137+
uses: actions/setup-go@v4
138+
with:
139+
go-version: '1.24'
140+
141+
- name: Run tests
142+
run: go test -v ./pkg/...
143+
144+
- name: Build
145+
run: go build -v .
146+
147+
- name: Create Release
148+
id: create_release
149+
uses: softprops/action-gh-release@v1
150+
with:
151+
tag_name: ${{ needs.check-for-changes.outputs.new_tag }}
152+
name: Nightly Release ${{ needs.check-for-changes.outputs.new_tag }}
153+
draft: false
154+
prerelease: false
155+
token: ${{ secrets.GITHUB_TOKEN }}
156+
body: |
157+
Automated nightly release created on $(date +'%Y-%m-%d')
158+
159+
This release contains all changes since the previous release.
160+
161+
- name: Package data manifests
162+
run: |
163+
mkdir -p release/aws-meta-data
164+
cp -r pkg/data/manifests/* release/aws-meta-data/
165+
cd release
166+
zip -r aws-meta-data.zip aws-meta-data/
167+
168+
- name: Package services
169+
run: |
170+
mkdir -p release/aws-meta-services
171+
cp pkg/services/list.go release/aws-meta-services/
172+
cd release
173+
zip -r aws-meta-services.zip aws-meta-services/
174+
175+
- name: Upload Release Assets
176+
uses: softprops/action-gh-release@v1
177+
with:
178+
tag_name: ${{ needs.check-for-changes.outputs.new_tag }}
179+
files: |
180+
./release/aws-meta-data.zip
181+
./release/aws-meta-services.zip
182+
./aws-meta
183+
token: ${{ secrets.GITHUB_TOKEN }}
184+
185+
publish-go-pkg:
186+
needs: build
187+
runs-on: ubuntu-latest
188+
steps:
189+
- name: Checkout
190+
uses: actions/checkout@v4
191+
192+
- name: Set up Go
193+
uses: actions/setup-go@v4
194+
with:
195+
go-version: '1.24'
196+
197+
- name: Publish Go packages
198+
run: |
199+
GOPROXY=proxy.golang.org go list -m github.com/myerscode/aws-meta/pkg/data@${{ needs.check-for-changes.outputs.new_tag }}
200+
GOPROXY=proxy.golang.org go list -m github.com/myerscode/aws-meta/pkg/services@${{ needs.check-for-changes.outputs.new_tag }}
201+
env:
202+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

aws-meta

10.5 MB
Binary file not shown.

cmd/generate.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/myerscode/aws-meta/internal/aws"
7+
"github.com/myerscode/aws-meta/internal/github"
8+
"github.com/myerscode/aws-meta/internal/util"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
var generateCmd = &cobra.Command{
13+
Use: "generate",
14+
Short: "Generate AWS metadata files.",
15+
Run: func(cmd *cobra.Command, args []string) {
16+
17+
botoRepo := github.Repo{
18+
Config: github.Config{
19+
Owner: "boto",
20+
RepoName: "botocore",
21+
Branch: "main",
22+
},
23+
Client: github.NewGitHubClient(""),
24+
}
25+
26+
botocore := aws.Botocore{Repo: botoRepo}
27+
28+
tags, err := botocore.Repo.FetchTags(1)
29+
30+
if err != nil {
31+
util.PrintErrorAndExit(err)
32+
}
33+
34+
for _, tag := range tags {
35+
util.LogInfo(fmt.Sprintf("Generating Partition List for Tag: %s", tag.Name))
36+
botocore.GeneratePartitionList(tag)
37+
util.LogInfo(fmt.Sprintf("Generating Service List for Tag: %s", tag.Name))
38+
botocore.GenerateServiceList(tag)
39+
util.LogInfo(fmt.Sprintf("Generating Region Service List for Tag: %s", tag.Name))
40+
botocore.GenerateRegionServicesList(tag)
41+
}
42+
},
43+
}
44+
45+
func init() {
46+
rootCmd.AddCommand(generateCmd)
47+
}

cmd/root.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
Copyright © 2025 NAME HERE <EMAIL ADDRESS>
3+
*/
4+
package cmd
5+
6+
import (
7+
"fmt"
8+
"github.com/myerscode/aws-meta/internal/util"
9+
"github.com/spf13/pflag"
10+
"os"
11+
12+
"github.com/spf13/cobra"
13+
"github.com/spf13/viper"
14+
)
15+
16+
var cfgFile string
17+
18+
// rootCmd represents the base command when called without any subcommands
19+
var rootCmd = &cobra.Command{
20+
Use: "aws-meta",
21+
Short: "A tool for collecting and looking at information about AWS Partitions and Regions.",
22+
PersistentPreRun: func(cmd *cobra.Command, args []string) {
23+
envVarBind(cmd)
24+
},
25+
}
26+
27+
func Execute() {
28+
err := rootCmd.Execute()
29+
if err != nil {
30+
os.Exit(1)
31+
}
32+
}
33+
34+
func init() {
35+
cobra.OnInitialize(initConfig)
36+
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.aws-meta.yaml)")
37+
38+
rootCmd.Flags().BoolP("trace", "t", false, "Show full trace logs.")
39+
}
40+
41+
func initConfig() {
42+
if cfgFile != "" {
43+
viper.SetConfigFile(cfgFile)
44+
} else {
45+
home, err := os.UserHomeDir()
46+
cobra.CheckErr(err)
47+
48+
viper.AddConfigPath(home)
49+
viper.SetConfigType("yaml")
50+
viper.SetConfigName(".aws-meta")
51+
}
52+
53+
viper.SetEnvPrefix("AWSMETA")
54+
viper.AutomaticEnv()
55+
56+
if err := viper.ReadInConfig(); err == nil {
57+
util.LogError(fmt.Sprintf("Error sing config file: %s", viper.ConfigFileUsed()))
58+
}
59+
}
60+
61+
func envVarBind(cmd *cobra.Command) {
62+
cmd.Flags().VisitAll(func(f *pflag.Flag) {
63+
configName := f.Name
64+
if !f.Changed && viper.IsSet(configName) {
65+
val := viper.Get(configName)
66+
err := cmd.Flags().Set(f.Name, fmt.Sprintf("%v", val))
67+
if err != nil {
68+
util.LogError(err.Error())
69+
}
70+
}
71+
})
72+
}

0 commit comments

Comments
 (0)