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

chore: fix up release pipelines #17

Merged
merged 4 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
8 changes: 8 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
push:
branches: [ main ]
tags: [ 'v*.*.*' ]

jobs:
build:
Expand Down Expand Up @@ -92,10 +93,17 @@ jobs:
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/')"
needs: [ build ]
environment: VALIDATOR_RELEASE
steps:
- uses: actions/download-artifact@v2
with:
name: wheels
- name: Publish to GitHub release page
uses: softprops/action-gh-release@v1
with:
files: |
*.whl
*.tar.gz
- name: Publish to PyPI
uses: messense/maturin-action@v1
env:
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
push:
branches: [ main ]
tags: [ 'v*.*.*' ]

jobs:
check:
Expand Down Expand Up @@ -101,3 +102,35 @@ jobs:
- uses: Swatinem/rust-cache@v1
- name: Doc
run: RUSTDOCFLAGS="-Dwarnings" cargo doc --workspace --all-features

release:
name: Release
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/')"
needs: [ check, test ]
environment: VALIDATOR_RELEASE
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Fetch Substrait submodule tags
working-directory: substrait
run: |
git fetch --recurse-submodules=no origin +refs/tags/*:refs/tags/*
git describe --dirty --tags
- name: Local build to populate resource files
working-directory: rs
run: cargo build
- name: Publish substrait-validator-derive
working-directory: derive
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish --allow-dirty
- name: Wait for substrait-validator-derive to appear in the index
continue-on-error: true
run: python3 ci/crates-io-wait.py substrait-validator-derive `cat ci/version` 1800
- name: Publish substrait-validator
working-directory: rs
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish --allow-dirty
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't these crates be published independently?

Copy link
Collaborator Author

@jvanstraten jvanstraten Jun 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because

  • one depends on the other;
  • especially with automated releases it seems like a good idea to always release both to not complicate versioning, even if the derive crate is really unlikely to change;
  • cargo won't let you publish a crate if a dependency is not yet in the registry;
  • cargo publish exits with success before the published crate is synchronized into the crate registry (this can take several minutes depending on queue length).

The latter is an open issue. Most people use shell scripts, I strongly prefer Python personally (if only because it's already a dependency, and bash is not [ETA: though this is running on CI. d'oh, nevermind]). Once cargo resolves this, the blocking Python script can be burned at the stake.

73 changes: 73 additions & 0 deletions ci/crates-io-wait.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/python3
# SPDX-License-Identifier: Apache-2.0

import urllib.request
import json
import sys
import time


def crate_version_exists(crate, version):
"""Returns whether the given version of the given crate exists on the
crates.io index."""

# Fetch the version info for the crate.
with urllib.request.urlopen(
"https://raw.githubusercontent.com/rust-lang/crates.io-index/"
f"master/{crate[0:2]}/{crate[2:4]}/{crate}"
) as f:
data = f.read()

# Parse version info.
versions = list(map(json.loads, data.decode("utf-8").strip().split("\n")))

# Check whether the requested version exists.
for version_data in versions:
if version_data.get("vers", None) == version:
return True
return False


def check(crate, version):
"""Exits with code 0 if the given crate + version is found."""

try:
if crate_version_exists(crate, version):
print("Crate found!")
sys.exit(0)
except Exception as e:
print(f"{type(e).__name__}: {e}")


if __name__ == "__main__":

if len(sys.argv) == 4:
_, crate, version, wait = sys.argv
crate = crate.strip()
version = version.strip()
wait_remain = int(wait.strip())

print("Checking...")
check(crate, version)

period = 10
while wait_remain > 0:
print(f"Waiting {period}s...")
sys.stdout.flush()
time.sleep(period)
wait_remain -= period
period = int(period * 1.25)

print("Checking...")
sys.stdout.flush()
check(crate, version)

print("Timeout expired!")
sys.exit(1)

# Arguments invalid, print usage.
me = sys.argv[0] if sys.argv else "version.py"
print("Waits for a crate to appear on crates.io, since cargo publish doesn't.")
print("See https://github.com/rust-lang/cargo/issues/9507")
print(f"Usage: {me} <crate> <version> <max-wait-seconds>")
sys.exit(2)