v5.0.0-alpha.1 #34
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: publish-to-npm | |
on: | |
release: | |
types: [released] | |
# Support manual releases in case something goes wrong, or we need to do a test. | |
workflow_dispatch: | |
inputs: | |
tag: | |
description: Tag to be published | |
type: string | |
required: true | |
jobs: | |
# Step 1: Verify that the tag we're trying to release is a valid candidate for publishing. | |
verify-candidate-tag: | |
runs-on: ubuntu-latest | |
steps: | |
# Check out the main-5 branch, and get its head commit as output for later. | |
- uses: actions/checkout@v4 | |
with: | |
ref: 'main-5' | |
- run: echo "COMMIT_ID=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT | |
id: get-branch-commit | |
# Checkout the tag we want to release, and get its head commit as output for later. | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.release.tag_name || inputs.tag }} | |
- run: echo "COMMIT_ID=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT | |
id: get-tag-commit | |
# If the two commits aren't identical, the tag isn't eligible for release. | |
- name: Fail non-matching commits | |
if: ${{ steps.get-branch-commit.outputs.COMMIT_ID != steps.get-tag-commit.outputs.COMMIT_ID }} | |
run: | | |
echo "Tag commit must match latest commit in main-5. Branch is ${{ steps.get-branch-commit.outputs.COMMIT_ID }}. Tag is ${{ steps.get-tag-commit.outputs.COMMIT_ID }}" | |
exit 1 | |
# Verify that the `package.json`'s version property is 5.Y.Z, as we want to restrict the `dev-5` and `main-5` | |
# branches to publishing v5.x. | |
- name: Verify major version | |
run: | | |
MAJOR_VERSION=`cat package.json | jq '.version | split(".") | .[0]' | xargs` | |
[[ ${MAJOR_VERSION} == 5 ]] || (echo "package.json version must be 5.x" && exit 1) | |
# Verify that the tag is of the format "vX.Y.Z", where the X, Y, and Z exactly match the corresponding values in | |
# `package.json`'s version property. | |
- name: Compare tag to package.json | |
run: | | |
TAG=${{ github.event.release.tag_name || inputs.tag }} | |
PACKAGE_VERSION=v`cat package.json | jq '.version' | xargs` | |
[[ ${TAG} == ${PACKAGE_VERSION} ]] || (echo "Tag name must match package.json version, prefixed by lowercase v" && exit 1) | |
# Step 2: Publish the tag as a release candidate. | |
publish-rc: | |
needs: verify-candidate-tag | |
uses: salesforcecli/github-workflows/.github/workflows/npmPublish.yml@main | |
with: | |
ctc: false # We've been told we don't have to care about this until someone makes us care. | |
sign: true | |
tag: latest-alpha-rc # Publish as a release candidate, so we can do our validations against it. | |
githubTag: ${{ github.event.release.tag_name || inputs.tag }} | |
secrets: inherit | |
# Step 3: Run smoke tests against the release candidate. | |
rc-test: | |
needs: publish-rc | |
strategy: | |
# By default, if any job in a matrix fails, all other jobs are immediately cancelled. This option makes the jobs | |
# run to completion instead. | |
fail-fast: false | |
matrix: | |
os: [{vm: ubuntu-latest, exe: .sh}, {vm: macos-latest, exe: .sh}, {vm: windows-2019, exe: .cmd}] | |
runs-on: ${{ matrix.os.vm }} | |
steps: | |
# We need to checkout the tag to get the smoke tests | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.release.tag_name || inputs.tag }} | |
# We need Node LTS and Java v11 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 'lts/*' | |
- uses: actions/setup-java@v4 | |
with: | |
distribution: 'temurin' | |
java-version: '11' # For now, Java version is hardcoded. | |
# Install SF, and the release candidate version. | |
- run: npm install -g @salesforce/cli | |
- run: sf plugins install @salesforce/plugin-code-analyzer@latest-alpha-rc | |
# Log the installed plugins for easier debugging. | |
- run: sf plugins | |
# Attempt to run the smoke tests. | |
- run: smoke-tests/smoke-test${{ matrix.os.exe }} sf | |
# Upload the smoke test result as an artifact, so it's visible for later. | |
- uses: actions/upload-artifact@v4 | |
if: ${{ always() }} | |
with: | |
name: ${{ runner.os }}-smoke-test-results | |
path: smoke-test-results | |
# Step 4: Promote the release candidate to latest. | |
promote-to-latest: | |
needs: rc-test | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 'lts/*' | |
- run: | | |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc | |
npm dist-tag add @salesforce/plugin-code-analyzer@${{ github.event.release.tag_name || inputs.tag }} latest-alpha | |
# Step 5: Create a Pull Request for merging `main-5` into `dev-5` | |
create-main2dev-pull-request: | |
needs: promote-to-latest | |
runs-on: macos-latest | |
env: | |
GH_TOKEN: ${{ secrets.SVC_CLI_BOT_GITHUB_TOKEN }} | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
# Check out `main-5` | |
- uses: actions/checkout@v4 | |
with: | |
ref: 'main-5' | |
# Create a new branch based on `main-5`, so that merge conflicts can be manually resolved if need be. | |
- run: | | |
NEW_VERSION=$(jq -r ".version" package.json) | |
git checkout -b m2d/v$NEW_VERSION | |
git push --set-upstream origin m2d/v$NEW_VERSION | |
# Create a Pull Request from the new branch into `dev-5`. | |
- run: | | |
NEW_VERSION=$(jq -r ".version" package.json) | |
# For whatever reason, the version of 'echo' on GHAs doesn't process backspace by default. | |
# The non-POSIX-standard -e flag causes it to do that. | |
echo -e "This branch and PR were automatically created following the successful release of v$NEW_VERSION.\n\ | |
It must be MERGED into dev-5, NOT SQUASHED OR REBASED. Squashing or rebasing this branch onto dev-5 can cause potentially irreconcilable merge conflicts later.\n\ | |
As an additional safeguard and reminder, the title of this PR MUST include the word 'merging' in the description portion of the PR title, e.g., 'Main2Dev @W-XXXXXXX@ Merging main-5 to dev-5 after vX.Y.Z'.\n\ | |
If there are conflicts between dev-5 and this branch, you should do the following locally:\n\ | |
- $ git checkout dev-5\n\ | |
- $ git pull\n\ | |
- $ git fetch --all\n\ | |
- $ git checkout m2d/v$NEW_VERSION\n\ | |
- $ git pull origin dev-5 --no-rebase # You MUST include this flag, or someone's day will be ruined.\n\ | |
- Resolve the merge conflicts manually. When in doubt, ask the code's author for help.\n\ | |
- $ git commit\n\ | |
- $ git push" > body.txt | |
# Create the pull request. | |
gh pr create -B dev-5 -H m2d/v$NEW_VERSION --title "Filler title. Read description and rename." -F body.txt |