From 6c225eb77c1ea5e3dcb325f1414db89d2b5e273c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Etienne=20B=C3=B6mcke?= Date: Mon, 5 Jun 2023 10:48:38 +0200 Subject: [PATCH] ci: improve version handling in cd pipeline - automatically bump the version before publishing to npm - split release & pre-release pipelines to make them simpler to maintain --- .github/workflows/pre-release.yml | 39 +++++++++++++++++++++++++++++++ .github/workflows/release.yml | 28 ++++++++++------------ 2 files changed, 51 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/pre-release.yml diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml new file mode 100644 index 000000000..489b008c9 --- /dev/null +++ b/.github/workflows/pre-release.yml @@ -0,0 +1,39 @@ +name: Publish pre-release package + +on: + push: + branches: + - "release/*" + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: '18' + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: yarn install + run: yarn + + - name: Compile Typescript + run: yarn build + + - name: Setup .yarnrc.yml + run: | + yarn config set npmAlwaysAuth true + yarn config set npmAuthToken $NPM_AUTH_TOKEN + env: + NPM_AUTH_TOKEN: ${{ secrets.NPM_AWELL_EXTENSIONS_CI }} + + - name: Publish to NPM Registry + run: | + pkg_version=$(cat package.json | jq -r '.version') + yarn version "$pkg_version-beta$GITHUB_RUN_NUMBER" + yarn npm publish --tag beta --access public diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c6bc57a2e..5dd8d4bf4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,13 +4,9 @@ on: push: branches: - "main" - - "release/*" jobs: deploy: - permissions: - packages: write - contents: read runs-on: ubuntu-latest steps: - name: Checkout repository @@ -19,7 +15,7 @@ jobs: - name: Install Node.js uses: actions/setup-node@v3 with: - node-version: '18' + node-version: "18" env: NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -28,7 +24,7 @@ jobs: - name: Compile Typescript run: yarn build - + - name: Run tests run: yarn test @@ -41,15 +37,8 @@ jobs: - name: Publish to NPM Registry run: | - pkg_version=$(cat package.json | jq -r '.version') - branch=${GITHUB_REF##*/} - - if [[ $branch != "main" ]]; then - yarn version "$pkg_version-beta$GITHUB_RUN_NUMBER" - yarn npm publish --tag beta --access public - else - yarn npm publish --access public - fi + yarn version -i patch + yarn npm publish --access public - name: Redeploy the extension server run: | CURRENT_VERSION=$(cat package.json | jq -r '.version') @@ -60,4 +49,11 @@ jobs: -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/awell-health/awell-extension-server/actions/workflows/update-dependency.yml/dispatches \ -d '{"ref":"main","inputs":{"dependency":"@awell-health/awell-extensions","version":"'"$CURRENT_VERSION"'"}}' - \ No newline at end of file + + - name: Commit and push updated version + run: | + git config --global user.name "Awell CI" + git config --global user.email "ci@awellhealth.com" + git add package.json .yarn/versions + git commit -m "ci: bump version" + git push