diff --git a/.github/workflows/pr-ci.yml b/.github/workflows/pr-ci.yml index b65cf9a7..b4294ccc 100644 --- a/.github/workflows/pr-ci.yml +++ b/.github/workflows/pr-ci.yml @@ -3,6 +3,7 @@ name: Tyger on: push: branches: [main] + tags: ["v*.*.*"] pull_request: # all branches workflow_dispatch: @@ -209,3 +210,40 @@ jobs: - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v2 + + release: + if: startsWith(github.ref, 'refs/tags/') + permissions: + contents: write + needs: + - tyger-build-deploy + - windows-smoke-tests + - codeQL + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: actions/setup-go@v4 + with: + go-version-file: 'cli/go.mod' + + - uses: cue-lang/setup-cue@v1.0.0 + with: + version: v0.6.0 + name: install CUE + + - name: get container registry + run: | + set -euo pipefail + official_container_registry=$(scripts/get-context-environment-config.sh -e developerConfig.officialContainerRegistry.fqdn) + echo "OFFICIAL_CONTAINER_REGISTRY=$(echo $official_container_registry)" >> $GITHUB_ENV + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v5 + with: + version: v1.21.2 + workdir: cli + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/cli/.gitignore b/cli/.gitignore new file mode 100644 index 00000000..cde01232 --- /dev/null +++ b/cli/.gitignore @@ -0,0 +1,2 @@ + +dist/ diff --git a/cli/.goreleaser.yaml b/cli/.goreleaser.yaml new file mode 100644 index 00000000..4c6521ed --- /dev/null +++ b/cli/.goreleaser.yaml @@ -0,0 +1,57 @@ +before: + hooks: + - go mod tidy + +builds: + - id: tyger + main: ./cmd/tyger + binary: tyger + env: + - CGO_ENABLED=0 + ldflags: + - -s -w + - -X main.version={{.Tag}} + - -X github.com/microsoft/tyger/cli/internal/install.containerRegistry={{ .Env.OFFICIAL_CONTAINER_REGISTRY }} + goos: + - linux + - windows + - darwin + + - id: tyger-proxy + main: ./cmd/tyger-proxy + binary: tyger-proxy + env: + - CGO_ENABLED=0 + ldflags: + - -s -w + - -X main.version={{.Tag}} + goos: + - linux + - windows + - darwin + +archives: + - format: tar.gz + # this name template makes the OS and Arch compatible with the results of `uname`. + name_template: >- + {{ .ProjectName }}_ + {{- .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + # use zip for windows archives + format_overrides: + - goos: windows + format: zip + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" + +release: + draft: true + replace_existing_draft: true diff --git a/scripts/get-context-environment-config.sh b/scripts/get-context-environment-config.sh index 0a1bf39e..e4934399 100755 --- a/scripts/get-context-environment-config.sh +++ b/scripts/get-context-environment-config.sh @@ -51,14 +51,16 @@ this_dir=$(dirname "${0}") config_dir="${TYGER_ENVIRONMENT_CONFIG_DIR:-${this_dir}/../deploy/config/microsoft}" helm_chart_dir=$(readlink -f "${this_dir}/../deploy/helm") -environment_name="${TYGER_ENVIRONMENT_NAME:-}" -if [[ -z "${environment_name:-}" ]]; then +if [[ "$expression" == "config" || "$expression" == config.* ]]; then + environment_name="${TYGER_ENVIRONMENT_NAME:-}" + if [[ -z "${environment_name:-}" ]]; then if [[ ! "$(git config user.email)" =~ [^@]+ ]]; then - >&2 echo "git email is not set" - exit 1 + echo >&2 "Set the TYGER_ENVIRONMENT_NAME environment variable or ensure your git email is set" + exit 1 fi environment_name="${BASH_REMATCH[0]//[.\-_]/}" + fi fi cd "${config_dir}" -cue export . --out "${output}" -t environmentName="${environment_name}" -t tygerHelmChartDir="${helm_chart_dir}" -e "${expression}" +cue export . --out "${output}" -t environmentName="${environment_name:-}" -t tygerHelmChartDir="${helm_chart_dir}" -e "${expression}"