d2e/cli build and publish #13872
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: d2e/cli build and publish | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| GIT_REPO_FULL_NAME: | |
| description: Select RepoName | |
| required: false | |
| type: choice | |
| options: | |
| - OHDSI/Data2Evidence | |
| GIT_BRANCH_NAME: | |
| default: develop | |
| description: Enter BranchName / ReleaseTagName | |
| required: true | |
| type: string | |
| tag: | |
| description: Enter tag for release | |
| required: true | |
| type: string | |
| prerelease: | |
| type: boolean | |
| default: true | |
| required: true | |
| overwrite: | |
| type: boolean | |
| default: true | |
| required: true | |
| environment: | |
| description: Select deployment environment | |
| required: false | |
| type: choice | |
| default: npm | |
| options: | |
| - npm | |
| - github | |
| pull_request: | |
| types: [opened, ready_for_review, reopened, synchronize] | |
| merge_group: | |
| push: | |
| branches: | |
| - develop | |
| env: | |
| GIT_BRANCH_NAME: ${{ github.event.inputs.GIT_BRANCH_NAME || github.head_ref || github.ref_name }} # workflow_dispatch || pull_request || push | |
| GIT_REPO_FULL_NAME: ${{ github.event.inputs.GIT_REPO_FULL_NAME || github.event.pull_request.head.repo.full_name || github.event.repository.full_name }} # workflow_dispatch || pull_request || push | |
| jobs: | |
| build-platform: | |
| runs-on: ubuntu-24.04 | |
| strategy: | |
| matrix: | |
| include: | |
| - target: bun-linux-x64 | |
| filename: linux-x64 | |
| - target: bun-linux-arm64 | |
| filename: linux-arm64 | |
| - target: bun-darwin-x64 | |
| filename: darwin-x64 | |
| - target: bun-darwin-arm64 | |
| filename: darwin-arm64 | |
| - target: bun-windows-x64 | |
| filename: windows-x64.exe | |
| environment: ${{github.event_name == 'workflow_dispatch' && github.event.inputs.environment || 'github'}} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ env.GIT_BRANCH_NAME }} | |
| repository: ${{ env.GIT_REPO_FULL_NAME }} | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: 1.2.23 | |
| - name: Update version | |
| run: | | |
| if [[ ${{ github.event_name }} == 'workflow_dispatch' ]]; then | |
| RELEASE_VERSION=${{ github.event.inputs.tag }} | |
| if [[ "${{ github.event.inputs.environment }}" == 'npm' ]]; then | |
| # Unscoped name for npmjs.org | |
| jq --arg v $RELEASE_VERSION '.version=$v | .name="d2e" | del(.optionalDependencies)' package.json > tmppkg; mv tmppkg package.json | |
| else | |
| # Keep scoped name for GitHub Packages | |
| jq --arg v $RELEASE_VERSION '.version=$v | del(.optionalDependencies)' package.json > tmppkg; mv tmppkg package.json | |
| fi | |
| else | |
| jq --arg v "-$(date +%s)-$GITHUB_SHA" '.version+=$v | del(.optionalDependencies)' package.json > tmppkg; mv tmppkg package.json | |
| fi | |
| - name: bun install | |
| run: bun install | |
| - name: Build executables | |
| run: | | |
| bun build --compile ./scripts/dist/cli.js --outfile ./${{ matrix.filename }} --target ${{ matrix.target }} | |
| - name: Prepare | |
| run: | | |
| if [[ ${{ github.event_name }} == 'workflow_dispatch' ]]; then | |
| echo "PRERELEASE=${{ github.event.inputs.prerelease }}" | tee -a $GITHUB_ENV | tee -a $GITHUB_STEP_SUMMARY | |
| echo "OVERWRITE=${{ github.event.inputs.overwrite }}" | tee -a $GITHUB_ENV | tee -a $GITHUB_STEP_SUMMARY | |
| TAG=${{ github.event.inputs.tag }} | |
| echo "TAG=$TAG" | tee -a $GITHUB_ENV | tee -a $GITHUB_STEP_SUMMARY | |
| ASSET_NAME=data2evidence-cli-${TAG} | |
| echo "ASSET_NAME=$ASSET_NAME" | tee -a $GITHUB_ENV | tee -a $GITHUB_STEP_SUMMARY | |
| GITHUB_RELEASE=v${{ github.event.inputs.tag }} | |
| echo "GITHUB_RELEASE=$GITHUB_RELEASE" | tee -a $GITHUB_ENV | tee -a $GITHUB_STEP_SUMMARY | |
| else | |
| echo "PRERELEASE=true" | tee -a $GITHUB_ENV | tee -a $GITHUB_STEP_SUMMARY | |
| echo "OVERWRITE=true" | tee -a $GITHUB_ENV | tee -a $GITHUB_STEP_SUMMARY | |
| TAG=latest | |
| echo "TAG=$TAG" | tee -a $GITHUB_ENV | tee -a $GITHUB_STEP_SUMMARY | |
| ASSET_NAME=data2evidence-cli | |
| echo "ASSET_NAME=$ASSET_NAME" | tee -a $GITHUB_ENV | tee -a $GITHUB_STEP_SUMMARY | |
| echo "GITHUB_RELEASE=latest" | tee -a $GITHUB_ENV | tee -a $GITHUB_STEP_SUMMARY | |
| fi | |
| - name: Push platforms | |
| uses: svenstaro/upload-release-action@v2 | |
| if: github.ref_name == 'develop' || github.event_name == 'workflow_dispatch' | |
| with: | |
| repo_token: ${{ secrets.GITHUB_TOKEN }} | |
| file: ${{ matrix.filename }} | |
| tag: ${{ env.GITHUB_RELEASE }} | |
| target_commit: ${{ github.ref_name }} | |
| prerelease: ${{ env.PRERELEASE }} | |
| overwrite: ${{ env.OVERWRITE }} | |
| asset_name: ${{ env.ASSET_NAME }}-${{ matrix.filename }} | |
| build: | |
| needs: build-platform | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - run: echo "All platform builds succeeded" | |
| publish: | |
| needs: build | |
| runs-on: ubuntu-24.04 | |
| environment: ${{github.event_name == 'workflow_dispatch' && github.event.inputs.environment || 'github'}} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ env.GIT_BRANCH_NAME }} | |
| repository: ${{ env.GIT_REPO_FULL_NAME }} | |
| - name: Use Node.js | |
| uses: actions/setup-node@v4 | |
| if: github.event_name != 'workflow_dispatch' || github.event.inputs.environment == 'github' | |
| with: | |
| node-version: "18.x" | |
| registry-url: "https://npm.pkg.github.com" | |
| scope: "@ohdsi" | |
| - name: Use Node.js (prod) | |
| uses: actions/setup-node@v2 | |
| if: github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'npm' | |
| with: | |
| node-version: '18' | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Update version | |
| run: | | |
| if [[ ${{ github.event_name }} == 'workflow_dispatch' ]]; then | |
| RELEASE_VERSION=${{ github.event.inputs.tag }} | |
| if [[ "${{ github.event.inputs.environment }}" == 'npm' ]]; then | |
| # Unscoped name for npmjs.org | |
| jq --arg v $RELEASE_VERSION '.version=$v | .name="d2e" | del(.optionalDependencies)' package.json > tmppkg; mv tmppkg package.json | |
| else | |
| # Keep scoped name for GitHub Packages | |
| jq --arg v $RELEASE_VERSION '.version=$v | del(.optionalDependencies)' package.json > tmppkg; mv tmppkg package.json | |
| fi | |
| else | |
| jq --arg v "-$(date +%s)-$GITHUB_SHA" '.version+=$v | del(.optionalDependencies)' package.json > tmppkg; mv tmppkg package.json | |
| fi | |
| - name: npm build | |
| run: npm install | |
| - name: Publish | |
| run: | | |
| if [[ (${{ env.GIT_BRANCH_NAME }} == 'develop' && ${{ github.event_name }} != 'workflow_dispatch') || (${{ github.event_name }} == 'workflow_dispatch' && "${{ github.event.inputs.environment }}" == 'github') ]]; then | |
| npm publish | |
| else | |
| npm publish --dry-run | |
| fi | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Publish production | |
| if: github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'npm' | |
| run: npm publish --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPMJS_TOKEN }} | |
| - uses: actions/delete-package-versions@v5 | |
| if: github.ref_name == 'develop' | |
| with: | |
| package-name: "d2e" | |
| package-type: "npm" | |
| min-versions-to-keep: 3 | |
| delete-only-pre-release-versions: "true" | |
| - name: Prepare | |
| if: github.ref_name == 'develop' || github.event_name == 'workflow_dispatch' | |
| run: | | |
| if [[ ${{ github.event_name }} == 'workflow_dispatch' ]]; then | |
| echo "PRERELEASE=${{ github.event.inputs.prerelease }}" | tee -a $GITHUB_ENV | tee -a $GITHUB_STEP_SUMMARY | |
| echo "OVERWRITE=${{ github.event.inputs.overwrite }}" | tee -a $GITHUB_ENV | tee -a $GITHUB_STEP_SUMMARY | |
| TAG=${{ github.event.inputs.tag }} | |
| echo "TAG=$TAG" | tee -a $GITHUB_ENV | tee -a $GITHUB_STEP_SUMMARY | |
| ASSET_NAME=data2evidence-cli-${TAG} | |
| echo "ASSET_NAME=$ASSET_NAME" | tee -a $GITHUB_ENV | tee -a $GITHUB_STEP_SUMMARY | |
| GITHUB_RELEASE=v${{ github.event.inputs.tag }} | |
| echo "GITHUB_RELEASE=$GITHUB_RELEASE" | tee -a $GITHUB_ENV | tee -a $GITHUB_STEP_SUMMARY | |
| else | |
| echo "PRERELEASE=true" | tee -a $GITHUB_ENV | tee -a $GITHUB_STEP_SUMMARY | |
| echo "OVERWRITE=true" | tee -a $GITHUB_ENV | tee -a $GITHUB_STEP_SUMMARY | |
| TAG=latest | |
| echo "TAG=$TAG" | tee -a $GITHUB_ENV | tee -a $GITHUB_STEP_SUMMARY | |
| ASSET_NAME=data2evidence-cli | |
| echo "ASSET_NAME=$ASSET_NAME" | tee -a $GITHUB_ENV | tee -a $GITHUB_STEP_SUMMARY | |
| echo "GITHUB_RELEASE=latest" | tee -a $GITHUB_ENV | tee -a $GITHUB_STEP_SUMMARY | |
| fi | |
| - name: Pack | |
| if: github.ref_name == 'develop' || github.event_name == 'workflow_dispatch' | |
| run: | | |
| NPM_FILENAME=$(npm pack | tail -n 1) | |
| echo "NPM_FILENAME=$NPM_FILENAME" >> $GITHUB_ENV | |
| - name: Push | |
| uses: svenstaro/upload-release-action@v2 | |
| if: github.ref_name == 'develop' || github.event_name == 'workflow_dispatch' | |
| with: | |
| repo_token: ${{ secrets.GITHUB_TOKEN }} | |
| file: ${{ env.NPM_FILENAME }} | |
| tag: ${{ env.GITHUB_RELEASE }} | |
| target_commit: ${{ github.ref_name }} | |
| prerelease: ${{ env.PRERELEASE }} | |
| overwrite: ${{ env.OVERWRITE }} | |
| asset_name: ${{ env.ASSET_NAME }}.tgz |