Add Makefile and refactored Azure pipeline (#58)

* add makefile for local running.

* update pipeline

* Update pipeline.

* add newline for .gitignore.

* Fix the building issue.

* Fix the makefile issue.

* Fix the makefile issue.

* Fix makefile issue.

* Fix the building issue.

* fix the pipeline issue.

* Enable vendor mode.

* Fix the goimport issue.

* Fix the goimport issue.
This commit is contained in:
Su Shi 2019-07-01 13:10:24 -07:00 коммит произвёл Junyi Yi
Родитель e9e99b4577
Коммит b400fd6482
5 изменённых файлов: 97 добавлений и 34 удалений

4
.gitignore поставляемый
Просмотреть файл

@ -48,3 +48,7 @@ build-iPhoneSimulator/
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc
# Code generation folder by Magic Modules
generated/

4
.gitmodules поставляемый
Просмотреть файл

@ -1,7 +1,3 @@
[submodule "generated/ansible"]
path = generated/ansible
url = https://github.com/VSChina/ansible.git
branch = devel
[submodule "tools/magic-modules"]
path = tools/magic-modules
url = https://github.com/VSChina/magic-modules.git

57
Makefile Normal file
Просмотреть файл

@ -0,0 +1,57 @@
ROOT=$(shell pwd)
GENROOT=$(ROOT)/generated
GOSRC=$(GENROOT)/go/src
TFROOT=$(GOSRC)/github.com/terraform-providers
TFGITURL=https://github.com/VSChina/terraform-provider-azurerm.git
TFREPO=terraform-provider-azurerm
ASGITURL=https://github.com/VSChina/ansible.git
ASREPO=ansible
MMROOT=$(ROOT)/tools/magic-modules
# Environment variables.
export GOPATH=$(GENROOT)/go
export GO111MODULE=on
export GOFLAGS=-mod=vendor
default: init
all: clean init build format-terraform
init:
@echo "==> cloning repos of terraform and ansible..."
if [ ! -d "$(TFROOT)" ]; then \
mkdir -p "$(TFROOT)"; \
fi
if [ ! -d "$(TFROOT)/$(TFREPO)" ]; then \
git clone $(TFGITURL) $(TFROOT)/$(TFREPO); \
fi
if [ ! -d "$(GENROOT)/$(ASREPO)" ]; then \
git clone $(ASGITURL) $(GENROOT)/$(ASREPO); \
fi
git submodule update --init && \
cd $(MMROOT) && \
gem install bundler && \
bundle install --retry=3 --jobs=4
clean:
rm -rf $(GENROOT)
build: build-terraform build-ansible
build-terraform:
cd $(MMROOT) && \
jq '.[]' $(ROOT)/resources.json | xargs -I '{}' bundle exec compiler -d -p $(ROOT)/'{}' -e terraform -o $(TFROOT)/$(TFREPO)/
format-terraform:
cd $(TFROOT)/$(TFREPO) && \
goimports -w azurerm && \
make fmt
build-ansible:
cd $(MMROOT) && \
jq '.[]' $(ROOT)/resources.json | xargs -I '{}' bundle exec compiler -d -p $(ROOT)/'{}' -e ansible -o $(GENROOT)/$(ASREPO)/
.PHONY: init clean build build-terraform format-terraform build-ansible

Просмотреть файл

@ -7,29 +7,27 @@ trigger:
- master
variables:
# GOROOT: '$HOME/.goenv/versions/1.12.6' # Go installation path
GOPATH: '$(system.defaultWorkingDirectory)/$(Build.BuildNumber)/go-work' # Go workspace path
GENROOT: $(system.defaultWorkingDirectory)/generated
GOPATH: '$(GENROOT)/go' # Go workspace path
GOBIN: '$(GOPATH)/bin' # Go binaries path
TFROOT: '$(GOPATH)/src/github.com/terraform-providers'
GOSRC: '$(GOPATH)/src' # Go source path
TFORG: '$(GOPATH)/src/github.com/terraform-providers'
TFREPO: 'terraform-provider-azurerm'
TFROOT: '$(TFORG)/$(TFREPO)'
TFGITURL: 'https://github.com/VSChina/terraform-provider-azurerm.git'
TFPROVIDERNAME: 'terraform-provider-azurerm'
ASREPO: 'ansible'
ASROOT: '$(GENROOT)/$(ASREPO)'
ASGITURL: 'https://github.com/VSChina/ansible.git'
MMROOT: $(system.defaultWorkingDirectory)/tools/magic-modules
steps:
# - task: UseRubyVersion@0
# inputs:
# versionSpec: '>= 2.5'
# - task: UsePythonVersion@0
# inputs:
# versionSpec: '>=3.6'
- bash: |
shopt -s extglob
echo `go env`
echo '##vso[task.prependpath]$(GOBIN)'
if [ ! -d "$(TFROOT)" ]
if [ ! -d "$(TFORG)" ]
then
mkdir -p "$(TFROOT)"
mkdir -p "$(TFORG)"
fi
displayName: 'init Go environment'
failOnStderr: true
@ -43,26 +41,31 @@ steps:
failOnStderr: false
- bash: |
git clone $(TFGITURL) $(TFPROVIDERNAME)
cd $(TFPROVIDERNAME)
git clone $(TFGITURL) $(TFROOT)
cd $(TFROOT)
git checkout autogen-pr-$(system.pullRequest.pullRequestNumber) || git checkout -b autogen-pr-$(system.pullRequest.pullRequestNumber)
if [[ $(git branch -a --list 'origin/autogen-pr-$(system.pullRequest.pullRequestNumber)') ]]; then
git pull
fi
workingDirectory: $(TFROOT)
displayName: 'clone terraform repository'
failOnStderr: false
- bash: |
git submodule update --init
pushd generated/ansible
git clone $(ASGITURL) $(ASROOT)
cd $(ASROOT)
git checkout autogen-pr-$(system.pullRequest.pullRequestNumber) || git checkout -b autogen-pr-$(system.pullRequest.pullRequestNumber)
if [[ $(git branch -a --list 'origin/autogen-pr-$(system.pullRequest.pullRequestNumber)') ]]; then
git pull
fi
popd
displayName: 'init submodules'
displayName: 'clone ansible repository'
failOnStderr: false
- bash: |
git submodule update --init && \
cd $(MMROOT) && \
gem install bundler && \
bundle install --retry=3 --jobs=4
displayName: 'init magic modules'
failOnStderr: false
- bash: |
@ -76,18 +79,22 @@ steps:
failOnStderr: true
- bash: |
cd tools/magic-modules
gem install bundler
bundle install --retry=3 --jobs=4
jq '.[]' ../../resources.json | xargs -I '{}' bundle exec compiler -d -p ../../'{}' -e terraform -o $(TFROOT)/$(TFPROVIDERNAME)/
jq '.[]' ../../resources.json | xargs -I '{}' bundle exec compiler -d -p ../../'{}' -e ansible -o ../../generated/ansible/
make build && \
make format-terraform
displayName: 'code generation'
failOnStderr: false
- bash: |
cd $(TFROOT)/$(TFPROVIDERNAME)
cd $(TFROOT)
goimports -w azurerm
make fmt
env:
GOPATH: $(GOPATH)
displayName: 'go import and format'
failOnStderr: false
- bash: |
cd $(TFROOT)
git add -A
git commit -m "Code generation for Terraform."
git push
@ -107,7 +114,7 @@ steps:
- bash: |
cd generated/ansible
cd $(ASROOT)
# run `black` against the directory of ansible if neccessary.
git add -A
git commit -m "Code generation for Ansible."

@ -1 +0,0 @@
Subproject commit a688d2ee39860cdb22e5ecd4ca927f22744f7f9e