This repository has been archived by the owner on May 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
169 lines (149 loc) · 6.79 KB
/
formula.yml
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# TODO:
# - test the formula (this might take a while to run w/o bottles)
# - test that it installs correctly
# - test that it works properly
name: Build formula for dbt package
on:
workflow_dispatch:
inputs:
version:
type: string
description: "The package version to release"
required: true
dbt-package:
type: string
description: "Name of the dbt database adapter"
required: true
is-default-version:
description: "Is this version the latest stable release?"
type: boolean
required: true
workflow_call:
inputs:
version:
type: string
description: "The package version to release"
required: true
dbt-package:
type: string
description: "Name of the dbt database adapter"
required: true
is-default-version:
description: "Is this version the latest stable release?"
type: boolean
required: true
env:
BUILD_DIR: ${{ github.workspace }}/build
jobs:
create-formula:
runs-on: ubuntu-latest
steps:
- name: Log workflow inputs
run: |
echo "::group::Build formula inputs"
echo "version=${{ github.event.inputs.version }}"
echo "dbt-package=${{ github.event.inputs.dbt-package }}"
echo "is-default-version=${{ github.event.inputs.is-default-version }}"
echo "::endgroup::"
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup homebrew
if: ${{ !env.ACT }}
uses: Homebrew/actions/setup-homebrew@master
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Create build dir
run: mkdir -p $BUILD_DIR
- name: Install dependencies
run: |
pip install --no-cache-dir --upgrade pip
pip install --no-cache-dir j2cli wheel homebrew-pypi-poet
- name: Parse semver string
id: semver
uses: dbt-labs/actions/parse-semver@v1
with:
version: ${{ github.event.inputs.version }}
- name: Get python package info
id: package-info
uses: dbt-labs/actions/py-package-info@main
with:
package: ${{ github.event.inputs.dbt-package }}
version: ${{ steps.semver.outputs.version }}
- name: Generate formula resources
id: gen-resources
run: |
pip install ${{ github.event.inputs.dbt-package }}==${{ steps.semver.outputs.version }} --no-cache-dir
RESOURCES_FILE_PATH=$BUILD_DIR/resources.txt
poet -r ${{ github.event.inputs.dbt-package }} | .github/process-python-resources.py ${{ github.event.inputs.dbt-package }} > "$RESOURCES_FILE_PATH"
cat "$RESOURCES_FILE_PATH"
echo "formula-resources-file=${RESOURCES_FILE_PATH}" >> $GITHUB_OUTPUT
- name: Generate formula file name
id: gen-filename
run: |
if [ ${{ steps.semver.outputs.is-pre-release }} == 1 ]
then
echo "This is a prelease"
FILENAME_WITH_VERSION="Formula/${{ github.event.inputs.dbt-package }}@${{ steps.semver.outputs.base-version }}-${{ steps.semver.outputs.pre-release }}.rb"
else
echo "This is a final release"
FILENAME_WITH_VERSION="Formula/${{ github.event.inputs.dbt-package }}@${{ steps.semver.outputs.version }}.rb"
fi
echo "filename-with-version=${FILENAME_WITH_VERSION}" >> $GITHUB_OUTPUT
FILENAME="Formula/${{ github.event.inputs.dbt-package }}.rb"
echo "filename=${FILENAME}" >> $GITHUB_OUTPUT
- name: Generate formula class name
id: gen-classname
run: |
PACKAGE_NAME=$(python -c "print(''.join(word.title() for word in '${{ github.event.inputs.dbt-package }}'.split('-')))")
PACKAGE_VERSION=$(python -c "print(''.join(word.title() for word in '${{ steps.semver.outputs.version }}'.split('.')))")
echo "classname-with-version=${PACKAGE_NAME}AT${PACKAGE_VERSION}" >> $GITHUB_OUTPUT
echo "classname=${PACKAGE_NAME}" >> $GITHUB_OUTPUT
- name: Generate versioned formula file
env:
package: ${{ github.event.inputs.dbt-package }}
classname: ${{ steps.gen-classname.outputs.classname-with-version }}
summary: ${{ steps.package-info.outputs.summary }}
homepage: ${{ steps.package-info.outputs.homepage }}
source_url: ${{ steps.package-info.outputs.source-url }}
source_checksum: ${{ steps.package-info.outputs.source-checksum }}
run: |
export resources=$(cat "${{ steps.gen-resources.outputs.formula-resources-file }}")
j2 .github/formula-template.j2 > "${{ steps.gen-filename.outputs.filename-with-version }}"
cat "${{ steps.gen-filename.outputs.filename-with-version }}"
- name: Create alias for default formula
if: ${{ fromJson(github.event.inputs.is-default-version) }}
run: |
mkdir -p Aliases
cd Aliases
ln -sf ../${{ steps.gen-filename.outputs.filename-with-version }} ${{ github.event.inputs.dbt-package }}@${{ steps.semver.outputs.major }}.${{ steps.semver.outputs.minor }}
- name: Format versioned formula file
if: ${{ !env.ACT }}
run: |
brew style --formula --fix "${{ steps.gen-filename.outputs.filename-with-version }}"
- name: Generate default formula file
if: ${{ fromJson(github.event.inputs.is-default-version) }}
env:
package: ${{ github.event.inputs.dbt-package }}
classname: ${{ steps.gen-classname.outputs.classname }}
summary: ${{ steps.package-info.outputs.summary }}
homepage: ${{ steps.package-info.outputs.homepage }}
source_url: ${{ steps.package-info.outputs.source-url }}
source_checksum: ${{ steps.package-info.outputs.source-checksum }}
run: |
export resources=$(cat "${{ steps.gen-resources.outputs.formula-resources-file }}")
j2 .github/formula-template.j2 > "${{ steps.gen-filename.outputs.filename }}"
cat "${{ steps.gen-filename.outputs.filename }}"
- name: Format default formula file
if: ${{ !env.ACT && fromJson(github.event.inputs.is-default-version) }}
run: |
brew style --formula --fix "${{ steps.gen-filename.outputs.filename }}"
- name: Create pull request
if: ${{ !env.ACT }}
uses: peter-evans/create-pull-request@v5
with:
title: "${{ github.event.inputs.dbt-package }} formula for version ${{ github.event.inputs.version }}"
branch: "${{ github.event.inputs.dbt-package }}-formula/${{ github.event.inputs.version }}"
body: |
Generated formula to install ${{ github.event.inputs.dbt-package }} for version ${{ github.event.inputs.version }}