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

AVRO-3423: Add build.sh step to encapsulate all the steps needed during release #1570

Closed
wants to merge 36 commits into from
Closed

AVRO-3423: Add build.sh step to encapsulate all the steps needed during release #1570

wants to merge 36 commits into from

Conversation

zcsizmadia
Copy link
Contributor

@zcsizmadia zcsizmadia commented Feb 26, 2022

Make sure you have checked all steps below.

Jira

Tests

  • My PR adds the following unit tests OR does not need testing for this extremely good reason:

Commits

  • My commits all reference Jira issues in their subject lines. In addition, my commits follow the guidelines from "How to write a good git commit message":
    1. Subject is separated from body by a blank line
    2. Subject is limited to 50 characters (not including Jira issue reference)
    3. Subject does not end with a period
    4. Subject uses the imperative mood ("add", not "adding")
    5. Body wraps at 72 characters
    6. Body explains "what" and "why", not "how"

Documentation

  • In case of new functionality, my PR adds documentation that describes how to use it.
    • All the public functions and the classes in the PR contain Javadoc that explain what it does

@zcsizmadia zcsizmadia marked this pull request as draft February 26, 2022 20:03
@zcsizmadia
Copy link
Contributor Author

zcsizmadia commented Feb 26, 2022

@martin-g @RyanSkraba

This is a proposed way to simplify the release process for the C#. Step #9 in https://cwiki.apache.org/confluence/display/AVRO/How+To+Release#HowToRelease-Publishing could be reduced to the following if running from the ../lang/csharp folder:

NUGET_KEY="YOUR_KEY" ./build.sh release

This step requires that ./build.sh dist was executed earlier. That requirement can be eliminated by running dotnet pack --configuration Release Avro.sln as the first thing in release, however the dist step might be already done at the time when release is happening.

Other languages might follow this pattern so the release step would become a series of ./build.sh release from all language.

@@ -76,6 +76,35 @@ do
cp -pr build/doc/* ${ROOT}/build/avro-doc-${VERSION}/api/csharp
;;

release)
# "dist" step must be executed before this step
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about the following:

extract all the logic in dist) to a function, so it will look like:

...
dist)
   dist()
release)
  release()
...

This way the first few lines of release() could check if there are artifacts created by dist() and call dist() if there are no such. Something like:

function release() {
  if [ ! -f .../some/file ]; then
    dist()
  fi

  # release stuff
}

# If not specified use default location
[ "$NUGET_SOURCE" ] || NUGET_SOURCE="https://api.nuget.org/v3/index.json"

# Set NUGET_KEY beofre executing script. E.g. `NUGET_KEY="YOUR_KEY" ./build.sh release`
Copy link
Member

Choose a reason for hiding this comment

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

typo in before

@zcsizmadia
Copy link
Contributor Author

@martin-g I can check if the tar.gz exists and all the needed nupkgs exist, if not execute the dist() function as you described above. I have it implemented locally and I can commit it.

However, what about if there is no release action, but RELEASE=true NUGET_KEY="YOUR_KEY" ./build.sh dist needed to be executed:

  dist)
    ...
    if "$RELEASE"
    then
        ...
        # Bunch of nuget push ...
    fi
    ;;

@martin-g
Copy link
Member

what about if there is no release action, but RELEASE=true NUGET_KEY="YOUR_KEY" ./build.sh dist

I like it!

@zcsizmadia zcsizmadia changed the title AVRO-3424: Add build.sh step to encapsulate all the steps needed during release AVRO-3423: Add build.sh step to encapsulate all the steps needed during release Feb 26, 2022
@zcsizmadia
Copy link
Contributor Author

This runs dist step and pushes the nupkgs to nuget.org:

RELEASE=1 NUGET_KEY="YOUR_KEY" ./build.sh dist

./build.sh dist is the same as it was before.

Is there any place where the NUGET_KEY is stored already on the "release" machine? SO I can default the value to it if NUGET_KEY is not set.

@zcsizmadia
Copy link
Contributor Author

zcsizmadia commented Feb 26, 2022

I still like the a new release step.This is another alternative to combine dist and release:

  dist|release)
     # dist steps
      ...
      if [ "$target" == "release" ]
      then
        # Push packages
        ...
      fi

@zcsizmadia
Copy link
Contributor Author

Added a verify-release step to simplify and harden the verisifcation step after the release. It iterates through all the supported dotnet code SDKS to make sure that all the libs and tool can be installed from nuget for all the SDKs.

@RyanSkraba
Copy link
Contributor

I really like one advantage of this -- I have tons of notes (in addition to the wiki) for releasing binary artifacts and doing the equivalent of verify-release. I've always intended to clean my notes up and contribute them back, and it would be really neat to do that in the build scripts themselves.

Unfortunately, I'm kind of skittish about delegating these steps to a script and generalizing them to all languages... I'd find it hard to "trust" doing a ./build.sh release from the root and have all of the binary artifacts deployed -- especially if there were failures midway or something unexpected happens (it always does).

Note that the Wiki process isn't immune to that either (check out the Python SDK release 1.9.2.1 as an example of fixing a bad deploy!)

I don't have any good ideas for that other than prompting (y/n/skip) at each command! Any ideas?

@zcsizmadia
Copy link
Contributor Author

Adding a step function might be a good solution to help out skittish users ;)

function step
{
    ask if want to run [y/skip/abort]
    if no, return
    if abort, exit shole script
    execute $1
    if error code == 0 -> green message: step complete
    if error code != 0 -> red message: step failed (maybe question for retry/abort?)
}

   release)
       step "dotnet nuget push A.B.C.nupkg"
       step "dotnet nuget push A.B.C.D.nupkg"
       ...

Btw, couls you post how the release is happening now? Are you executing the steps from the wiki page in blocks, or each line one by one from those code snipptes for each step?

@zcsizmadia
Copy link
Contributor Author

@RyanSkraba Added a ask function to the script and usage to the verify-release step as an example. It asks for each SDKs how to proceed. If there is any error anytime, the script stops.

Verify .NET SDK 3.1 ([y]es/[n]o/([a]bort)? y
...
Verify .NET SDK 5.0 ([y]es/[n]o/([a]bort)? y
...

@RyanSkraba
Copy link
Contributor

(Please excuse the delay! I've been playing catch-up with emails)

Btw, could you post how the release is happening now? Are you executing the steps from the wiki page in blocks, or each line one by one from those code snipptes for each step?

Effectively, I've been doing commands from the wiki page -- the commands that can be reverted or backed out in blocks and the commands that (permanently) publish artifacts one at a time. Usually one SDK at a time. Even if it's a bit fussy, it's really only about an hours work!

I like the ask function and if we generalize this process (release and verify-release) to other language SDKs, we should probably also generalize that! If one day we get to the state where we're completely automating releases, this will be welcome. We probably don't need to ask to verify, right? It's fine though as it is!

Perhaps a future feature would be to not ask but to echo out the command instead of executing it.

@zcsizmadia
Copy link
Contributor Author

I added soem better command line argument parsing and option fro dry run, answer yes to all questions .... It is better to have a more standard way of handling wehn the number of options start to inscrease.

It is possible to put most of these build.sh framework into /share/build-helper script, and pretty much all languages just source /share/build-helper and implenet their own commands with functions like function command_test {}. The buidl helper would execute bt something like this command_$1 for the supported commands.

Zoltan Csizmadia added 2 commits March 8, 2022 21:37
@github-actions github-actions bot added the C label Mar 8, 2022
@zcsizmadia
Copy link
Contributor Author

Added cd "$(dirname "$0")" to the top of the build.sh scripts. Previously it was inconsistent , some scripts had it, some did not. If the build.sh is executed from tha lang folder where the build.sh script is, it has no effect.
If the build.sh script is executed from a different folder, it will change into the proper folder and make sure the scripts will work. E.g. lang/csharp/build.sh dist will work.

@zcsizmadia
Copy link
Contributor Author

Modded the C build.sh script as well. Only C++ is left. That script might need some rework, since it has some "non-standard" targets, like doc and 'format' ...

@zcsizmadia
Copy link
Contributor Author

@martin-g Should be able to provide the CARGO_API_TOKEN from the command line as well? --cargo-api-token?
I was thinking to add support for language specific options to the build.sh script. This would perfectly fit there

@martin-g
Copy link
Member

martin-g commented Mar 8, 2022

Env var should work too. I'm fine with both.

{
execute cargo build --release --lib --all-features
execute cargo package
execute mkdir -p "$BUILD_ROOT/dist/rust"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
execute mkdir -p "$BUILD_ROOT/dist/rust"
execute mkdir -p "$dist_dir"

martin-g added 2 commits May 12, 2022 14:41
Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
@martin-g
Copy link
Member

martin-g commented May 13, 2022

@jklamer Please review 69772c3
After some experimentation I concluded that cargo package cannot be used for Workspace project with Virtual manifests when a dependency (e.g. avro_derive) is not yet released.
The .crate (the source package) can be created only after cargo publishing the modules/manifests.

@jklamer
Copy link
Contributor

jklamer commented May 15, 2022

@martin-g will review soon. Currently on vacation but will get to it ASAP


clean() {
git clean -xdf '*.avpr' \
function command_clean()
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove the function keyword from everywhere else instead of adding it here. There is very little practical difference, except that we should default to fewer characters when there is no reasonable argument for more.

function prepare_build()
{
command_clean
execute mkdir -p "$build_dir"
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is execute defined?

Copy link
Contributor Author

@zcsizmadia zcsizmadia Sep 19, 2023

Choose a reason for hiding this comment

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

share/build-helper.sh in the PR. The main reason behind the execute concept was to be able to have a --dry-run option, where the build.sh just prints out what would be running. The user can copy paste it and run it manually step by step if needed, or just simply checking the steps. Additionally there is a step option, IIRC I implemented it :) Wit enables to user to execute the build scripts step by step.

The build helper is pretty much the common code between all the build scripts and all build scripts include it. It has the execute implementation, the common help, the colored logging, etc.

execute make -C "$build_dir" package_source
execute rm "$root_dir"/docs/*.html
if [ ! -d "$dist_dir" ]; then
execute mkdir -p "$dist_dir"
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're using mkdir -p we don't need to check if the dir already exists first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Roger. I followed the original build.sh scripts as much to the letter as possible. At this stage my objective was to be able to easily compare roiginal build shells cripts with the new ones.

Copy link
Contributor

Choose a reason for hiding this comment

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

I understand but since you're adding execute doesn't that make it kind of moot?

@zcsizmadia zcsizmadia closed this by deleting the head repository Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants