Unverified Commit c0f72fbf authored by ysaito1001's avatar ysaito1001 Committed by GitHub
Browse files

Enable stable & unstable versions in release workflow (#3201)

## Motivation and Context
Addresses `TODO(GA)` from
https://github.com/smithy-lang/smithy-rs/pull/3082

## Description
This small PR will remove a guard so we can truly specify different
versions for stable crates and unstable crates. Previously, whatever
that's entered in `Stable semantic version` in the release workflow
textbox (see a screenshot in the above PR) is overwritten by what's
entered in `Unstable semantic version`. With this PR, whatever that's
entered in `Stable semantic version` will make its way to
`smithy.rs.runtime.crate.stable.version` in `gradle.properties`.

In addition, with this PR, the name of a release branch is derived from
what we enter in `Stable semantic version` in the release workflow
textbox.

## Testing
~~It has been tested in the above PR.~~

EDIT:
Found a bug I introduced in the above PR where `publisher` was not
reading a metadata `package.metadata.smithy-rs-release-tooling`
correctly in a manifest file. Fixed it in c477d2f, confirmed that a
[dry-run](https://github.com/smithy-lang/smithy-rs/actions/runs/6872502257)
passed, and verified the release artifact contained both stable crate
versions & unstable versions as expected.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
parent 8a453134
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -99,8 +99,7 @@ jobs:
      id: branch-push
      shell: bash
      env:
        # TODO(GA): specify ${{ inputs.stable_semantic_version }}
        SEMANTIC_VERSION: ${{ inputs.unstable_semantic_version }}
        SEMANTIC_VERSION: ${{ inputs.stable_semantic_version }}
        DRY_RUN: ${{ inputs.dry_run }}
      run: |
        set -e
@@ -141,8 +140,7 @@ jobs:
      working-directory: upgrade-gradle-properties/smithy-rs
      shell: bash
      env:
        # TODO(GA): specify ${{ inputs.stable_semantic_version }}
        SEMANTIC_VERSION: ${{ inputs.unstable_semantic_version }}
        SEMANTIC_VERSION: ${{ inputs.stable_semantic_version }}
        RELEASE_COMMIT_SHA: ${{ inputs.commit_sha }}
        RELEASE_BRANCH_NAME: ${{ needs.get-or-create-release-branch.outputs.release_branch }}
        DRY_RUN: ${{ inputs.dry_run }}
@@ -161,7 +159,13 @@ jobs:
          # to retry a release action execution that failed due to a transient issue.
          # In that case, we expect the commit to be releasable as-is, i.e. the runtime crate version in gradle.properties
          # should already be the expected one.
          if [[ "${DRY_RUN}" == "true" ]]; then
            # During dry-runs, "git push" without "--force" can fail if smithy-rs-release-x.y.z-preview is behind
            # smithy-rs-release-x.y.z, but that does not matter much during dry-runs.
            git push --force origin "HEAD:refs/heads/${RELEASE_BRANCH_NAME}"
          else
            git push origin "HEAD:refs/heads/${RELEASE_BRANCH_NAME}"
          fi

          echo "commit_sha=$(git rev-parse HEAD)" > $GITHUB_OUTPUT
        else
+51 −1
Original line number Diff line number Diff line
@@ -88,7 +88,9 @@ impl Manifest {
    fn stability(&self) -> Result<PackageStability> {
        let value = self
            .metadata
            .get("package.metadata.smithy-rs-release-tooling")
            .get("package")
            .and_then(|v| v.get("metadata"))
            .and_then(|v| v.get("smithy-rs-release-tooling"))
            .and_then(|v| v.get("stable"));
        match value {
            None => Ok(PackageStability::Unstable),
@@ -520,4 +522,52 @@ mod tests {
            "aws-sdk-rust/examples/foo/bar/Cargo.toml"
        ));
    }

    #[test]
    fn test_package_stability_from_manifest() {
        fn verify_package_stability_for_manifest(
            manifest: &[u8],
            expected_stability: PackageStability,
        ) {
            let metadata = toml::from_slice(manifest).unwrap();
            let manifest = Manifest {
                path: "test".into(),
                metadata,
            };
            assert_eq!(expected_stability, manifest.stability().unwrap());
        }

        let stable_manifest = br#"
            [package]
            name = "test"
            version = "1.0.0"

            [package.metadata.smithy-rs-release-tooling]
            stable = true
        "#;
        verify_package_stability_for_manifest(stable_manifest, PackageStability::Stable);

        let explicitly_unstable_manifest = br#"
            [package]
            name = "test"
            version = "0.1.0"

            [package.metadata.smithy-rs-release-tooling]
            stable = false
        "#;
        verify_package_stability_for_manifest(
            explicitly_unstable_manifest,
            PackageStability::Unstable,
        );

        let implicitly_unstable_manifest = br#"
            [package]
            name = "test"
            version = "0.1.0"
        "#;
        verify_package_stability_for_manifest(
            implicitly_unstable_manifest,
            PackageStability::Unstable,
        );
    }
}
+1 −2
Original line number Diff line number Diff line
@@ -15,8 +15,7 @@ mkdir -p "${ARTIFACTS_DIR}"
pushd "${SMITHY_RS_DIR}"
echo "gradle.properties BEFORE the upgrade"
cat gradle.properties
# TODO(GA): pass ${STABLE_SEMANTIC_VERSION} to --stable-version
publisher upgrade-runtime-crates-version --stable-version "${UNSTABLE_SEMANTIC_VERSION}" --version "${UNSTABLE_SEMANTIC_VERSION}"
publisher upgrade-runtime-crates-version --stable-version "${STABLE_SEMANTIC_VERSION}" --version "${UNSTABLE_SEMANTIC_VERSION}"
echo "gradle.properties AFTER the upgrade"
cat gradle.properties
git status