|
| 1 | +name: Continuous Deployment |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +concurrency: ${{ github.workflow }}-${{ github.ref }} |
| 9 | + |
| 10 | +jobs: |
| 11 | + release-stable: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + name: Release Stable |
| 14 | + outputs: |
| 15 | + published: ${{ steps.changesets.outputs.published }} |
| 16 | + steps: |
| 17 | + - name: Checkout Repo |
| 18 | + uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Setup NodeJS |
| 21 | + uses: actions/setup-node@v4 |
| 22 | + with: |
| 23 | + node-version: 20 |
| 24 | + cache: 'yarn' |
| 25 | + |
| 26 | + - name: Install Dependencies |
| 27 | + run: yarn install --frozen-lockfile |
| 28 | + |
| 29 | + - name: Create Release Pull Request or Publish to npm |
| 30 | + id: changesets |
| 31 | + uses: changesets/action@v1 |
| 32 | + with: |
| 33 | + title: 'chore(release): new version' |
| 34 | + commit: 'chore(release): new version' |
| 35 | + publish: yarn release |
| 36 | + version: yarn changeset-version |
| 37 | + env: |
| 38 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 39 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 40 | + |
| 41 | + - name: Get current package version |
| 42 | + id: get_version |
| 43 | + run: echo "CURRENT_PACKAGE_VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV |
| 44 | + |
| 45 | + - name: Create Github Release |
| 46 | + if: steps.changesets.outputs.published == 'true' |
| 47 | + uses: softprops/action-gh-release@v2 |
| 48 | + with: |
| 49 | + tag_name: v${{ env.CURRENT_PACKAGE_VERSION }} |
| 50 | + |
| 51 | + release-unstable: |
| 52 | + runs-on: ubuntu-latest |
| 53 | + name: Release Unstable |
| 54 | + needs: release-stable |
| 55 | + if: always() && github.event_name == 'push' && needs.release-stable.outputs.published == 'false' |
| 56 | + steps: |
| 57 | + - name: Checkout Repo |
| 58 | + uses: actions/checkout@v4 |
| 59 | + |
| 60 | + - name: Setup NodeJS |
| 61 | + uses: actions/setup-node@v4 |
| 62 | + with: |
| 63 | + node-version: 20 |
| 64 | + cache: 'yarn' |
| 65 | + |
| 66 | + - name: Install Dependencies |
| 67 | + run: yarn install --frozen-lockfile |
| 68 | + |
| 69 | + - name: Creating .npmrc |
| 70 | + run: | |
| 71 | + cat << EOF > ".npmrc" |
| 72 | + //registry.npmjs.org/:_authToken=$NPM_TOKEN |
| 73 | + EOF |
| 74 | + env: |
| 75 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 76 | + |
| 77 | + - name: Create unstable release |
| 78 | + env: |
| 79 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 80 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 81 | + run: | |
| 82 | + # this ensures there's always a patch release created |
| 83 | + cat << 'EOF' > .changeset/snapshot-template-changeset.md |
| 84 | + --- |
| 85 | + '@ayanworks/credo-ethr-module': patch |
| 86 | + --- |
| 87 | +
|
| 88 | + snapshot release |
| 89 | + EOF |
| 90 | +
|
| 91 | + yarn changeset version --snapshot alpha |
| 92 | + yarn style:fix |
| 93 | + yarn build |
| 94 | + yarn changeset publish --tag alpha |
| 95 | +
|
| 96 | + CURRENT_PACKAGE_VERSION=$(node -p "require('./package.json').version") |
| 97 | + git config --global user.name "Ayanworks" |
| 98 | + git config --global user.email "[email protected]" |
| 99 | + git tag v$CURRENT_PACKAGE_VERSION |
| 100 | + git push origin v$CURRENT_PACKAGE_VERSION --no-verify |
0 commit comments