Skip to content

Commit

Permalink
chore: improved release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
lquixada committed Jul 2, 2023
1 parent cc2663b commit 098ed1e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
13 changes: 3 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,16 @@ jobs:
needs: [checks, security]
steps:
- uses: actions/checkout@v3
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v3
with:
node-version: '10'
# Setup .npmrc file to publish to npm
registry-url: 'https://registry.npmjs.org'
- uses: actions/cache@v3
with:
# This is cache where npm installs from before going out to the network
path: ~/.npm
path: ~/.npm # this is cache where npm installs from before going out to the network
key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}
- run: npm install --prefer-offline
- if: ${{ !contains(github.ref_name, '-test.') }}
run: npm publish --tag latest-v3.x
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# If "test" prerelease is present, pretend to publish package.
- if: ${{ contains(github.ref_name, '-test.') }}
run: npm publish --tag latest-v3.x --dry-run
- run: ./release
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
29 changes: 29 additions & 0 deletions release
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash -xv

# Removes "v" prefix
version=${GITHUB_REF_NAME:1}

# Major of the version being handled by the current workflow
workflow_major=$(echo $version | cut -d. -f1)

workflow_track="latest-v${workflow_major}.x"

# Major of the version published under the current "latest" npm tag
latest_major=$(npm view cross-fetch@latest version | cut -d. -f1)


# If it's test prerelease, we just want to test the release workflow (dry run it!)
if [[ "$version" == *"-test."* ]]; then
npm publish --tag $workflow_track --dry-run && \
exit 0
fi

npm publish --tag $workflow_track

if [[ "$workflow_major" == "$latest_major" ]]; then
npm dist-tag add cross-fetch@$version latest
fi

if [[ "$workflow_major" == "$(($latest_major + 1))" ]]; then
npm dist-tag add cross-fetch@$version next
fi

0 comments on commit 098ed1e

Please sign in to comment.