How to Become A Programming Polyglot by One-language Effort

1. Introduction
2. Preparation
2.1 Initialize a projen project
2.2 Figure out each projen command and arguments in AwsCdkConstructLibrary
2.3 Build a construct library
3. Publishing to supported language repositories
3.1 How to publish a package in npm?
- Arguments in the .projenrc.js you need to give attention to
- Required information by Github Actions
3.2 How to publish a package to PyPi?
- Arguments in .projenrc.js you need to give attention to
- Required information by Github Actions
3.3 How to publish a package to Maven?
- Arguments in the .projenrc.js you need to give attention to
- Few more steps for Maven
- Required information by Github Actions
3.4 How to publish a package to Nuget?
- Arguments in the .projenrc.js you need to give attention to
- required information by Github Actions
4. Conclusion
Required Secrets by Github Actions in order to Publish Construct Library in Maven, PyPI, npm, and NuGet

Introduction

Preparation

Initialize a projen project

$ npx projen new awscdk-construct
$ alias pj='npx projen' // I moved it into ~/.bash_profile on my M1.

Figure out each projen command and arguments in AwsCdkConstructLibrary

Build a construct library

State Machine Diagram Generated by CDK Example

Publishing to supported language repositories

How to publish a package in npm?

  • releaseBranches: branches which trigger a release.
  • releaseToNpm : automatically release to npm when new versions are introduced.
  • releaseWorkflow: define a GitHub workflow for releasing from “main” when new versions are bumped.
  • releaseEveryCommit: automatically release new versions every commit to one of branches in releaseBranches.
new AwsCdkConstructLibrary({
.
.
.
releaseToNpm: true,
releaseBranches: ['main'],
releaseWorkflow: true,
releaseEveryCommit: true
.
.
.
})
  • NPM_TOKEN: it is required by Github Actions to publish the npm package.
  1. create an npm account (email validation is required)
  2. create an access token on the web page of your npm account. Choose the type of AUTOMATION when you’re about to create the access token. AUTOMATION! AUTOMATION! AUTOMATION TYPE! It’s important to be emphasized three times.
  3. store the access token as an Actions secret in your Github repository.
Email Message after Publishing an npm package via projen with success

How to publish a package to PyPi?

  • publishToPypi
publishToPypi: {    
distName: 'scotthsieh_projen_statemachine',
module: 'scotthsieh_projen_statemachine'
}
  • TWINE_USERNAME
  • TWINE_PASSWORD
Python Package in Your PyPI Account after a Successful CICD by Github Actions.

How to publish a package to Maven?

  • publishToMaven
publishToMaven: {
mavenGroupId: 'io.github.hsiehshujeng',
mavenArtifactId: 'projen-inception',
javaPackage: 'io.github.hsiehshujeng.projen.inception',
mavenEndpoint: 'https://s01.oss.sonatype.org' // check https://central.sonatype.org/publish/release/#login-into-ossrh
},
  1. Create an account for Maven central
    You need to create an account for Maven central via OSSRH. Two short films in the guide will be helpful. You could choose a domain as groupId e.g. org.example, for the account, or your Github name as groupId , e.g. io.github.${GITHUB_USERNAME}. (com.github has no long been supported as a valid groupId since Apr. 1st, 2021 and the detail can be looked up here)
    After you create a JIRA issue in the Sonatype JIRA tracking system, you’ll get response within sometime. Take me for example, it’s only a 4-minute waiting after I created the JIRA issue. You only need to respond accordingly from their robotic response.
    Within this exploration for projen, my account for Maven is connected to the JIRA issue OSSRH-68981.
  2. Create a GPG key
    How to generate the GPG key for my projen project to produce the Java library? You could refer to ‘How to create a GPG key?’ at the section of Maven in jsii-release. During the generating progress of the GPG key, you will be asked to enter a passphrase for the key. Please memorize the passphrase of the GPG key in any way like it’s your lifetime partner, promise me, since you’ll need it for an Actions secret and exporting the private key.
    Some information you might find it useful.
    • consider executing $ gpg --full-generate-key and choose RSA with the length of 4,096.
    • you’ll need to paste the public key onto https://keyserver.ubuntu.com/.
  • MAVEN_GPG_PRIVATE_KEY: execute the following command then past the one-line content to this Actions secret.
echo $(cat -e private.pem) | sed 's/\$ /\\n/g' | sed 's/\$$//'
  • MAVEN_GPG_PRIVATE_KEY_PASSPHRASE: the passphrase you entered during the generating progress of the GPG key.
  • MAVEN_USERNAME: the user name you take to log-in the Sonatype JIRA tracking system.
  • MAVEN_PASSWORD: the password you take to log-in the Sonatype JIRA tracking system.
  • MAVEN_STAGING_PROFILE_ID, an identity shown up on the URL of Staging Profile after logging in https://s01.oss.sonatype.org/.
Java Package Searched with io.github.hsiehshujeng after a Successful CICD by Github Actions.
Search Result at Maven Central Repository Search

How to publish a package to Nuget?

  • publishToNuget
publishToNuget: {
dotNetNamespace: 'ScottHsieh.Examples',
packageId: 'Projen.Inception',
},
  • NUGET_API_KEY: a token that enables your project to deploy a NuGet package
Received Email Message after Publishing a NuGet package via projen with success

How to publish a package to Go? ( Incomplete)

  • publsihToGo
  • NUGET_API_KEY: a token that enables your project to deploy a nuget package

Conclusion

Packages Output to Supported Language Repositories with Success
  • how to deploy with Typescript: refer to here
  • how to deploy with Python: refer to here
  • how to deploy with Java: refer to here
  • how to deploy with Csharp: refer to here
A Glimpse of Successful Deployments via Different Programming Languages

References

  1. Ben-Israel, E., 2021. PROJECT STRUCTURE. [online] Cdkworkshop.com. Available at: <https://cdkworkshop.com/40-dotnet/20-create-project/300-structure.html> [Accessed 18 May 2021].
  2. Bui-Palsulich, T., 2019. Publishing Go Modules — The Go Blog. [online] Blog.golang.org. Available at: <https://blog.golang.org/publishing-go-modules> [Accessed 15 May 2021].
  3. Central.sonatype.org. 2021. Central Repository Changelog — The Central Repository Documentation. [online] Available at: <https://central.sonatype.org/changelog/#2021-04-01-comgithub-is-not-supported-anymore-as-a-valid-coordinate> [Accessed 15 May 2021].
  4. Central.sonatype.org. 2021. OSSRH Guide — The Central Repository Documentation. [online] Available at: <https://central.sonatype.org/publish/publish-guide/#deployment> [Accessed 15 May 2021].
  5. Docs.github.com. 2021. Encrypted secrets — GitHub Docs. [online] Available at: <https://docs.github.com/en/actions/reference/encrypted-secrets> [Accessed 15 May 2021].
  6. Docs.npmjs.com. 2021. About access tokens | npm Docs. [online] Available at: <https://docs.npmjs.com/about-access-tokens> [Accessed 15 May 2021].
  7. Hesse, S., 2021. Migrating a CDK Construct to projen and jsii . [online] Sebastian Hesse — Software Engineer. Available at: <https://www.sebastianhesse.de/2021/03/01/migrating-a-cdk-construct-to-projen-and-jsii/> [Accessed 15 May 2021].
  8. Jones, M., 2019. Scoped API keys. [online] Docs.microsoft.com. Available at: <https://docs.microsoft.com/en-us/nuget/nuget-org/scoped-api-keys> [Accessed 16 May 2021].
  9. Sonatype, Inc., 2021. OSSRH Guide — The Central Repository Documentation. [online] Central.sonatype.org. Available at: <https://central.sonatype.org/publish/publish-guide/> [Accessed 15 May 2021].
  10. The Apache Software Foundation, 2021. Maven — Guide to uploading artifacts to the Central Repository. [online] Maven.apache.org. Available at: <https://maven.apache.org/repository/guide-central-repository-upload.html> [Accessed 15 May 2021].
  11. seeebiii, 2021. Create and Publish CDK Constructs Using projen and jsii. [online] GitHub. Available at: <https://github.com/seeebiii/projen-test> [Accessed 15 May 2021].

--

--

--

10 x AWS-certified, Data Architect in the 104 Corporation. An AWS Community Builder

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Service Mesh, Istio and Why Do We Need It

Dealing with a Dependency Hell

Create Features Toggles Using AWS AppConfig in Spring Boot

How to setup MongoDB Atlas database for your project

Shibboleth for Beginners — Part 1

Moralis Launches Support for Magic

Architecting Model Based Engineering Environments and OpenMBEE 4.0

A Quantum Computing Library in 48 Lines of Python

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Scott Hsieh (史考特)

Scott Hsieh (史考特)

10 x AWS-certified, Data Architect in the 104 Corporation. An AWS Community Builder

More from Medium

Viafoura Conversations — Making Custom User Badges using Python

Serverless — What? Why? How?

5 Reasons why APEX is the best for enterprise application development

Working with a stack you don’t know