Build and Publish #34
This file contains 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: Build and Publish | |
on: | |
workflow_dispatch: # Only manual trigger and only for the main branch | |
branches: | |
- main | |
inputs: | |
bump_level: | |
type: choice | |
description: Select bump level | |
required: true | |
options: | |
- patch | |
- minor | |
- major | |
env: | |
IMAGE_NAME: databricks-cdk-lambda | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
jobs: | |
build-and-publish: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
with: | |
token: ${{ secrets.GIT_TOKEN_DANIEL }} | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '16.x' | |
registry-url: 'https://registry.npmjs.org' | |
- name: Install dependencies | |
run: | | |
npm install -g typescript | |
curl -sSL https://install.python-poetry.org | python3 - --version 1.2.2 | |
- name: Docker login | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB}} | |
- name: Build and publish | |
run: | | |
BUMP_LEVEL=${{ github.event.inputs.bump_level }} | |
echo "bump level: ${BUMP_LEVEL}" | |
# Version bump | |
cd typescript | |
# Install npm package | |
npm ci | |
NEW_VERSION=$(npm version "${BUMP_LEVEL}" | sed "s/^v//") | |
git config --local user.email "Bumpversion" | |
git config --local user.name "Bumpversion" | |
git add package.json package-lock.json | |
echo "new version: ${NEW_VERSION}" | |
npx tsc | |
cd ../aws-lambda | |
poetry version "${NEW_VERSION}" | |
poetry update | |
git add pyproject.toml poetry.lock | |
git commit -m "Bump version to ${NEW_VERSION}" | |
git tag "v${NEW_VERSION}" | |
# Docker build | |
docker build -t "${{ env.IMAGE_NAME }}:dev" . | |
docker tag "${{ env.IMAGE_NAME }}:dev" "godatadriven/${{ env.IMAGE_NAME }}:dev" | |
docker tag "${{ env.IMAGE_NAME }}:dev" "godatadriven/${{ env.IMAGE_NAME }}:${NEW_VERSION}" | |
docker push "godatadriven/${{ env.IMAGE_NAME }}:dev" | |
docker push "godatadriven/${{ env.IMAGE_NAME }}:${NEW_VERSION}" | |
cd ../typescript | |
npm publish | |
cd ../ | |
git push | |
git push --tags | |
echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_ENV | |
- name: Create Release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token | |
with: | |
tag_name: v${{ env.NEW_VERSION }} | |
release_name: v${{ env.NEW_VERSION }} | |
body: | | |
npm package: https://www.npmjs.com/package/databricks-cdk/v/${{ env.NEW_VERSION }} | |
draft: false | |
prerelease: false |