forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (78 loc) · 2.87 KB
/
build-downstream.yml
File metadata and controls
89 lines (78 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: build
permissions: read-all
on:
workflow_call:
inputs:
repo:
description: 'Repository to build'
required: true
type: string
jobs:
generate-repository:
runs-on: ubuntu-22.04
env:
BASE_BRANCH: ${{ github.event_name == 'merge_group' && github.event.merge_group.base_ref || github.event.pull_request.base.ref || github.ref_name }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout Repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.2
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
with:
go-version: '^1.26'
cache-dependency-path: |
mmv1/go.mod
tpgtools/go.mod
- name: Build ${{ inputs.repo }}
run: |
set -e
set -x
# Set GOPATH to a directory the runner user has access to
export GOPATH=~/go
# Clean up branch name if it starts with refs/heads/
if [[ $BASE_BRANCH == refs/heads/* ]]; then
BASE_BRANCH=${BASE_BRANCH#refs/heads/}
fi
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 --depth 1 $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 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 -q "$current_dir/output.zip" . -x "*.git/*")
env:
INPUTS_REPO: ${{ inputs.repo }}
- name: Upload built artifacts
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: artifact-${{ inputs.repo }}
path: output.zip