diff --git a/.github/workflows/nrc-job-apply-version.yml b/.github/workflows/nrc-job-apply-version.yml new file mode 100644 index 0000000..8dac101 --- /dev/null +++ b/.github/workflows/nrc-job-apply-version.yml @@ -0,0 +1,57 @@ +on: + workflow_call: + inputs: + isRelease: + description: flag a release invocation + type: boolean + default: false + version: + description: version to apply to package.json files + type: string + required: true +jobs: + apply-version: + runs-on: ubuntu-latest + steps: + - id: checkout + name: checkout project + uses: actions/checkout@v3 + + - id: installNode + name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: 18.x + cache: 'npm' + + # generate changelog if its a release + - id: generateReleaseChangelog + name: create release changelog + if: ${{ inputs.isRelease }} + run: echo "generate change log" + + # apply version to package.json files and create a git tag + - id: applyVersion + name: apply version to package.json files + env: + VERSION: ${{ inputs.version }} + IS_RELEASE: ${{ inputs.isRelease }} + run: | + export RELEASE_COMMENT="" + + if [ "$IS_RELEASE" == "true" ]; then + RELEASE_COMMENT="release" + fi + + npm version -m "apply $RELEASE_COMMENT version $VERSION" + + # create release PR + - id: createReleasePR + name: create release PR + if: ${{ inputs.isRelease }} + run: echo "create release PR" + + + + + \ No newline at end of file diff --git a/.github/workflows/nrc-job-publish.yml b/.github/workflows/nrc-job-publish.yml deleted file mode 100644 index 37a3bfb..0000000 --- a/.github/workflows/nrc-job-publish.yml +++ /dev/null @@ -1,27 +0,0 @@ -on: - workflow_call: - inputs: - version: - description: version used to publish to NPM registry - required: true - type: string -jobs: - build-test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Use Node.js - uses: actions/setup-node@v3 - with: - node-version: 18.x - cache: 'npm' - # clean install - - run: npm ci - # build - - run: npm run build --if-present - # test - - run: npm publish - # tag release - - - diff --git a/.github/workflows/nrc-job-release.yml b/.github/workflows/nrc-job-release.yml new file mode 100644 index 0000000..e63b80c --- /dev/null +++ b/.github/workflows/nrc-job-release.yml @@ -0,0 +1,47 @@ +on: + workflow_call: +jobs: + release: + runs-on: ubuntu-latest + if: ${{ github.repository == 'aacerox/node-rest-client' }} + steps: + # checkout repo + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + fetch-tags: true + # read latest tag + - id: readLatestTag + name: read latest tag + run: echo "latestTag=$(git describe --tags --abbrev=0)" >> "$GITHUB_OUTPUT" + # setup node.js + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 18.x + cache: 'npm' + # install repo dependencies + - id: cleanInstallRepo + name: clean install repo + run: npm ci + # run changeset action + # - when push from normal PR: the 'version' command is executed. A new release branch and PR + # is created if it doesn't exists and if it does exists the commit is added to release branch + # + # - when push from release PR: the 'publish' command is executed and artifact are published to npm + - id: changesetPR + name: Changeset release + uses: changesets/action@v1 + env: + NRC_RELEASE_MSG: "node-rest-client release ${{ steps.readLatestTag.outputs.latestTag }}" + GITHUB_TOKEN: ${{ secrets.NRC_GITHUB_TOKEN }} + with: + version: npm run version:packages + publish: npm run publish:packages + commit: "chore(release): ${{ env.NRC_RELEASE_MSG }}" + title: "${{ env.NRC_RELEASE_MSG }}" + + + + + diff --git a/.github/workflows/nrc-workflow-ci.yml b/.github/workflows/nrc-workflow-ci.yml index 04151d3..f3851e9 100644 --- a/.github/workflows/nrc-workflow-ci.yml +++ b/.github/workflows/nrc-workflow-ci.yml @@ -1,23 +1,22 @@ name: Node-Rest-Client CI on: push: - branches: - - feat/general-upgrade + branches: - master - - release + - 'release/**' +# just one workflow active, for the same branch +concurrency: ${{ github.workflow }}-${{ github.ref }} + jobs: - build-test: + # test + test: uses: ./.github/workflows/nrc-job-build-test.yml - generate-version: - uses: ./.github/workflows/nrc-job-generate-version.yml - needs: build-test - print-version: - runs-on: ubuntu-latest - needs: generate-version - steps: - - run: echo "version used is $VERSION" - env: - VERSION: ${{ needs.generate-version.outputs.version }} + + # changeset release + release: + uses: ./.github/workflows/nrc-job-release.yml + + diff --git a/.github/workflows/nrc-workflow-release.yml b/.github/workflows/nrc-workflow-release.yml deleted file mode 100644 index 8153d22..0000000 --- a/.github/workflows/nrc-workflow-release.yml +++ /dev/null @@ -1,57 +0,0 @@ -name: Node-Rest-Client Release -on: - push: - branches: - - feat/general-upgrade - workflow_dispatch: -jobs: - create-release-branch: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - fetch-tags: true - - - - # - id: # - # name: configure git - # run: | - # # setup the username and email. I tend to use 'GitHub Actions Bot' with no email by default - # git --version - # git config user.name "GitHub Actions Bot" - # git config user.email "<>" - # git status - # git tag - # git describe - - - id: readLatestTag - name: read latest tag - run: echo "latestTag=$(git describe --tags --abbrev=0)" >> "$GITHUB_OUTPUT" - - - id: createReleaseBranch - name: create release branch - env: - RELEASE_TAG: ${{ steps.readLatestTag.outputs.latestTag }} - run: | - export BRANCH_NAME="release/$RELEASE_TAG" - git checkout -b $BRANCH_NAME - git push --set-upstream origin release/$RELEASE_TAG - - - id: cleanInstallRepo - name: clean install repo - run: npm ci - - - id: changesetPR - name: Create Release Pull Request - uses: changesets/action@v1 - env: - NRC_RELEASE_MSG: "node-rest-client release ${{ steps.readLatestTag.outputs.latestTag }}" - GITHUB_TOKEN: ${{ secrets.NRC_GITHUB_TOKEN }} - with: - version: npm run version:packages - commit: "chore(release): ${{ env.NRC_RELEASE_MSG }}" - title: "${{ env.NRC_RELEASE_MSG }}" - - \ No newline at end of file