From f80d0d8522d332ce704d68106526cf7fe789628b Mon Sep 17 00:00:00 2001 From: Connor Sullivan Date: Mon, 29 Jul 2024 21:08:20 -0400 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=9A=80=20Continuous=20deployment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sets up continuous deployment with GitVersion. Renames `ci` to `pipeline` to match the mental model. Update contributing docs. --- .github/workflows/{ci.yaml => pipeline.yaml} | 50 +++++++++++++++++++- CONTRIBUTING.md | 6 +-- GitVersion.yml | 2 + package.json | 2 +- 4 files changed, 54 insertions(+), 6 deletions(-) rename .github/workflows/{ci.yaml => pipeline.yaml} (57%) create mode 100644 GitVersion.yml diff --git a/.github/workflows/ci.yaml b/.github/workflows/pipeline.yaml similarity index 57% rename from .github/workflows/ci.yaml rename to .github/workflows/pipeline.yaml index 27eaa02..8d46c9a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/pipeline.yaml @@ -1,4 +1,4 @@ -name: CI +name: Pipeline on: push: @@ -10,9 +10,24 @@ jobs: Build: name: Build runs-on: ubuntu-latest + outputs: + GitVersion_SemVer: ${{ steps.GitVersion.outputs.GitVersion_SemVer }} steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 # Full depth (not shallow) for GitVersion and better relevancy of Sonar analysis + + - name: Set up GitVersion + uses: gittools/actions/gitversion/setup@v2.0.1 + with: + versionSpec: 6.x + + - name: Execute GitVersion + id: GitVersion + uses: gittools/actions/gitversion/execute@v2.0.1 + with: + useConfigFile: true - name: Use Node.js uses: actions/setup-node@v4 @@ -55,7 +70,7 @@ jobs: node-version: ${{ matrix.node }} - name: Install production - run: npm ci --include prod + run: npm i --include prod - name: Build production run: npm run build @@ -71,3 +86,34 @@ jobs: node dist/main.js "$RUNNER_TEMP/*.css" --dashes diff --strip-trailing-cr -uI '//.*' src/fixtures/kebab-case/kebab-case-dashes.d.css.ts "$RUNNER_TEMP/kebab-case.d.css.ts" + + Publish: + # if: ${{ github.ref == 'refs/heads/main' }} + name: Publish + needs: + - Build # For version variable + - Test # Requires passing tests + runs-on: ubuntu-latest + env: + GitVersion_SemVer: ${{needs.Build.outputs.GitVersion_SemVer}} + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + cache: npm + node-version-file: .node-version + registry-url: https://registry.npmjs.org + + - name: Set version + run: sed -i 's/0.0.0-gitversion/${{ env.GitVersion_SemVer }}/g' package.json + + - name: Install + run: npm i --include prod + + - name: Publish + run: npm publish --provenance --access public --dryrun + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 93504f3..3656338 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -30,9 +30,9 @@ All contributions MUST adhere to the following expectations. 1. Every change MUST have unit tests. 2. Every change MUST have a GitHub issue linked. -3. Any configuration option change MUST be discussed in a GitHub issue first. -4. I will squash-merge the changeset into `main` upon approval. -5. I will publish the new version upon approval (not yet automated). +3. Any configuration option change SHOULD be discussed in a GitHub issue first. +4. The PR build (see [pipeline.yaml](./.github/workflows/pipeline.yaml)) MUST succeed. +5. I will squash-merge the changeset into `main` upon approval. [RFC2119]: https://www.rfc-editor.org/rfc/rfc2119 [RFC8174]: https://www.rfc-editor.org/rfc/rfc8174 diff --git a/GitVersion.yml b/GitVersion.yml new file mode 100644 index 0000000..8dab3d1 --- /dev/null +++ b/GitVersion.yml @@ -0,0 +1,2 @@ +workflow: GitHubFlow/v1 +mode: ContinuousDeployment diff --git a/package.json b/package.json index ea533df..c44c1bc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "css-typed", - "version": "0.2.4", + "version": "0.0.0-gitversion", "description": "Basic TypeScript declaration generator for CSS files", "keywords": [ "CSS", From 244ad4b06542e368bd3834ea1dc9c60456e897dd Mon Sep 17 00:00:00 2001 From: Connor Sullivan Date: Mon, 29 Jul 2024 21:17:45 -0400 Subject: [PATCH 2/4] Changes following first PR round --- .github/workflows/pipeline.yaml | 11 ++++++----- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pipeline.yaml b/.github/workflows/pipeline.yaml index 8d46c9a..bbd0879 100644 --- a/.github/workflows/pipeline.yaml +++ b/.github/workflows/pipeline.yaml @@ -69,10 +69,10 @@ jobs: cache: npm node-version: ${{ matrix.node }} - - name: Install production - run: npm i --include prod + - name: Install + run: npm install --omit=dev - - name: Build production + - name: Build run: npm run build - name: Run css-typed (the test) @@ -97,7 +97,8 @@ jobs: env: GitVersion_SemVer: ${{needs.Build.outputs.GitVersion_SemVer}} permissions: - contents: write + contents: read + id-token: write steps: - uses: actions/checkout@v4 @@ -111,7 +112,7 @@ jobs: run: sed -i 's/0.0.0-gitversion/${{ env.GitVersion_SemVer }}/g' package.json - name: Install - run: npm i --include prod + run: npm install --omit=dev - name: Publish run: npm publish --provenance --access public --dryrun diff --git a/package-lock.json b/package-lock.json index db63614..f3d2af4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "css-typed", - "version": "0.2.3", + "version": "0.0.0-gitversion", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "css-typed", - "version": "0.2.3", + "version": "0.0.0-gitversion", "license": "MIT", "dependencies": { "css-tree": "^2.3.1", diff --git a/package.json b/package.json index c44c1bc..666cb1b 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "ci-build": "npm-run-all -l -p build eslint prettier test", "eslint": "eslint -f pretty .", "eslint:fix": "npm run eslint -- --fix", - "prepublishOnly": "npm run ci-build", + "prepublishOnly": "npm run build", "prettier": "prettier -c '**/*.{cjs,css,js,json,md,yaml,yml}'", "prettier:fix": "npm run prettier -- -w", "test": "vitest run" From b5b4b6ff668e5754c8aed9d30954c9c96d7239d8 Mon Sep 17 00:00:00 2001 From: Connor Sullivan Date: Mon, 29 Jul 2024 21:24:34 -0400 Subject: [PATCH 3/4] Publish with alpha tag (continue testing) --- .github/workflows/pipeline.yaml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pipeline.yaml b/.github/workflows/pipeline.yaml index bbd0879..f4ae7d2 100644 --- a/.github/workflows/pipeline.yaml +++ b/.github/workflows/pipeline.yaml @@ -92,12 +92,12 @@ jobs: name: Publish needs: - Build # For version variable - - Test # Requires passing tests + # - Test # Requires passing tests runs-on: ubuntu-latest env: GitVersion_SemVer: ${{needs.Build.outputs.GitVersion_SemVer}} permissions: - contents: read + contents: write id-token: write steps: - uses: actions/checkout@v4 @@ -109,12 +109,17 @@ jobs: registry-url: https://registry.npmjs.org - name: Set version - run: sed -i 's/0.0.0-gitversion/${{ env.GitVersion_SemVer }}/g' package.json + run: sed -i 's/0.0.0-gitversion/${{ env.GitVersion_SemVer }}-alpha.1/g' package.json - name: Install run: npm install --omit=dev - name: Publish - run: npm publish --provenance --access public --dryrun + run: npm publish --provenance --access public --tag alpha env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: git tag + run: | + git tag v${{ env.GitVersion_SemVer }}-alpha.1 + git push origin tag v${{ env.GitVersion_SemVer }}-alpha.1 From e9fe307c548353c6579e43f103389058c07ce134 Mon Sep 17 00:00:00 2001 From: Connor Sullivan Date: Mon, 29 Jul 2024 21:29:16 -0400 Subject: [PATCH 4/4] Ready for merge --- .github/workflows/pipeline.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pipeline.yaml b/.github/workflows/pipeline.yaml index f4ae7d2..ccb3d84 100644 --- a/.github/workflows/pipeline.yaml +++ b/.github/workflows/pipeline.yaml @@ -88,11 +88,11 @@ jobs: diff --strip-trailing-cr -uI '//.*' src/fixtures/kebab-case/kebab-case-dashes.d.css.ts "$RUNNER_TEMP/kebab-case.d.css.ts" Publish: - # if: ${{ github.ref == 'refs/heads/main' }} + if: ${{ github.ref == 'refs/heads/main' }} name: Publish needs: - Build # For version variable - # - Test # Requires passing tests + - Test # Requires passing tests runs-on: ubuntu-latest env: GitVersion_SemVer: ${{needs.Build.outputs.GitVersion_SemVer}} @@ -109,17 +109,17 @@ jobs: registry-url: https://registry.npmjs.org - name: Set version - run: sed -i 's/0.0.0-gitversion/${{ env.GitVersion_SemVer }}-alpha.1/g' package.json + run: sed -i 's/0.0.0-gitversion/${{ env.GitVersion_SemVer }}/g' package.json - name: Install run: npm install --omit=dev - name: Publish - run: npm publish --provenance --access public --tag alpha + run: npm publish --provenance --access public env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - name: git tag run: | - git tag v${{ env.GitVersion_SemVer }}-alpha.1 - git push origin tag v${{ env.GitVersion_SemVer }}-alpha.1 + git tag v${{ env.GitVersion_SemVer }} + git push origin tag v${{ env.GitVersion_SemVer }}