ci(changesets): versioning packages (#1832) #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "Release" | |
on: | |
push: | |
branches: | |
- master | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
env: | |
BUILD_VERSION: "" | |
jobs: | |
check-commit: | |
name: Decide if releases or create PR | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
pull-requests: read | |
outputs: | |
is_changeset_pr: ${{ steps.check-commit.outputs.is_changeset_pr }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- id: check-commit | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
# Store commit message in a variable and escape it | |
COMMIT_MSG=$(git log -1 --pretty=%B) | |
FIRST_LINE=$(echo "$COMMIT_MSG" | head -n1) | |
if [[ "$FIRST_LINE" == "ci(changesets): versioning packages"* ]]; then | |
PR_NUMBER=$(echo "$FIRST_LINE" | grep -o '#[0-9]\+' | head -n1 | tr -d '#') | |
if [ -n "$PR_NUMBER" ]; then | |
PR_TITLE=$(gh pr view "$PR_NUMBER" --json title -q .title) | |
if [[ "$PR_TITLE" == "ci(changesets): versioning packages"* ]]; then | |
echo "is_changeset_pr=true" >> "$GITHUB_OUTPUT" | |
exit 0 | |
fi | |
fi | |
fi | |
echo "is_changeset_pr=false" >> "$GITHUB_OUTPUT" | |
create-pr: | |
name: Push changes to Changeset PR | |
needs: check-commit | |
if: needs.check-commit.outputs.is_changeset_pr == 'false' | |
runs-on: buildjet-4vcpu-ubuntu-2204 | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
persist-credentials: false | |
- name: Extract pnpm version from .tool-versions | |
id: get_pnpm | |
run: | | |
PNPM_VERSION=$(grep '^pnpm' .tool-versions | awk '{print $2}') | |
echo "PNPM_VERSION=${PNPM_VERSION}" >> $GITHUB_ENV | |
- uses: FuelLabs/github-actions/setups/node@master | |
with: | |
node-version: 20.11.0 | |
pnpm-version: ${{ env.PNPM_VERSION }} | |
- name: Setup git user (for changelog step) | |
run: | | |
git config --global user.name "${{ github.actor }}" | |
git config --global user.email "${{ github.actor }}@users.noreply.github.com" | |
- name: Create Changeset PR | |
uses: changesets/action@v1 | |
with: | |
commit: "ci(changesets): versioning packages" | |
title: "ci(changesets): versioning packages" | |
createGithubReleases: false | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
publish-npm: | |
name: Release to NPM | |
needs: check-commit | |
if: needs.check-commit.outputs.is_changeset_pr == 'true' | |
runs-on: ubuntu-latest | |
environment: npm-deploy | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
persist-credentials: false | |
- name: Extract pnpm version from .tool-versions | |
id: get_pnpm | |
run: | | |
PNPM_VERSION=$(grep '^pnpm' .tool-versions | awk '{print $2}') | |
echo "PNPM_VERSION=${PNPM_VERSION}" >> $GITHUB_ENV | |
- uses: FuelLabs/github-actions/setups/node@master | |
with: | |
node-version: 20.11.0 | |
pnpm-version: ${{ env.PNPM_VERSION }} | |
- uses: FuelLabs/github-actions/setups/npm@master | |
with: | |
npm-token: ${{ secrets.NPM_TOKEN_WALLET }} | |
- name: Bump and Collect Version | |
run: | | |
pnpm changeset version | |
echo "BUILD_VERSION=$(pnpm -s packages:version)" >> $GITHUB_ENV | |
git reset --hard | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build packages | |
run: pnpm build:libs | |
- name: Publish to NPM | |
id: changesets | |
uses: FuelLabs/changesets-action@v2.0.0 | |
with: | |
publish: pnpm changeset publish --tag next | |
createGithubReleases: aggregate | |
version: pnpm changeset version | |
env: | |
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }} | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN_WALLET }} | |
- name: Build Fuel Wallet | |
if: steps.changesets.outputs.published == 'true' | |
run: pnpm build:crx | |
env: | |
## increase node.js m memory limit for building | |
## with sourcemaps | |
NODE_OPTIONS: "--max-old-space-size=4096" | |
- name: Build Fuel Wallet Development | |
if: steps.changesets.outputs.published == 'true' | |
run: pnpm build:crx | |
env: | |
VITE_CRX_RELEASE: false | |
VITE_CRX_NAME: "Fuel Wallet Development" | |
CRX_OUT: "dist-crx-dev" | |
APP_VERSION_POSTFIX: "-development" | |
NODE_OPTIONS: "--max-old-space-size=4096" | |
- name: Upload Production artifacts to Sentry | |
if: steps.changesets.outputs.published == 'true' | |
run: | | |
pnpm sentry-cli sourcemaps inject --release ${{ env.BUILD_VERSION }} ./dist-crx | |
pnpm sentry-cli sourcemaps upload --release ${{ env.BUILD_VERSION }} ./dist-crx | |
env: | |
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} | |
SENTRY_ORG: ${{ vars.SENTRY_ORG }} | |
SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }} | |
working-directory: ./packages/app | |
- name: Upload Development artifacts to Sentry | |
if: steps.changesets.outputs.published == 'true' | |
run: | | |
pnpm sentry-cli sourcemaps inject --release ${{ env.BUILD_VERSION }} ./dist-crx-dev | |
pnpm sentry-cli sourcemaps upload --release ${{ env.BUILD_VERSION }} ./dist-crx-dev | |
env: | |
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} | |
SENTRY_ORG: ${{ vars.SENTRY_ORG }} | |
SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }} | |
working-directory: ./packages/app | |
- name: Attach Fuel Wallet to release | |
if: steps.changesets.outputs.published == 'true' | |
uses: softprops/action-gh-release@v1 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
tag_name: v${{ env.BUILD_VERSION }} | |
files: | | |
./packages/app/dist/*.zip |