From c47a3301cc162b4913462cabda4f76841f836953 Mon Sep 17 00:00:00 2001 From: Ollie Curtis <8831547+olliecurtis@users.noreply.github.com> Date: Mon, 24 Jul 2023 11:52:24 +0100 Subject: [PATCH] Adding automation to release s-c-s (#291) --- .github/release-drafter.yml | 29 ++++++++++++ .github/workflows/_test.yml | 36 +++++++++++++++ .github/workflows/ci.yml | 33 -------------- .github/workflows/label-check.yml | 15 +++++++ .github/workflows/main.yml | 57 ++++++++++++++++++++++++ .github/workflows/pr.yml | 46 +++++++++++++++++++ .github/workflows/release.yml | 74 +++++++++++++++++++++++++++++++ 7 files changed, 257 insertions(+), 33 deletions(-) create mode 100644 .github/release-drafter.yml create mode 100644 .github/workflows/_test.yml delete mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/label-check.yml create mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/pr.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 0000000..45a16bb --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,29 @@ +name-template: '$RESOLVED_VERSION' +tag-template: '$RESOLVED_VERSION' +categories: + - title: 'Breaking' + label: 'major' + - title: 'Added' + label: 'minor' + - title: 'Fixed' + label: 'patch' + - title: 'Dependency updates' + label: 'dependencies' +exclude-labels: + - 'skip-changelog' + - 'github_actions' +version-resolver: + major: + labels: + - 'major' + minor: + labels: + - 'minor' + patch: + labels: + - 'patch' + - 'dependencies' + default: patch +template: | + ## What’s Changed + $CHANGES diff --git a/.github/workflows/_test.yml b/.github/workflows/_test.yml new file mode 100644 index 0000000..6f66478 --- /dev/null +++ b/.github/workflows/_test.yml @@ -0,0 +1,36 @@ +name: Test + +on: + workflow_call: + +defaults: + run: + shell: bash -l {0} + +env: + CACHE_NAME: node-modules-cache + +jobs: + Test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: actions/setup-node@v3 + with: + node-version-file: '.nvmrc' + registry-url: 'https://registry.npmjs.org' + + - name: Restore Cache + uses: actions/cache/restore@v3.3.1 + id: npm-cache + with: + path: | + node_modules/ + key: ${{ env.CACHE_NAME }}-${{ hashFiles('package-lock.json') }} + + - name: Run linters + run: npm run lint + + - name: Test + run: npm test \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index a9798d2..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Stylelint Config Skyscanner CI - -on: - push: - branches: [main] - pull_request: - branches: [main] - -defaults: - run: - shell: bash -l {0} - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Set the correct npm version - run: nvm install && nvm use - - - name: Install dependencies from npm - run: | - nvm use - npm ci - - - name: Run linters - run: npm run lint - - - name: Test - run: | - nvm use - npm test diff --git a/.github/workflows/label-check.yml b/.github/workflows/label-check.yml new file mode 100644 index 0000000..a1af912 --- /dev/null +++ b/.github/workflows/label-check.yml @@ -0,0 +1,15 @@ +name: label-check + +on: + pull_request_target: + types: [opened, labeled, unlabeled, synchronize] + +jobs: + label-check: + runs-on: ubuntu-latest + + steps: + - uses: docker://agilepathway/pull-request-label-checker:latest + with: + one_of: major,minor,patch,dependencies,skip-changelog + repo_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..b755cc0 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,57 @@ +name: Main + +on: + push: + branches: [main] + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +defaults: + run: + shell: bash -l {0} + +env: + CACHE_NAME: node-modules-cache + +jobs: + Create-NPM-Cache: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + node-version-file: '.nvmrc' + registry-url: 'https://registry.npmjs.org' + + - name: Upload to Cache + uses: actions/cache@v3.3.1 + id: npm-cache + with: + path: | + node_modules/ + key: ${{ env.CACHE_NAME }}-${{ hashFiles('package-lock.json') }} + + - name: Install dependencies + if: ${{ steps.npm-cache.outputs.cache-hit != 'true' }} + run: npm ci + + Run-Tests: + permissions: + statuses: write + pull-requests: write + needs: [Create-NPM-Cache] + uses: ./.github/workflows/_test.yml + + ReleaseDraft: + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: read + steps: + - name: Draft release notes + uses: release-drafter/release-drafter@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 0000000..ae76db2 --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,46 @@ +name: PR + +on: + pull_request: + branches: [main] + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +defaults: + run: + shell: bash -l {0} + +env: + CACHE_NAME: node-modules-cache + +jobs: + Create-NPM-Cache: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + node-version-file: '.nvmrc' + registry-url: 'https://registry.npmjs.org' + + - name: Upload to Cache + uses: actions/cache@v3.3.1 + id: npm-cache + with: + path: | + node_modules/ + key: ${{ env.CACHE_NAME }}-${{ hashFiles('package-lock.json') }} + + - name: Install dependencies + if: ${{ steps.npm-cache.outputs.cache-hit != 'true' }} + run: npm ci + + Run-Tests: + permissions: + statuses: write + pull-requests: write + needs: [Create-NPM-Cache] + uses: ./.github/workflows/_test.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..164de08 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,74 @@ +name: release + +on: + release: + types: [published] + +defaults: + run: + shell: bash -l {0} + +env: + CACHE_NAME: node-modules-cache + +jobs: + Create-NPM-Cache: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + node-version-file: '.nvmrc' + registry-url: 'https://registry.npmjs.org' + + - name: Upload to Cache + uses: actions/cache@v3.3.1 + id: npm-cache + with: + path: | + node_modules/ + key: ${{ env.CACHE_NAME }}-${{ hashFiles('package-lock.json') }} + + - name: Install dependencies + if: ${{ steps.npm-cache.outputs.cache-hit != 'true' }} + run: npm ci + + Run-Tests: + permissions: + statuses: write + pull-requests: write + needs: [Create-NPM-Cache] + uses: ./.github/workflows/_test.yml + + Release: + name: Release @skyscanner/eslint-config-skyscanner to NPM + runs-on: ubuntu-latest + environment: Publishing + needs: [Create-NPM-Cache, Run-Tests] + steps: + - name: Checkout source code + uses: actions/checkout@v3 + with: + ref: main + + - uses: actions/setup-node@v3 + with: + node-version-file: '.nvmrc' + registry-url: 'https://registry.npmjs.org' + + - name: Restore Cache + uses: actions/cache/restore@v3.3.1 + id: npm-cache + with: + path: | + node_modules/ + key: ${{ env.CACHE_NAME }}-${{ hashFiles('package-lock.json') }} + + - name: Publish NPM package + run: | + npm version $RELEASE_VERSION --no-git-tag-version + npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + RELEASE_VERSION: ${{ github.event.release.tag_name }}