From 0c89d70613f1cf5ed53bb4ea260606f0c732a39f Mon Sep 17 00:00:00 2001 From: Emma Hamilton Date: Fri, 31 Jan 2025 16:12:15 +1000 Subject: [PATCH] Publishing workflow updates --- .github/actions/setup-deps/action.yml | 17 ++++++++++ .github/workflows/main.yml | 33 ++----------------- .github/workflows/publish.yml | 36 +++++++++++++++++++++ .github/workflows/publish_snapshot.yml | 45 ++++++++++++++++++++++++++ .github/workflows/release.yml | 29 ++++++----------- package.json | 3 +- 6 files changed, 111 insertions(+), 52 deletions(-) create mode 100644 .github/actions/setup-deps/action.yml create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/publish_snapshot.yml diff --git a/.github/actions/setup-deps/action.yml b/.github/actions/setup-deps/action.yml new file mode 100644 index 0000000..bfc0f8a --- /dev/null +++ b/.github/actions/setup-deps/action.yml @@ -0,0 +1,17 @@ +name: "Setup Dependencies" +runs: + using: "composite" + steps: + - run: corepack enable pnpm + shell: bash + + - name: Setup Node.js LTS + uses: actions/setup-node@v4 + with: + node-version: lts/* + registry-url: "https://registry.npmjs.org" + cache: pnpm + + - name: Install Dependencies + run: pnpm install + shell: bash diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5d22a47..8db747d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,16 +13,7 @@ jobs: steps: - uses: actions/checkout@main - - name: Set Node.js 22.x - uses: actions/setup-node@main - with: - node-version: 22.x - - - name: Install pnpm - run: corepack enable pnpm - - - name: Install Dependencies - run: pnpm i + - uses: ./.github/actions/setup-deps - name: Check Types run: pnpm run types @@ -32,16 +23,7 @@ jobs: steps: - uses: actions/checkout@main - - name: Set Node.js 22.x - uses: actions/setup-node@main - with: - node-version: 22.x - - - name: Install pnpm - run: corepack enable pnpm - - - name: Install Dependencies - run: pnpm i + - uses: ./.github/actions/setup-deps - name: Linting run: pnpm run lint @@ -51,16 +33,7 @@ jobs: steps: - uses: actions/checkout@main - - name: Set Node.js 22.x - uses: actions/setup-node@main - with: - node-version: 22.x - - - name: Install pnpm - run: corepack enable pnpm - - - name: Install Dependencies - run: pnpm i + - uses: ./.github/actions/setup-deps - name: Tests run: pnpm run test diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..9c40458 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,36 @@ +name: Publish + +on: + workflow_dispatch: + +permissions: + contents: write + id-token: write + +jobs: + publish: + name: Publish + runs-on: ubuntu-latest + environment: release + steps: + - uses: actions/checkout@main + with: + fetch-depth: 0 + persist-credentials: true # needed for git push + + - uses: ./.github/actions/setup-deps + + - run: pnpm build + + - name: git config + run: | + git config --global user.name 'Thinkmill Release Bot' + git config --global user.email 'automation+github@thinkmill.com.au' + + - name: npm publish, git tag + run: pnpm changeset publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + NPM_CONFIG_PROVENANCE: true + + - run: git push origin --follow-tags diff --git a/.github/workflows/publish_snapshot.yml b/.github/workflows/publish_snapshot.yml new file mode 100644 index 0000000..c99146b --- /dev/null +++ b/.github/workflows/publish_snapshot.yml @@ -0,0 +1,45 @@ +name: Publish (Snapshot) + +on: + workflow_dispatch: + +permissions: + contents: write + id-token: write + +jobs: + publish_snapshot: + name: Publish (Snapshot) + runs-on: ubuntu-latest + environment: release + steps: + - uses: actions/checkout@main + with: + persist-credentials: true # needed for git push + + - uses: ./.github/actions/setup-deps + + - name: version packages + run: pnpm changeset version --snapshot ${{ inputs.tag }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: git commit + run: | + git config --global user.name 'Thinkmill Release Bot' + git config --global user.email 'automation+github@thinkmill.com.au' + git commit -a -m 'snapshot release' + + - run: pnpm build + + - name: npm publish, git tag + run: pnpm changeset publish --tag test + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + NPM_CONFIG_PROVENANCE: true + + # reset, then push the dangling commit + - name: git push + run: | + git reset HEAD~1 --hard + git push origin --tags diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c0b1ab7..f488037 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,36 +1,25 @@ -name: Release +name: Version Packages on: push: branches: - main + workflow_dispatch: jobs: - release: - name: Release + versioning: + name: Pull Request runs-on: ubuntu-latest steps: - - name: Checkout Repo - uses: actions/checkout@main + - uses: actions/checkout@main with: fetch-depth: 0 + persist-credentials: false - - name: Set Node.js 22.x - uses: actions/setup-node@main - with: - node-version: 22.x - - - name: Install pnpm - run: corepack enable pnpm - - - name: Install Dependencies - run: pnpm i + - uses: ./.github/actions/setup-deps - - name: "Create Pull Request or Publish to npm" - uses: changesets/action@master + - uses: changesets/action@v1 with: - publish: pnpm run release - version: pnpm run version + version: pnpm run version-packages env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/package.json b/package.json index 0ddd222..a2910d5 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,7 @@ }, "scripts": { "postinstall": "preconstruct dev && manypkg check", - "release": "preconstruct build && changeset publish", - "version": "changeset version && pnpm i --frozen-lockfile=false", + "version-packages": "changeset version && pnpm i --frozen-lockfile=false", "test": "jest", "types": "tsc", "lint": "eslint .",