diff --git a/cicd/buildapp/buildspec.yml b/cicd/buildapp/buildspec.yml index 42105252..baa49505 100644 --- a/cicd/buildapp/buildspec.yml +++ b/cicd/buildapp/buildspec.yml @@ -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 diff --git a/cicd/buildapp/githubvars.sh b/cicd/buildapp/githubvars.sh new file mode 100755 index 00000000..0fd83e03 --- /dev/null +++ b/cicd/buildapp/githubvars.sh @@ -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" diff --git a/cicd/buildapp/goreleaser.patch b/cicd/buildapp/goreleaser.patch new file mode 100644 index 00000000..95cda888 --- /dev/null +++ b/cicd/buildapp/goreleaser.patch @@ -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: