Skip to content

feat: GCPConnect

feat: GCPConnect #294

Workflow file for this run

name: Publish release-candidate npm package
on:
pull_request:
types: [opened, reopened, synchronize]
jobs:
publish_rc:
if: contains(github.event.pull_request.labels.*.name, 'release-candidate')
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18.18.0'
registry-url: 'https://registry.npmjs.org'
- name: Get package name and current version from package.json
id: get_package_info
run: |
PACKAGE_NAME=$(jq -r .name < package.json)
PACKAGE_VERSION=$(jq -r .version < package.json)
echo "::set-output name=package_name::$PACKAGE_NAME"
echo "::set-output name=current_version::$PACKAGE_VERSION"
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
- name: Build package
run: npm run build
- name: Ensure no untracked changes after build
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "Untracked changes found after build"
exit 1
else
echo "No untracked changes"
fi
- name: Set Git config
run: |
git config --local user.email "[email protected]"
git config --local user.name "Github Actions"
- name: Check and update release version
id: prepare_and_publish
run: |
set -e # Exit immediately if a command exits with a non-zero status
# Check for matching rc versions
matching_rc_versions=$(npm view ${{ steps.get_package_info.outputs.package_name }} versions --json | jq -c 'map(select(. | contains("'"${{ steps.get_package_info.outputs.current_version }}"'-rc")))')
echo "$matching_rc_versions"
if [ "$(echo "$matching_rc_versions" | jq 'type')" == '"array"' ] && [ "$(echo "$matching_rc_versions" | jq 'length')" -gt 0 ]; then
latest_rc_version=$(echo "$matching_rc_versions" | jq -r '.[-1]')
echo "Catching version up to latest rc: $latest_rc_version"
npm version "$latest_rc_version" --allow-same-version
echo "Iterating over version: $latest_rc_version"
npm version prerelease --preid=rc
else
echo "No matching rc versions found. Initializing version ${{ steps.get_package_info.outputs.current_version }}-rc.0"
npm version "${{ steps.get_package_info.outputs.current_version }}-rc.0"
fi
NEW_PACKAGE_VERSION=$(node -p "require('./package.json').version")
echo "Ready to publish: $NEW_PACKAGE_VERSION"
echo "::set-output name=publishing_rc_version::$NEW_PACKAGE_VERSION"
- name: Publish to npm
run: npm publish --tag rc
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
- name: Create comment
uses: peter-evans/create-or-update-comment@8da4c50e7142257262c9df90da4e74a59068c038
with:
token: ${{ secrets.GH_CQ_BOT }}
issue-number: ${{ github.event.pull_request.number }}
body: |
### Published rc version:
${{steps.prepare_and_publish.outputs.publishing_rc_version}}