From a6d224b12a0f930671383f0ce1c69fd6a42a6624 Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Fri, 3 May 2024 22:58:14 +0200 Subject: [PATCH] combined release and deploy action, reuse build action --- .github/workflows/build.yml | 32 ++-------- .github/workflows/release-from-tag.yml | 18 ------ .github/workflows/release-package.yml | 36 ------------ .github/workflows/release.yml | 81 ++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 82 deletions(-) delete mode 100644 .github/workflows/release-from-tag.yml delete mode 100644 .github/workflows/release-package.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f387b22..97616c9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,33 +14,9 @@ on: jobs: build: runs-on: ubuntu-latest - env: - SONARCLOUD_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }} steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - - name: Read properties from package.json - id: package_json - uses: zoexx/github-action-json-file-properties@1.0.6 - with: - file_path: package.json - - - uses: actions/setup-node@v4 - with: - node-version: 20 - cache: npm - - - run: npm ci - - run: npm run lint - - run: npm run test:coverage - - run: npm run build - - uses: SonarSource/sonarcloud-github-action@master - if: env.SONARCLOUD_TOKEN != null - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ env.SONARCLOUD_TOKEN }} - with: - args: -Dsonar.projectVersion=${{steps.package_json.outputs.version}} + - uses: brdgm/github-action-build@v1 + with: + sonar-token: ${{ secrets.SONARCLOUD_TOKEN }} + github-token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/release-from-tag.yml b/.github/workflows/release-from-tag.yml deleted file mode 100644 index 105be5e..0000000 --- a/.github/workflows/release-from-tag.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: Release from Tag - -on: - push: - tags: - - '*' - workflow_dispatch: - -jobs: - build: - runs-on: ubuntu-latest - permissions: - contents: write - steps: - - uses: actions/checkout@v4 - - uses: ncipollo/release-action@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release-package.yml b/.github/workflows/release-package.yml deleted file mode 100644 index 06a5d61..0000000 --- a/.github/workflows/release-package.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: Node.js Package - -on: - push: - tags: - - '*' - workflow_dispatch: - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: 20 - - run: npm ci - - run: npm run lint - - run: npm run test:coverage - - run: npm run build - - publish-npm-registry: - needs: build - runs-on: ubuntu-latest - permissions: - id-token: write - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: 20 - registry-url: https://registry.npmjs.org - - run: npm ci - - run: npm publish --provenance --access public - env: - NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..c5c315a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,81 @@ +name: Release and Deploy + +on: + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: npm + + - run: npm ci + - run: npm run lint + - run: npm run test:unit + - run: npm run build + + publish-npm-registry: + needs: build + runs-on: ubuntu-latest + permissions: + id-token: write + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: npm + registry-url: https://registry.npmjs.org + + - name: Read properties from package.json + id: package_json + uses: zoexx/github-action-json-file-properties@1.0.6 + with: + file_path: package.json + + - name: set git config + run: | + git config user.name "GitHub Actions" + git config user.email noreply@github.com + shell: bash + + - name: Install git flow extensions + run: | + sudo apt-get install git-flow + shell: bash + + - run: git flow init --defaults + shell: bash + + - run: git flow release start ${{ steps.package_json.outputs.version }} + shell: bash + + - run: git flow release finish ${{ steps.package_json.outputs.version }} --push --message "Release" + shell: bash + + - run: npm ci + - run: npm publish --provenance --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: set next version + run: | + npm --no-git-tag-version version patch + git config user.name "GitHub Actions" + git config user.email noreply@github.com + git add package.json package-lock.json + git commit --message "set next version" + git push + shell: bash + + - uses: ncipollo/release-action@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + tag: ${{ steps.package_json.outputs.version }} + generateReleaseNotes: true