diff --git a/.github/scripts/bump_packages_version.py b/.github/scripts/bump_packages_version.py new file mode 100644 index 000000000..86d2ad216 --- /dev/null +++ b/.github/scripts/bump_packages_version.py @@ -0,0 +1,67 @@ +import os +import sys + +import yaml + +PACKAGES_FILE = "./elementary/monitor/dbt_project/packages.yml" +HELPER_COMMENTS = """ + # NOTE - for unreleased CLI versions we often need to update the package version to a commit hash (please leave this + # commented, so it will be easy to access) + # - git: https://github.com/elementary-data/dbt-data-reliability.git + # revision: + # When releasing a new version of the package, if the current version is using a commit hash, update the version to the new version. + # - package: elementary-data/elementary + # version: {version} +""" + + +def bump_packages_version(version: str) -> None: + with open(PACKAGES_FILE) as f: + data = yaml.safe_load(f) + + packages = data.get("packages") or [] + + new_packages = [] + elementary_found = False + for pkg in packages: + if "git" in pkg and "dbt-data-reliability" in pkg["git"]: + # Replace git hash reference with proper package reference + new_packages.append( + { + "package": "elementary-data/elementary", + "version": version, + } + ) + elementary_found = True + elif pkg.get("package") == "elementary-data/elementary": + # Update existing package version + pkg["version"] = version + new_packages.append(pkg) + elementary_found = True + else: + new_packages.append(pkg) + + if not elementary_found: + print( + "::error::Could not find elementary-data/elementary or " + "dbt-data-reliability entry in packages.yml" + ) + sys.exit(1) + + data["packages"] = new_packages + with open(PACKAGES_FILE, "w") as f: + yaml.dump(data, f, default_flow_style=False, sort_keys=False) + + # Append the helper comments for developer convenience + with open(PACKAGES_FILE, "a") as f: + f.write(HELPER_COMMENTS.format(version=version)) + + print(f"Updated packages.yml to version {version}") + + +if __name__ == "__main__": + version = os.environ.get("PKG_VERSION", "") + if not version: + print("::error::PKG_VERSION environment variable is not set") + sys.exit(1) + bump_packages_version(version) diff --git a/.github/workflows/bump-version.yml b/.github/workflows/bump-version.yml index 69b25e9ab..efa9d7c67 100644 --- a/.github/workflows/bump-version.yml +++ b/.github/workflows/bump-version.yml @@ -61,16 +61,30 @@ jobs: - name: Bump version run: | sed -i 's/^version = "[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*"/version = "${{ inputs.cli-version }}"/' ./pyproject.toml - - name: Bump version for package (using input) - if: ${{ needs.validate-version.outputs.validated-dbt-package-version != ''}} + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: "3.10" + - name: Install PyYAML + run: pip install pyyaml + - name: Determine package version + id: pkg-version run: | - sed -i 's/version: [0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$/version: ${{ needs.validate-version.outputs.validated-dbt-package-version }}/' ./elementary/monitor/dbt_project/packages.yml - sed -i 's/version: [0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$/version: ${{ needs.validate-version.outputs.validated-dbt-package-version }}/' ./docs/_snippets/quickstart-package-install.mdx - - name: Bump version for package (using default) - if: ${{ needs.validate-version.outputs.validated-dbt-package-version == ''}} + if [ -n "${{ inputs.dbt-package-version }}" ] && [ -z "${{ needs.validate-version.outputs.validated-dbt-package-version }}" ]; then + echo "::error::Invalid dbt-package-version input" + exit 1 + elif [ -n "${{ needs.validate-version.outputs.validated-dbt-package-version }}" ]; then + echo "version=${{ needs.validate-version.outputs.validated-dbt-package-version }}" >> $GITHUB_OUTPUT + else + echo "version=${{ needs.validate-version.outputs.default-dbt-package-version }}" >> $GITHUB_OUTPUT + fi + - name: Bump version for packages.yml + env: + PKG_VERSION: ${{ steps.pkg-version.outputs.version }} + run: python .github/scripts/bump_packages_version.py + - name: Bump version for docs snippet run: | - sed -i 's/version: [0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$/version: ${{ needs.validate-version.outputs.default-dbt-package-version }}/' ./elementary/monitor/dbt_project/packages.yml - sed -i 's/version: [0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$/version: ${{ needs.validate-version.outputs.default-dbt-package-version }}/' ./docs/_snippets/quickstart-package-install.mdx + sed -i 's/version: [0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$/version: ${{ steps.pkg-version.outputs.version }}/' ./docs/_snippets/quickstart-package-install.mdx - name: Commit changes run: git commit -am "release v${{ inputs.cli-version }}" - name: Push code