Skip to content

Commit

Permalink
cmd: print binary version, check it in CD
Browse files Browse the repository at this point in the history
  • Loading branch information
dorav committed Nov 1, 2023
1 parent 7c469b7 commit 6db27a4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,18 @@ jobs:
go-version-file: go.mod
- name: Set BINARY_NAME
id: set_binary_name
env:
VERSION: ${{ github.event.inputs.version || 'v1' }}
run: |
echo "BINARY_NAME=atlas-action-${{ github.event.inputs.version || 'v1' }}" >> $GITHUB_ENV
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "BINARY_NAME=atlas-action-$VERSION" >> $GITHUB_ENV
- name: Compile Go Binary
run: |
go build -o $BINARY_NAME -ldflags "-X main.Version=${{ github.event.inputs.version || 'v1' }}" ./cmd/atlas-action
- name: Check version
run: |
OUTPUT=$(./$BINARY_NAME --version)
[ $(echo $OUTPUT | grep -i "^$VERSION") ] && echo Version=$OUTPUT || (echo "unexpected output: $OUTPUT, expected: $VERSION"; exit 1)
- name: Configure AWS credentials
run: |
aws configure set aws_access_key_id ${{ secrets.RELEASE_AWS_ACCESS_KEY_ID }}
Expand Down
13 changes: 12 additions & 1 deletion cmd/atlas-action/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,20 @@ func main() {
}
}

// VersionFlag is a flag type that can be used to display a version number, stored in the "version" variable.
type VersionFlag bool

// BeforeReset writes the version variable and terminates with a 0 exit status.
func (v VersionFlag) BeforeReset(app *kong.Kong) error {
_, err := fmt.Fprintln(app.Stdout, Version)
app.Exit(0)
return err
}

// RunAction is a command to run one of the Atlas GitHub Actions.
type RunAction struct {
Action string `help:"Command to run" required:""`
Action string `help:"Command to run" required:""`
Version VersionFlag `help:"Prints the version and exits"`
}

func (r *RunAction) Run(ctx context.Context, client *atlasexec.Client, action *githubactions.Action) error {
Expand Down

0 comments on commit 6db27a4

Please sign in to comment.