|
| 1 | +name: Manual Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + bump: |
| 7 | + description: 'Version bump type (used if release_version is empty)' |
| 8 | + type: choice |
| 9 | + options: |
| 10 | + - major |
| 11 | + - minor |
| 12 | + - patch |
| 13 | + - prerelease |
| 14 | + required: false |
| 15 | + release_version: |
| 16 | + description: 'Semver version to release (must be > current root version)' |
| 17 | + required: false |
| 18 | + |
| 19 | +permissions: |
| 20 | + contents: write |
| 21 | + pull-requests: write |
| 22 | + id-token: write |
| 23 | + packages: write |
| 24 | + |
| 25 | +jobs: |
| 26 | + release: |
| 27 | + # Allow only on master, spring*, summer*, winter*; |
| 28 | + if: ${{ github.repository_owner == 'salesforce' && (github.ref_name == 'master' || startsWith(github.ref_name, 'spring') || startsWith(github.ref_name, 'summer') || startsWith(github.ref_name, 'winter')) }} |
| 29 | + environment: release |
| 30 | + runs-on: ubuntu-latest |
| 31 | + steps: |
| 32 | + - name: Checkout |
| 33 | + uses: actions/checkout@v4 |
| 34 | + with: |
| 35 | + fetch-depth: 0 |
| 36 | + token: ${{ secrets.WORKFLOW_PAT }} |
| 37 | + persist-credentials: true |
| 38 | + |
| 39 | + - name: Setup Node |
| 40 | + uses: actions/setup-node@v4 |
| 41 | + with: |
| 42 | + node-version: '20' |
| 43 | + registry-url: 'https://registry.npmjs.org' |
| 44 | + cache: 'yarn' |
| 45 | + |
| 46 | + - name: Install dependencies |
| 47 | + run: yarn install --frozen-lockfile |
| 48 | + |
| 49 | + - name: Resolve version input |
| 50 | + id: resolve_version |
| 51 | + run: | |
| 52 | + RELEASE_VERSION='${{ inputs.release_version }}' |
| 53 | + if [ -z "$RELEASE_VERSION" ]; then |
| 54 | + RELEASE_VERSION='${{ inputs.bump }}' |
| 55 | + fi |
| 56 | + echo "resolved=$RELEASE_VERSION" >> "$GITHUB_OUTPUT" |
| 57 | +
|
| 58 | + - name: Resolve version |
| 59 | + env: |
| 60 | + INPUT_VERSION: ${{ steps.resolve_version.outputs.resolved }} |
| 61 | + run: | |
| 62 | + node ./scripts/release/version.js "$INPUT_VERSION" |
| 63 | + RESOLVED_VERSION=$(jq -r .version package.json) |
| 64 | + echo "RESOLVED_VERSION=$RESOLVED_VERSION" >> "$GITHUB_ENV" |
| 65 | +
|
| 66 | + - name: Set git identity (Actions bot) |
| 67 | + run: | |
| 68 | + git config user.name "github-actions[bot]" |
| 69 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 70 | +
|
| 71 | + - name: Commit & push |
| 72 | + uses: actions-js/[email protected] |
| 73 | + with: |
| 74 | + github_token: ${{ secrets.WORKFLOW_PAT }} |
| 75 | + branch: ${{ github.ref_name }} |
| 76 | + message: 'chore: release v${{ env.RESOLVED_VERSION }}' |
| 77 | + |
| 78 | + - name: Build |
| 79 | + run: yarn build |
| 80 | + |
| 81 | + - name: Tag and create GitHub release |
| 82 | + env: |
| 83 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 84 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 85 | + run: | |
| 86 | + VERSION=$(jq -r .version package.json) |
| 87 | + git tag -a "v$VERSION" -m "Release v$VERSION" |
| 88 | + git push origin tag "v$VERSION" |
| 89 | + gh release create "v$VERSION" --title "v$VERSION" --generate-notes |
| 90 | +
|
| 91 | + - name: Publish to npm |
| 92 | + env: |
| 93 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 94 | + NPM_CONFIG_ALWAYS_AUTH: 'true' |
| 95 | + run: | |
| 96 | + # Force both npm and yarn to use npmjs and pick up the token |
| 97 | + yarn config set registry https://registry.npmjs.org |
| 98 | + npm config set registry https://registry.npmjs.org |
| 99 | + printf "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}\nalways-auth=true\n" > ~/.npmrc |
| 100 | +
|
| 101 | + # Sanity checks |
| 102 | + echo "yarn registry: $(yarn config get registry)" |
| 103 | + echo "npm registry: $(npm config get registry)" |
| 104 | +
|
| 105 | + TAG=$([ "$GITHUB_REF_NAME" = "master" ] && echo latest || echo "$GITHUB_REF_NAME") |
| 106 | + yarn nx release publish --yes --tag "$TAG" |
0 commit comments