From 0bc29cf58bf4dba405e2d0e11c20da18640bb11a Mon Sep 17 00:00:00 2001 From: Jorge del Casar <948953+jorgecasar@users.noreply.github.com> Date: Thu, 18 Jan 2024 13:18:52 +0100 Subject: [PATCH] ci: fix CI/CD and simplify workflows --- .github/workflows/npm-pr-review.yml | 20 ------- .github/workflows/npm-pr.yml | 31 ---------- .../{npm-release.yml => release.yml} | 10 +++- .github/workflows/update-wiki.yml | 58 ------------------- .github/workflows/verify.yml | 54 +++++++++++++++++ .npmrc | 3 - 6 files changed, 62 insertions(+), 114 deletions(-) delete mode 100644 .github/workflows/npm-pr-review.yml delete mode 100644 .github/workflows/npm-pr.yml rename .github/workflows/{npm-release.yml => release.yml} (84%) delete mode 100644 .github/workflows/update-wiki.yml create mode 100644 .github/workflows/verify.yml delete mode 100644 .npmrc diff --git a/.github/workflows/npm-pr-review.yml b/.github/workflows/npm-pr-review.yml deleted file mode 100644 index da31ebf..0000000 --- a/.github/workflows/npm-pr-review.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Pull Request Approved - -on: - pull_request_review: - types: [submitted] - -concurrency: pr-${{ github.event.pull_request.id }} - -jobs: - check-labels: - runs-on: ubuntu-latest - if: github.event.pull_request.mergeable == true && github.event.review.state == 'approved' - steps: - - name: Warn about missing labels - if: ${{ !contains(github.event.pull_request.labels.*.name, 'release') && !contains(github.event.pull_request.labels.*.name, 'documentation') }} - uses: thollander/actions-comment-pull-request@v1 - with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - message: "This pull request hasn't been labeled as `release` nor `documentation`. Please ensure this is intentional before merging." - comment_tag: label-warn diff --git a/.github/workflows/npm-pr.yml b/.github/workflows/npm-pr.yml deleted file mode 100644 index efb07e4..0000000 --- a/.github/workflows/npm-pr.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: NodeJS CI with NPM (PR) - -on: - pull_request: - types: [opened, synchronize, ready_for_review, review_requested, labeled] - -concurrency: pr-${{ github.event.pull_request.id }} - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 16 - - run: npm clean-install - - run: npm run lint - - run: npm test - - check-labels: - runs-on: ubuntu-latest - if: github.event.pull_request.mergeable == true - steps: - - name: Warn about missing labels - if: ${{ !contains(github.event.pull_request.labels.*.name, 'release') && !contains(github.event.pull_request.labels.*.name, 'documentation') }} - uses: thollander/actions-comment-pull-request@v2 - with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - message: "This pull request hasn't been labeled as `release` nor `documentation`. Please ensure this is intentional before merging." - comment_tag: label-warn diff --git a/.github/workflows/npm-release.yml b/.github/workflows/release.yml similarity index 84% rename from .github/workflows/npm-release.yml rename to .github/workflows/release.yml index 922e006..1337bf6 100644 --- a/.github/workflows/npm-release.yml +++ b/.github/workflows/release.yml @@ -21,16 +21,22 @@ jobs: with: fetch-depth: 0 persist-credentials: false + - name: Setup Node.js uses: actions/setup-node@v3 with: node-version: 'lts/*' + registry-url: 'https://registry.npmjs.org' + cache: 'npm' + - name: Install dependencies - run: npm clean-install + run: npm clean-install --ignore-scripts + - name: Verify the integrity of provenance attestations and registry signatures for installed dependencies run: npm audit signatures + - name: Release env: GITHUB_TOKEN: ${{ secrets.SNGULARBOT_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} run: npm run release diff --git a/.github/workflows/update-wiki.yml b/.github/workflows/update-wiki.yml deleted file mode 100644 index 022b76a..0000000 --- a/.github/workflows/update-wiki.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: Sync Docs (Merge) - -on: - push: - branches: [main] - -jobs: - check-pr-labels: - runs-on: ubuntu-latest - permissions: - pull-requests: read - outputs: - labels: ${{ steps.get-pr.outputs.pr_labels }} - steps: - - name: Get Pull Request information - uses: 8BitJonny/gh-get-current-pr@2.2.0 - id: get-pr - - update-wiki: - runs-on: ubuntu-latest - needs: [check-pr-labels] - if: contains(needs.check-pr-labels.outputs.labels, 'documentation') - steps: - - name: Setup variables - run: | - echo "REPO_DEST=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}').wiki" >> $GITHUB_ENV - shell: bash - - name: Checkout OpenApi NodeJS CLI Repository - run: git clone https://github.com/sngular/openapi-nodejs-cli.git openapi-nodejs-cli - - name: Checkout OpenApi NodeJS CLI Wiki Repository - run: git clone https://github.com/sngular/openapi-nodejs-cli.wiki.git wiki - - name: Copy docs and consolidate links - run: | - cp -rf openapi-nodejs-cli/docs/* wiki/ - cd wiki - grep -lr "(.*\.md)" *|xargs -r sed -i 's/\.md//g' - echo ">" - git diff-index --quiet HEAD & git status -s - echo "<" - git status - echo ">" - git diff-index --quiet HEAD & git status -s - echo "<" - echo "TO_BE_CANCELLED=$(if [[ $(git diff-index --quiet HEAD & git status -s) ]]; then echo "false"; else echo "true"; fi)" >> $GITHUB_ENV - echo "$TO_BE_CANCELLED" - - name: Setup git user - if: ${{ env.TO_BE_CANCELLED == 'false' }} - run: | - git config --global user.name ${{ github.actor }} - - name: Sync Wiki - if: ${{ env.TO_BE_CANCELLED == 'false' }} - run: | - cd wiki - git status - git add . - git commit -m "openapi-nodejs-cli documentation | GitHub Actions $GITHUB_WORKFLOW $GITHUB_RUN_NUMBER" - git remote add origin-wiki "https://${{secrets.GITBOT_TOKEN}}@github.com/sngular/openapi-nodejs-cli.wiki.git" - git push origin-wiki main diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml new file mode 100644 index 0000000..ffa1b83 --- /dev/null +++ b/.github/workflows/verify.yml @@ -0,0 +1,54 @@ +name: Verify changes + +on: pull_request + +permissions: + contents: read # for checkout + +jobs: + verify: + name: Verify changes + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + persist-credentials: false + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 'lts/*' + registry-url: 'https://registry.npmjs.org' + + - name: Install Dependencies + run: npm install --ci + + - name: Lint + run: npm run lint + tests: + name: Tests + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [18, 20, 'latest'] + os: [ubuntu-latest, macos-latest, windows-latest] + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + registry-url: 'https://registry.npmjs.org' + cache: 'npm' + + - name: Install Dependencies + run: npm install --ci + + - name: Test + run: npm run test diff --git a/.npmrc b/.npmrc deleted file mode 100644 index 5f0fc3f..0000000 --- a/.npmrc +++ /dev/null @@ -1,3 +0,0 @@ -//registry.npmjs.org/:_authToken=${NPM_TOKEN} -registry=https://registry.npmjs.org/ -always-auth=true