Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build the provider in github #9351

Merged
merged 59 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
6017f3b
test building the provider in github
ScottSuarez Oct 25, 2023
4c25393
updoot
ScottSuarez Oct 25, 2023
09e4e09
merp
ScottSuarez Oct 25, 2023
a5b208e
merp
ScottSuarez Oct 25, 2023
b96b513
merp
ScottSuarez Oct 25, 2023
08bc08c
improve bundle cache
ScottSuarez Oct 25, 2023
2a6cfca
build all downstreams
ScottSuarez Oct 27, 2023
581dbd4
fix individual build downstreams
ScottSuarez Oct 27, 2023
c9e4214
fix doc builder
ScottSuarez Oct 27, 2023
1839b20
supress output of git rm.. too noisy
ScottSuarez Oct 27, 2023
77ae4a2
test matrixes
ScottSuarez Oct 28, 2023
53d801a
meep
ScottSuarez Oct 28, 2023
f72e753
meep
ScottSuarez Oct 28, 2023
c53d033
meep
ScottSuarez Oct 28, 2023
427aaa5
echo output
ScottSuarez Oct 28, 2023
d28e910
meerp
ScottSuarez Oct 28, 2023
f63d24b
build
ScottSuarez Oct 28, 2023
dfd132f
update make file
ScottSuarez Oct 30, 2023
300e2b4
output-path
ScottSuarez Oct 30, 2023
52780e8
fix make file
ScottSuarez Oct 30, 2023
44d2161
simplify build script to use make commands
ScottSuarez Oct 30, 2023
178de0f
tgc generation simplified
ScottSuarez Oct 30, 2023
474066d
retain old base build pathway
ScottSuarez Oct 30, 2023
954b5fa
retain old base build pathway
ScottSuarez Oct 30, 2023
ee8080e
more verbose logging
ScottSuarez Oct 30, 2023
bf0bb30
fix syntax errors
ScottSuarez Oct 30, 2023
d07ac92
fix build script for ga version
ScottSuarez Oct 31, 2023
c3ffc35
commit working env
ScottSuarez Oct 31, 2023
0da2a2e
Update GNUmakefile
ScottSuarez Nov 1, 2023
49f62d9
revert changes to ruby version
ScottSuarez Nov 1, 2023
b5256de
Merge branch 'pgh' of https://github.com/ScottSuarez/magic-modules in…
ScottSuarez Nov 1, 2023
3003f97
Merge branch 'main' of https://github.com/GoogleCloudPlatform/magic-m…
ScottSuarez Nov 2, 2023
b3e7903
Run tests
ScottSuarez Nov 2, 2023
46afdc6
add dependency
ScottSuarez Nov 2, 2023
bae7e57
edit downstreams
ScottSuarez Nov 3, 2023
b721b97
fix yaml
ScottSuarez Nov 3, 2023
1045ea1
simplify output statement
ScottSuarez Nov 3, 2023
4fc81f9
lets see if this works
ScottSuarez Nov 3, 2023
b894d09
fix workflow
ScottSuarez Nov 3, 2023
1176b97
revert
ScottSuarez Nov 3, 2023
72a028f
small typo
ScottSuarez Nov 3, 2023
39b148c
split to workflow files
ScottSuarez Nov 3, 2023
3abafe3
remove workflow run file
ScottSuarez Nov 3, 2023
d0758c9
test better naming conventions (might not work)
ScottSuarez Nov 3, 2023
2164ab6
more name convention alignments
ScottSuarez Nov 3, 2023
6ce314d
generation checkin
ScottSuarez Nov 3, 2023
bc14131
tgc unit test fix
ScottSuarez Nov 3, 2023
360a642
replace wiht local provider
ScottSuarez Nov 3, 2023
ffe5c66
extract tpgb into go path
ScottSuarez Nov 3, 2023
4c42791
tgc unit tests
ScottSuarez Nov 3, 2023
bb4a38b
fix typo
ScottSuarez Nov 3, 2023
00c539c
gnumake
ScottSuarez Nov 7, 2023
db896db
Update GNUmakefile
ScottSuarez Nov 7, 2023
c0fec6e
Update .github/workflows/unit-test-tpg.yml
ScottSuarez Nov 7, 2023
ac68661
merge with main
ScottSuarez Nov 7, 2023
1a4758d
Merge branch 'main' of https://github.com/GoogleCloudPlatform/magic-m…
ScottSuarez Nov 14, 2023
cba768c
apply suggestions from review
ScottSuarez Nov 14, 2023
d7ab1ef
correct syntax error on Make file
ScottSuarez Nov 15, 2023
c27dbeb
Update .github/workflows/downstreams.yml
ScottSuarez Nov 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ clone_repo
git config --local user.name "Modular Magician"
git config --local user.email "magic-modules@google.com"

# MMv1 now lives inside a sub-folder
pushd mmv1

if [ "$COMMAND" == "head" ]; then
BRANCH=auto-pr-$REFERENCE
COMMIT_MESSAGE="New generated code for MM PR $REFERENCE."
Expand All @@ -101,67 +98,90 @@ elif [ "$COMMAND" == "downstream" ]; then
COMMIT_MESSAGE="$ORIGINAL_MESSAGE$NEWLINE[upstream:$REFERENCE]"
fi

if [ "$REPO" == "terraform" ]; then
pushd $LOCAL_PATH
go mod download
find . -type f -not -wholename "./.git*" -not -wholename "./.changelog*" -not -name ".travis.yml" -not -name ".golangci.yml" -not -name "CHANGELOG.md" -not -name "CHANGELOG_v*.md" -not -name "GNUmakefile" -not -name "docscheck.sh" -not -name "LICENSE" -not -name "README.md" -not -wholename "./examples*" -not -name ".go-version" -not -name ".hashibot.hcl" -print0 | xargs -0 git rm
popd
fi
if [ "$COMMAND" == "base" ]; then
pushd mmv1
if [ "$REPO" == "terraform" ]; then
pushd $LOCAL_PATH
go mod download
find . -type f -not -wholename "./.git*" -not -wholename "./.changelog*" -not -name ".travis.yml" -not -name ".golangci.yml" -not -name "CHANGELOG.md" -not -name "CHANGELOG_v*.md" -not -name "GNUmakefile" -not -name "docscheck.sh" -not -name "LICENSE" -not -name "README.md" -not -wholename "./examples*" -not -name ".go-version" -not -name ".hashibot.hcl" -print0 | xargs -0 git rm
popd
fi

if [ "$REPO" == "terraform-google-conversion" ]; then
# Generate tfplan2cai
pushd $LOCAL_PATH
# clear out the templates as they are copied during
# generation from mmv1/third_party/validator/tests/data
rm -rf ./tfplan2cai/testdata/templates/
rm -rf ./tfplan2cai/testdata/generatedconvert/
rm -rf ./tfplan2cai/converters/google/provider
rm -rf ./tfplan2cai/converters/google/resources
find ./tfplan2cai/test/** -type f -exec git rm {} \;
popd
if [ "$REPO" == "terraform-google-conversion" ]; then
# Generate tfplan2cai
pushd $LOCAL_PATH
# clear out the templates as they are copied during
# generation from mmv1/third_party/validator/tests/data
rm -rf ./tfplan2cai/testdata/templates/
rm -rf ./tfplan2cai/testdata/generatedconvert/
rm -rf ./tfplan2cai/converters/google/provider
rm -rf ./tfplan2cai/converters/google/resources
find ./tfplan2cai/test/** -type f -exec git rm {} \;
popd

bundle exec compiler.rb -a -e terraform -f validator -o $LOCAL_PATH/tfplan2cai -v $VERSION
bundle exec compiler.rb -a -e terraform -f validator -o $LOCAL_PATH/tfplan2cai -v $VERSION

# Generate cai2hcl
pushd $LOCAL_PATH
rm -rf ./cai2hcl/*
popd
# Generate cai2hcl
pushd $LOCAL_PATH
rm -rf ./cai2hcl/*
popd

bundle exec compiler.rb -a -e terraform -f tgc_cai2hcl -o $LOCAL_PATH/cai2hcl -v $VERSION
bundle exec compiler.rb -a -e terraform -f tgc_cai2hcl -o $LOCAL_PATH/cai2hcl -v $VERSION

if [ "$COMMAND" == "downstream" ]; then
pushd $LOCAL_PATH
go get -d github.com/hashicorp/terraform-provider-google-beta@$BASE_BRANCH
go mod tidy
set +e
make build
set -e
popd
if [ "$COMMAND" == "downstream" ]; then
pushd $LOCAL_PATH
go get -d github.com/hashicorp/terraform-provider-google-beta@$BASE_BRANCH
go mod tidy
set +e
make build
set -e
popd
fi
elif [ "$REPO" == "tf-oics" ]; then
# use terraform generator with oics override
bundle exec compiler.rb -a -e terraform -f oics -o $LOCAL_PATH -v $VERSION
else
if [ "$REPO" == "terraform" ]; then
if [ "$VERSION" == "ga" ]; then
bundle exec compiler.rb -a -e $REPO -o $LOCAL_PATH -v $VERSION --no-docs
bundle exec compiler.rb -a -e $REPO -o $LOCAL_PATH -v beta --no-code
else
bundle exec compiler.rb -a -e $REPO -o $LOCAL_PATH -v $VERSION
fi
pushd ../
make tpgtools OUTPUT_PATH=$LOCAL_PATH VERSION=$VERSION

# Only generate TeamCity-related file for TPG and TPGB
if [ "$VERSION" == "ga" ] || [ "$VERSION" == "beta" ]; then
make teamcity-servicemap-generate OUTPUT_PATH=$LOCAL_PATH VERSION=$VERSION
fi
popd
fi
fi
elif [ "$REPO" == "tf-oics" ]; then
# use terraform generator with oics override
bundle exec compiler.rb -a -e terraform -f oics -o $LOCAL_PATH -v $VERSION
popd
else
if [ "$REPO" == "terraform" ]; then
if [ "$VERSION" == "ga" ]; then
bundle exec compiler.rb -a -e $REPO -o $LOCAL_PATH -v $VERSION --no-docs
bundle exec compiler.rb -a -e $REPO -o $LOCAL_PATH -v beta --no-code
else
bundle exec compiler.rb -a -e $REPO -o $LOCAL_PATH -v $VERSION
if [ "$REPO" == "terraform-google-conversion" ]; then
make clean-tgc OUTPUT_PATH="$LOCAL_PATH"
make tgc OUTPUT_PATH="$LOCAL_PATH"
ScottSuarez marked this conversation as resolved.
Show resolved Hide resolved

if [ "$COMMAND" == "downstream" ]; then
pushd $LOCAL_PATH
go get -d github.com/hashicorp/terraform-provider-google-beta@$BASE_BRANCH
go mod tidy
set +e
make build
set -e
popd
fi
pushd ../
make tpgtools OUTPUT_PATH=$LOCAL_PATH VERSION=$VERSION

# Only generate TeamCity-related file for TPG and TPGB
if [ "$VERSION" == "ga" ] || [ "$VERSION" == "beta" ]; then
make teamcity-servicemap-generate OUTPUT_PATH=$LOCAL_PATH VERSION=$VERSION
fi
popd
elif [ "$REPO" == "tf-oics" ]; then
# use terraform generator with oics override
make tf-oics OUTPUT_PATH="$LOCAL_PATH"
elif [ "$REPO" == "terraform" ]; then
make clean-provider OUTPUT_PATH="$LOCAL_PATH"
make provider OUTPUT_PATH="$LOCAL_PATH" VERSION=$VERSION
fi
fi

popd

pushd $LOCAL_PATH

git config --local user.name "Modular Magician"
Expand Down Expand Up @@ -222,5 +242,3 @@ if [ "$COMMITTED" == "true" ] && [ "$COMMAND" == "downstream" ]; then
-d '{"merge_method": "squash"}' \
"https://api.github.com/repos/$UPSTREAM_OWNER/$GH_REPO/pulls/$NEW_PR_NUMBER/merge"
fi

popd
114 changes: 114 additions & 0 deletions .github/workflows/build-downstream.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: build
permissions: read-all

on:
workflow_call:
inputs:
repo:
description: 'Repository to build'
required: true
type: string

concurrency:
group: ${{ inputs.repo }}-${{ github.event_name == 'pull_request' && format('pr-{0}-', github.event.pull_request.number) || format('commit-{0}', github.sha) }}
cancel-in-progress: true

jobs:
generate-repository:
runs-on: ubuntu-22.04
env:
BASE_BRANCH: ${{ github.event.pull_request.base.ref || github.ref }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Ruby
uses: ruby/setup-ruby@ec02537da5712d66d4d50a0f33b7eb52773b5ed1
with:
ruby-version: '3.1'

- name: Cache Bundler gems
uses: actions/cache@v2
with:
path: mmv1/vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('mmv1/**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-
- name: Install Ruby dependencies
run: |
bundle config path mmv1/vendor/bundle
bundle install
working-directory: mmv1

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '^1.19'

# Cache Go modules
- name: Cache Go modules
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- run: go install golang.org/x/tools/cmd/goimports@latest

- name: Build ${{ inputs.repo }}
run: |
set -e
set -x
# Set GOPATH to a directory the runner user has access to
export GOPATH=~/go
function clone_repo() {
export OUTPUT_PATH=$GOPATH/src/github.com/$UPSTREAM_OWNER/$GH_REPO
GITHUB_PATH=https://x-access-token:$GITHUB_TOKEN@github.com/$UPSTREAM_OWNER/$GH_REPO
mkdir -p "$(dirname $OUTPUT_PATH)"
git clone $GITHUB_PATH $OUTPUT_PATH --branch $BASE_BRANCH
}
GH_REPO="${{ inputs.repo }}"
if [ "$GH_REPO" == "docs-examples" ] && [ "$BASE_BRANCH" == "main" ]; then
BASE_BRANCH="master"
fi
GITHUB_PATH=https://x-access-token:$GITHUB_TOKEN@github.com/$UPSTREAM_OWNER/$GH_REPO
if [[ "$GH_REPO" == terraform-provider-google* ]]; then
UPSTREAM_OWNER=hashicorp
clone_repo
if [ "$GH_REPO" == "terraform-provider-google" ]; then
export VERSION=ga
else
export VERSION=beta
fi
make clean-provider
make provider
elif [ "$GH_REPO" == "terraform-google-conversion" ]; then
UPSTREAM_OWNER=GoogleCloudPlatform
clone_repo
make clean-tgc
make tgc
elif [ "$GH_REPO" == "docs-examples" ]; then
UPSTREAM_OWNER=terraform-google-modules
clone_repo
make tf-oics
else
echo "case not supported"
exit 1
fi
(current_dir=$(pwd) && cd $OUTPUT_PATH && zip -r "$current_dir/output.zip" .)
- name: Upload built artifacts
uses: actions/upload-artifact@v2
with:
name: artifact-${{ inputs.repo }}
path: output.zip
50 changes: 50 additions & 0 deletions .github/workflows/downstreams.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: downstreams
permissions: read-all

on:
push:
branches:
- main
- 'FEATURE-BRANCH-*'

concurrency:
group: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || format('commit-{0}', github.sha) }}
cancel-in-progress: true

jobs:

terraform-provider-google:
uses: ./.github/workflows/build-downstream.yml
with:
repo: 'terraform-provider-google'
terraform-provider-google-beta:
uses: ./.github/workflows/build-downstream.yml
with:
repo: 'terraform-provider-google-beta'
terraform-google-conversion:
uses: ./.github/workflows/build-downstream.yml
with:
repo: 'terraform-google-conversion'
docs-examples:
uses: ./.github/workflows/build-downstream.yml
with:
repo: 'docs-examples'

unit-test-terraform-provider-google:
name: terraform-provider-google
needs: terraform-provider-google
uses: ./.github/workflows/unit-test-tpg.yml
with:
repo: 'terraform-provider-google'

unit-test-terraform-provider-googele-beta:
name: terraform-provider-google-beta
needs: terraform-provider-google-beta
uses: ./.github/workflows/unit-test-tpg.yml
with:
repo: 'terraform-provider-google-beta'

unit-test-terraform-google-conversion:
name: terraform-google-conversion
needs: [terraform-google-conversion, terraform-provider-google-beta]
uses: ./.github/workflows/unit-test-tgc.yml
55 changes: 55 additions & 0 deletions .github/workflows/unit-test-tgc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: unit-test-tgc
permissions: read-all

on:
workflow_call:

jobs:
compile-and-unit-tests:
runs-on: ubuntu-22.04
steps:
- name: Download built artifacts
uses: actions/download-artifact@v2
with:
name: artifact-terraform-google-conversion
path: artifacts-tgc

- name: Download built artifacts
uses: actions/download-artifact@v2
with:
name: artifact-terraform-provider-google-beta
path: artifacts-tpgb

- name: Unzip the artifacts and delete the zip
run: |
unzip artifacts-tgc/output.zip -d ./tgc
unzip artifacts-tpgb/output.zip -d ./tpgb
rm artifacts-tgc/output.zip
rm artifacts-tpgb/output.zip
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '^1.19'

- name: Cache Go modules and build cache
uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
key: ${{ runner.os }}-test-terraform-google-conversion-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-test-terraform-google-conversion-${{ hashFiles('**/go.sum') }}
${{ runner.os }}-test-terraform-google-conversion-
- name: Build Terraform Google Conversion
run: |
cd tgc
go mod edit -replace=github.com/hashicorp/terraform-provider-google-beta=../tpgb
go mod tidy
make build
- name: Run Unit Tests
run: |
cd tgc
make test
Loading