|
| 1 | +name: Release |
| 2 | +concurrency: |
| 3 | + group: ${{ github.ref }} |
| 4 | + cancel-in-progress: true |
| 5 | + |
| 6 | +permissions: |
| 7 | + contents: write |
| 8 | + issues: write |
| 9 | + pull-requests: write |
| 10 | + |
| 11 | +on: |
| 12 | + push: |
| 13 | + branches: |
| 14 | + - release |
| 15 | + |
| 16 | +jobs: |
| 17 | + release: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + timeout-minutes: 30 |
| 20 | + defaults: |
| 21 | + run: |
| 22 | + shell: bash |
| 23 | + |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v3 |
| 26 | + with: |
| 27 | + fetch-depth: 0 |
| 28 | + ref: ${{ inputs.git-ref }} |
| 29 | + |
| 30 | + - name: Setup GIT |
| 31 | + run: | |
| 32 | + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" |
| 33 | + git config user.name "$GITHUB_ACTOR" |
| 34 | +
|
| 35 | + - name: Setup Node.js |
| 36 | + uses: actions/setup-node@v3 |
| 37 | + with: |
| 38 | + node-version: 18 |
| 39 | + cache: "npm" |
| 40 | + cache-dependency-path: "package-lock.json" |
| 41 | + registry-url: 'https://registry.npmjs.org' |
| 42 | + |
| 43 | + - name: Install dependencies |
| 44 | + env: |
| 45 | + CI: true |
| 46 | + run: | |
| 47 | + npm ci |
| 48 | +
|
| 49 | + - name: Get workspaces |
| 50 | + id: get-workspaces |
| 51 | + run: | |
| 52 | + echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT |
| 53 | + echo "commit=${{ github.sha }}" >> $GITHUB_OUTPUT |
| 54 | + ws=$(npm ls --omit=dev --depth 1 -json | jq -r '.dependencies[].resolved[11:]') |
| 55 | + echo 'ws<<EOF' >> $GITHUB_OUTPUT |
| 56 | + echo $ws >> $GITHUB_OUTPUT |
| 57 | + echo 'EOF' >> $GITHUB_OUTPUT |
| 58 | +
|
| 59 | + - name: Build workspaces |
| 60 | + env: |
| 61 | + CI: true |
| 62 | + run: | |
| 63 | + npm run build -ws |
| 64 | +
|
| 65 | + - name: Release workspaces |
| 66 | + if: steps.get-workspaces.outputs.ws != '' |
| 67 | + env: |
| 68 | + CI: true |
| 69 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 70 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 71 | + run: | |
| 72 | + topdir=$(pwd) |
| 73 | + for workspace in ${{ steps.get-workspaces.outputs.ws }}; do |
| 74 | + if [ "$workspace" = "packages/azure-functions-openapi-validator-example" ]; then |
| 75 | + echo "Skipping release for $workspace" |
| 76 | + continue |
| 77 | + fi |
| 78 | +
|
| 79 | + echo "Potentially going to version and release $workspace" |
| 80 | + cd $workspace |
| 81 | + mkdir .git |
| 82 | +
|
| 83 | + PCKG_NAME=`node -pe "require('./package.json').name"` |
| 84 | + CUR_VERSION_NO=`node -pe "require('./package.json').version"` |
| 85 | +
|
| 86 | + FROM_PARAM="" |
| 87 | + if [ "$CUR_VERSION_NO" != "0.0.0" ]; then |
| 88 | + FROM_PARAM="--from ${PCKG_NAME}_v${CUR_VERSION_NO}" |
| 89 | + fi |
| 90 | +
|
| 91 | + VERSION=`npx auto version $FROM_PARAM` |
| 92 | + if [ ! -z "$VERSION" ]; then |
| 93 | + echo "::notice title=✅ Detected $VERSION version change for $PCKG_NAME::Bumping version" |
| 94 | + npx auto changelog --base-branch ${{ steps.get-workspaces.outputs.branch }} $FROM_PARAM |
| 95 | + npm version $VERSION -m "chore: bump release version to %s [skip ci]" |
| 96 | + NEW_VERSION_NO=`node -pe "require('./package.json').version"` |
| 97 | + git tag -d v$NEW_VERSION_NO |
| 98 | + NEW_TAG=${PCKG_NAME}_v$NEW_VERSION_NO |
| 99 | + echo "Going to create a new release for $NEW_TAG" |
| 100 | + git add -A |
| 101 | + git commit -m "chore: release v$NEW_VERSION_NO [skip ci]" |
| 102 | + git tag -a $NEW_TAG -m "chore: tag v$NEW_VERSION_NO [skip ci]" |
| 103 | + git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY" HEAD:${{ steps.get-workspaces.outputs.branch }} --follow-tags |
| 104 | + npx auto release --use-version $NEW_TAG $FROM_PARAM --base-branch ${{ steps.get-workspaces.outputs.branch }} |
| 105 | + IS_PRIVATE=`node -pe "require('./package.json').private"` |
| 106 | + if [ "$IS_PRIVATE" != "true" ]; then |
| 107 | + npm publish ./dist |
| 108 | + echo "::notice title=🚀 ${PCKG_NAME} v$NEW_VERSION_NO::Package versioned and published" |
| 109 | + fi |
| 110 | + rm -rf .git |
| 111 | + else |
| 112 | + echo "::notice title=Versioning of $PCKG_NAME skipped::No relevant changes detected." |
| 113 | + fi |
| 114 | +
|
| 115 | + cd $topdir |
| 116 | + done |
| 117 | +
|
| 118 | + - if: ${{ always() }} |
| 119 | + name: Clean working directory |
| 120 | + run: | |
| 121 | + rm -r * |
0 commit comments