Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

publish snapshot releases on every merge to main #438

Merged
merged 5 commits into from
Mar 15, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions .github/workflows/release-snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: release snapshot to jfrog

on:
push:
branches:
- main
workflow_dispatch:

# Allow only one concurrent deployment, but do NOT cancel in-progress runs as
# we want to allow these release deployments to complete.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

permissions:
contents: read
id-token: write

jobs:
publish-npm:
name: Snapshot Publish
runs-on: ubuntu-latest

strategy:
matrix:
package:
[
"agent",
"api",
"common",
"credentials",
"crypto",
"crypto-aws-kms",
"dids",
"identity-agent",
"proxy-agent",
"user-agent",
]

steps:
- name: Checkout source
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 #v4.1.1
with:
fetch-depth: 0
leordev marked this conversation as resolved.
Show resolved Hide resolved

# https://cashapp.github.io/hermit/usage/ci/
- name: Init Hermit
uses: cashapp/activate-hermit@v1
with:
cache: "true"

- uses: jfrog/setup-jfrog-cli@v4
Copy link
Contributor

@frankhinek frankhinek Mar 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the security tools added by OSP raise security issues as a result of unpinned actions, please use the hash and include a comment with which version it is.

Otherwise looks good to ✅ and merge

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops, thanks for catching that. Also pinned cashapp/activate-hermit above

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no worries. thanks! nice work @finn-tbd

with:
version: latest
oidc-provider-name: github # must match the OpenID Connect name from https://blockxyz.jfrog.io/ui/admin/configuration/integrations
env:
JF_URL: https://blockxyz.jfrog.io

- name: Publish @web5/${{ matrix.package }} snapshot
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
REGISTRY: https://blockxyz.jfrog.io/artifactory/api/npm/tbd-oss-snapshots-npm/
run: |
set -exuo pipefail

package_name="${{ matrix.package }}"
cd "packages/${package_name}"

base_version=$(jq -r .version package.json)

# I'm not seeing a great way to determine the commit of the last release of a given package, so I'm using a not-so-great way
version_line=$(grep -n "\"version\": \"${base_version}\"" package.json | cut -d: -f1) # determine which line in package.json specifies the version
version_bump_commit=$(git blame --porcelain -L "${version_line},${version_line}" -- package.json | head -n1 | awk '{ print $1 }') # ask git when the last commit to that line was
commits_since_version_bump=$(git rev-list HEAD ${version_bump_commit} --count -- .) # count the number of commits that changed this package since the version change commit
last_commit_to_package="$(git log -1 --pretty=format:%H -- .)"

snapshot_version="${base_version}-SNAPSHOT.${commits_since_version_bump}-${last_commit_to_package:0:7}"

# check if that snapshot version has already been published
if npm view --registry "${REGISTRY}" "@web5/${package_name}@${snapshot_version}" > /dev/null; then
echo "release for @web5/${package_name}-${snapshot_version} already exists, not re-publishing"
exit 0
fi

pushd ../..
pnpm install
pnpm build
popd

# set the snapshot version
jq --arg version "${snapshot_version}" '.version = $version' package.json > package-new.json
mv package-new.json package.json

# set publishing config in package.json
jq --arg registry "${REGISTRY}" '.publishConfig.registry = $registry' package.json > package-new.json
mv package-new.json package.json

# login to jfrog and publish
jf npm-config --global=true --repo-resolve=tbd-oss-snapshots-npm --repo-deploy=tbd-oss-snapshots-npm
jf npm publish --registry "${REGISTRY}"
shell: bash
Loading