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(dist): replace wget to curl to download swagger-ui #2277

Merged
merged 20 commits into from
Aug 25, 2023

Conversation

VGalaxies
Copy link
Contributor

@VGalaxies VGalaxies commented Aug 12, 2023

Purpose of the PR

close #2223

related issue or PR:

Main Changes

  1. replace wget by curl when downloading swagger-ui
  2. silence the output of curl and tar commands
  3. reuse the existing v4.15.5.tar.gz before downloading
  4. avoid downloading swagger-ui in non-Linux platforms to prevent build failures (there might be a cross-platform build approach available 🤔)
  5. wrapp the script content within <![CDATA[ ... ]]> blocks ensures that the script retains its original format when generating the dist.sh script (also suppresses automatic indentation)
  6. remove intermediate files at the end of the script

An alternative approach, during the generation of the dist.sh script, only the ${final.name} property from the build process is utilized. It might be possible to separately store a dist.sh script within hugegraph-dist, then use sed during the build process to replace the value of ${final.name}, thereby avoiding the need to embed script content within the pom file.

Verifying these changes

  • Trivial rework / code cleanup without any test coverage. (No Need)
  • Already covered by existing tests, such as (please modify tests here).
  • Need tests and can be verified as follows:
    • xxx

Does this PR potentially affect the following parts?

  • Nope
  • Dependencies (add/update license info)
  • Modify configurations
  • The public API
  • Other affects (typed here)

Documentation Status

  • Doc - TODO
  • Doc - Done
  • Doc - No Need

@codecov
Copy link

codecov bot commented Aug 12, 2023

Codecov Report

Merging #2277 (f707fcb) into master (b02c2bd) will decrease coverage by 0.39%.
Report is 2 commits behind head on master.
The diff coverage is n/a.

@@             Coverage Diff              @@
##             master    #2277      +/-   ##
============================================
- Coverage     68.63%   68.24%   -0.39%     
- Complexity      977      981       +4     
============================================
  Files           498      498              
  Lines         40684    41240     +556     
  Branches       5681     5738      +57     
============================================
+ Hits          27922    28146     +224     
- Misses        10056    10363     +307     
- Partials       2706     2731      +25     

see 73 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

hugegraph-dist/pom.xml Outdated Show resolved Hide resolved
@imbajin imbajin mentioned this pull request May 15, 2023
15 tasks
@imbajin imbajin self-assigned this Aug 14, 2023
@imbajin imbajin added this to the 1.5.0 milestone Aug 14, 2023
@imbajin imbajin changed the title build(dist): improve download-swagger-ui in hugegraph-dist chore(dist): improve download-swagger-ui in hugegraph-dist Aug 14, 2023
@imbajin imbajin changed the title chore(dist): improve download-swagger-ui in hugegraph-dist chore(dist): replace wget to curl to download swagger-ui Aug 14, 2023
@VGalaxies VGalaxies requested a review from imbajin August 14, 2023 14:01
@VGalaxies
Copy link
Contributor Author

also added maven-enforcer-plugin to check java and maven version for #2114 (comment)

hugegraph-dist/pom.xml Outdated Show resolved Hide resolved
@VGalaxies VGalaxies requested a review from imbajin August 21, 2023 07:35
imbajin
imbajin previously approved these changes Aug 21, 2023
@VGalaxies
Copy link
Contributor Author

VGalaxies commented Aug 22, 2023

The order of executions related to packaging should be assembly-hugegraph -> install-swagger-ui (copy and remove) -> tar-package. The download-swagger-ui goal only needs to be completed before install-swagger-ui (currently bound to the prepare-package phase).

To control the execution order of different goals within the same phase, consider declaring the above executions in sequence within the pluginManagement of the root pom. Also use conditions like os and file to ensure that these goals are executed only within the Unix or macOS environment, specifically within the hugegraph-dist module.

pom.xml Outdated Show resolved Hide resolved
@VGalaxies VGalaxies requested a review from imbajin August 22, 2023 09:54
pom.xml Outdated Show resolved Hide resolved
pom.xml Outdated
</build>
</profile>
<profile>
<id>assembly-hugegraph</id>
Copy link
Member

Choose a reason for hiding this comment

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

after we move the profile, what's the proper building command?

Before:
mvn clean install -Papache-release -DskipTests for building apache-release source/binary package

Now: ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When a profile is activated through the implicit profile activation mechanism, the explicit profile activation mechanism within the same pom becomes ineffective.

So it's necessary to explicitly specify the profiles:

mvn clean install -Papache-release,assembly-hugegraph,tar-package -DskipTests

ref: https://maven.apache.org/guides/introduction/introduction-to-profiles.html#explicit-profile-activation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When a profile is activated through the implicit profile activation mechanism, the explicit profile activation mechanism within the same pom becomes ineffective.

So it's necessary to explicitly specify the profiles:

mvn clean install -Papache-release,assembly-hugegraph,tar-package -DskipTests

ref: maven.apache.org/guides/introduction/introduction-to-profiles.html#explicit-profile-activation

The relevant scripts and documentation need to be updated later.

pom.xml Outdated
Comment on lines 486 to 487
<id>download-swagger-ui</id>
<phase>prepare-package</phase>
Copy link
Member

Choose a reason for hiding this comment

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

seems this step will not be inherited by other modules?

Comment on lines 271 to 303
<profile>
<id>tar-package</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>tar-package</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<tar destfile="${final.destfile}" compression="gzip">
<tarfileset dir="${top.level.dir}/" filemode="755">
<include name="${final.name}/**"/>
</tarfileset>
</tar>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

After introducing pd and store (#2265), the relevant package goals could be considered for reuse.

Copy link
Member

Choose a reason for hiding this comment

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

After introducing pd and store (#2265), the relevant package goals could be considered for reuse.

@msgui could also take a look for this PR, and it will be helpful when u refactor the new struct

Comment on lines 271 to 303
<profile>
<id>tar-package</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>tar-package</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<tar destfile="${final.destfile}" compression="gzip">
<tarfileset dir="${top.level.dir}/" filemode="755">
<include name="${final.name}/**"/>
</tarfileset>
</tar>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
Copy link
Member

Choose a reason for hiding this comment

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

After introducing pd and store (#2265), the relevant package goals could be considered for reuse.

@msgui could also take a look for this PR, and it will be helpful when u refactor the new struct

</plugins>

<pluginManagement>
Copy link
Member

@imbajin imbajin Aug 23, 2023

Choose a reason for hiding this comment

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

need pluginManagement?

BTW, all the CI failed now 🔎

Copy link
Contributor Author

Choose a reason for hiding this comment

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

need pluginManagement?

BTW, all the CI failed now 🔎

  1. for reuse the configuration of the maven-antrun-plugin
  2. because of chore(dist): replace wget to curl to download swagger-ui  #2277 (comment), fix in 880d283 (#2277)

@VGalaxies
Copy link
Contributor Author

VGalaxies commented Aug 23, 2023

Following this discussion:

Through researching relevant information, we found that the semantics of activeByDefault are somewhat counterintuitive. In a particular pom, if a profile is activated through:

  1. Specifying it via the command line using -Pxxx, or
  2. Defining it in the Maven settings using <activeProfiles>, or
  3. Implicit profile activation, such as jdk, os, property, file

Then, within the same pom, a profile configured with activeByDefault set to true will NOT be activated.

To avoid explicitly specifying profiles suppressed from activation due to the aforementioned mechanisms via -Pxxx in the command line, we referred to the approach outlined in the official documentation:

<profiles>
  <profile>
    <id>xxx</id>
    <activation>
      <property>
        <name>!skip-xxx</name>
      </property>
    </activation>
    ...
  </profile>
</profiles>

Using the property mechanism within implicit profile activation to activate profiles configured with activeByDefault set to true.

Additionally, it's important to minimize occurrences of identical property names across different profiles. For example:

img_v2_97f89063-b734-4fa1-932f-0bf74c69867g

In a scenario where both profiles are activated, the value of env is test (dev is loaded and then overridden). Explicitly specifying -Pdev could result in the value of env becoming dev, which might introduce potential issues.

References:

  1. Maven Introduction to Profiles - Property Activation
  2. Stack Overflow - How to Keep Maven Profiles which are activeByDefault active

@VGalaxies VGalaxies requested a review from imbajin August 23, 2023 13:16
@VGalaxies
Copy link
Contributor Author

VGalaxies commented Aug 24, 2023

TODO: We have observed that when the core-test profile under the root pom is activated using the aforementioned approach, it leads to failures while running the majority of backend api-test cases. For more details, please refer to: GitHub Actions Run.

also provide the expected result: GitHub Actions Run

There might be an issue with the run-core-test.sh script.

Copy link
Member

@imbajin imbajin left a comment

Choose a reason for hiding this comment

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

LGTM

@imbajin imbajin merged commit 77c7612 into apache:master Aug 25, 2023
18 of 21 checks passed
@VGalaxies VGalaxies deleted the dist-build branch August 29, 2023 12:59
DanGuge pushed a commit to DanGuge/incubator-hugegraph that referenced this pull request Sep 25, 2023
Main Changes:
1. replace `wget` by `curl` when downloading `swagger-ui`
2. silence the output of `curl` and `tar` commands
3. reuse the existing `v4.15.5.tar.gz` before downloading
4. avoid downloading `swagger-ui` in non-Linux platforms to prevent build failures (there might be a cross-platform build approach available 🤔)
5. wrapp the script content within `<![CDATA[ ... ]]>` blocks ensures that the script retains its original format when generating the `dist.sh` script (also suppresses automatic indentation)
6. remove intermediate files at the end of the script

**An alternative approach**, during the generation of the `dist.sh` script, only the `${final.name}` property from the build process is utilized. It might be possible to separately store a `dist.sh` script within hugegraph-dist, then use `sed` during the build process to replace the value of `${final.name}`, **thereby avoiding the need to embed script content within the pom file**.

---------

Co-authored-by: imbajin <jin@apache.org>
VGalaxies added a commit to VGalaxies/incubator-hugegraph that referenced this pull request Nov 10, 2023
Main Changes:
1. replace `wget` by `curl` when downloading `swagger-ui`
2. silence the output of `curl` and `tar` commands
3. reuse the existing `v4.15.5.tar.gz` before downloading
4. avoid downloading `swagger-ui` in non-Linux platforms to prevent build failures (there might be a cross-platform build approach available 🤔)
5. wrapp the script content within `<![CDATA[ ... ]]>` blocks ensures that the script retains its original format when generating the `dist.sh` script (also suppresses automatic indentation)
6. remove intermediate files at the end of the script

**An alternative approach**, during the generation of the `dist.sh` script, only the `${final.name}` property from the build process is utilized. It might be possible to separately store a `dist.sh` script within hugegraph-dist, then use `sed` during the build process to replace the value of `${final.name}`, **thereby avoiding the need to embed script content within the pom file**.

---------

Co-authored-by: imbajin <jin@apache.org>
imbajin added a commit that referenced this pull request Nov 10, 2023
Main Changes:
1. replace `wget` by `curl` when downloading `swagger-ui`
2. silence the output of `curl` and `tar` commands
3. reuse the existing `v4.15.5.tar.gz` before downloading
4. avoid downloading `swagger-ui` in non-Linux platforms to prevent build failures (there might be a cross-platform build approach available 🤔)
5. wrapp the script content within `<![CDATA[ ... ]]>` blocks ensures that the script retains its original format when generating the `dist.sh` script (also suppresses automatic indentation)
6. remove intermediate files at the end of the script

**An alternative approach**, during the generation of the `dist.sh` script, only the `${final.name}` property from the build process is utilized. It might be possible to separately store a `dist.sh` script within hugegraph-dist, then use `sed` during the build process to replace the value of `${final.name}`, **thereby avoiding the need to embed script content within the pom file**.

---------

Co-authored-by: imbajin <jin@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[Enhancement] Avoid repeated downloads of swagger while building
3 participants