Skip to content

Commit

Permalink
Fix .goreleaser for CodeBuild
Browse files Browse the repository at this point in the history
Fixing mixing github variables in goreleaser builds.
  • Loading branch information
ChrisPates committed Jun 21, 2022
1 parent a22b7a3 commit 5ef4a3e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cicd/buildapp/buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ phases:

post_build:
commands:
# Tweak the .goreleaser.yml so it uses the vairables from .Env
- patch .goreleaser.yml cicd/buildapp/goreleaseer.patch

#Fetch the GitHub variables
- source cicd/buildapp/githubvars.sh

# Make main but only for the lambda (linux amd64)
- goreleaser build --snapshot --rm-dist --single-target

Expand Down
36 changes: 36 additions & 0 deletions cicd/buildapp/githubvars.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

export CI=true
export CodeBuild=true

export GitBranch=`git symbolic-ref HEAD --short 2>/dev/null`
if [ "$GitBranch" == "" ] ; then
GitBranch=`git branch -a --contains HEAD | sed -n 2p | awk '{ printf $1 }'`
export GitBranch=${GitBranch#remotes/origin/}
fi

export GitMessage=`git log -1 --pretty=%B`
export GitAuthor=`git log -1 --pretty=%an`
export GitAuthorEmail=`git log -1 --pretty=%ae`
export GitCommit=`git log -1 --pretty=%H`
export GITTag=`git describe --tags --abbrev=0`

export GitPullRequest=false
if [[ $GitBranch == pr-* ]] ; then
export GitPullRequest=${GitBranch#pr-}
fi

export GitProject=${APP_NAME}
export CodeBuildUrl=https://$AWS_DEFAULT_REGION.console.aws.amazon.com/codebuild/home?region=$AWS_DEFAULT_REGION#/builds/$CODEBUILD_BUILD_ID/view/new

echo "==> AWS CodeBuild Extra Environment Variables:"
echo "==> CI = $CI"
echo "==> CodeBuild = $CodeBuild"
echo "==> GitAuthor = $GitAuthor"
echo "==> GitAuthorEmail = $GitAuthorEmail"
echo "==> GitBranch = $GitBranch "
echo "==> GitCommit = $GitCommit"
echo "==> GitMessage = $GitMessage"
echo "==> GitTag = $GITTag"
echo "==> GitProject = $GitProject"
echo "==> GitPullRequest = $GitPullRequest"
11 changes: 11 additions & 0 deletions cicd/buildapp/goreleaser.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- .goreleaser.yml 2022-06-15 08:38:24.000000000 +0100
+++ .goreleaser-codebuild.yml 2022-06-21 12:33:43.000000000 +0100
@@ -22,7 +22,7 @@
- goos: windows
goarch: 386
ldflags:
- - -s -w -X github.com/awslabs/ssosync/cmd.version={{.Version}} -X github.com/awslabs/ssosync/cmd.commit={{.Commit}} -X github.com/awslabs/ssosync/cmd.date={{.Date}} -X github.com/awslabs/ssosync/cmd.builtBy=goreleaser
+ - -s -w -X github.com/awslabs/ssosync/cmd.version={{.Env.GitTag}} -X github.com/awslabs/ssosync/cmd.commit={{.Env.GitCommit}} -X github.com/awslabs/ssosync/cmd.date={{.Date}} -X github.com/awslabs/ssosync/cmd.builtBy=goreleaser -X github.com/awslabs/ssosync/cmd.goversion={{.Env.GoVersion}}
checksum:
name_template: '{{ .ProjectName }}_checksums.txt'
changelog:

0 comments on commit 5ef4a3e

Please sign in to comment.