Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
82 changes: 39 additions & 43 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
name: Publish

on:
push:
branches: [main]
release:
types: [published]

concurrency:
group: publish-${{ github.event.release.tag_name }}
group: publish-${{ github.event_name }}-${{ github.event_name == 'release' && github.event.release.tag_name || github.sha }}
cancel-in-progress: false

permissions:
Expand All @@ -15,13 +17,14 @@ env:
CARGO_TERM_COLOR: always

jobs:
verify-release:
verify-source:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.release.tag_name }}
ref: ${{ github.event_name == 'release' && github.event.release.tag_name || github.sha }}
- name: Verify release version
if: github.event_name == 'release'
run: |
tag="${{ github.event.release.tag_name }}"
package_version=$(node -p "require('./package.json').version")
Expand All @@ -32,12 +35,12 @@ jobs:
fi

build-wasm:
needs: verify-release
needs: verify-source
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.release.tag_name }}
ref: ${{ github.event_name == 'release' && github.event.release.tag_name || github.sha }}
- name: Use Node.js
uses: actions/setup-node@v6
with:
Expand All @@ -59,7 +62,7 @@ jobs:
reed-solomon/pkg/

build-native:
needs: verify-release
needs: verify-source
strategy:
fail-fast: false
matrix:
Expand All @@ -77,7 +80,7 @@ jobs:
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.release.tag_name }}
ref: ${{ github.event_name == 'release' && github.event.release.tag_name || github.sha }}
- name: Use Node.js
uses: actions/setup-node@v6
with:
Expand All @@ -96,15 +99,15 @@ jobs:
if-no-files-found: error

publish:
needs: [verify-release, build-wasm, build-native]
needs: [verify-source, build-wasm, build-native]
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.release.tag_name }}
ref: ${{ github.event_name == 'release' && github.event.release.tag_name || github.sha }}
- name: Use Node.js
uses: actions/setup-node@v6
with:
Expand Down Expand Up @@ -135,55 +138,48 @@ jobs:
- name: Build native library bundle
run: npm run build

- id: vars
- name: Get short commit SHA
if: github.event_name == 'push'
id: vars
run: echo "short_sha=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"

- name: Update versions
- name: Append commit SHA to snapshot versions
if: github.event_name == 'push'
env:
SHORT_SHA: ${{ steps.vars.outputs.short_sha }}
run: |
cat <<'EOF' > update_versions.cjs
node <<'EOF'
const fs = require('fs');
const shortSha = '${{ steps.vars.outputs.short_sha }}';

// Update dist package version
const shortSha = process.env.SHORT_SHA;

const distPkg = JSON.parse(fs.readFileSync('dist/package.json'));
const baseVersion = distPkg.version.split('-')[0];
const newVersion = `${baseVersion}-${shortSha}`;
distPkg.version = newVersion;
const baseVersion = distPkg.version;
const snapshotVersion = `${baseVersion}-${shortSha}`;
distPkg.version = snapshotVersion;

if (distPkg.optionalDependencies && typeof distPkg.optionalDependencies === 'object') {
for (const [dep, version] of Object.entries(distPkg.optionalDependencies)) {
if (typeof version === 'string' && (version === baseVersion || version.startsWith(baseVersion))) {
distPkg.optionalDependencies[dep] = newVersion;
if (version === baseVersion) {
distPkg.optionalDependencies[dep] = snapshotVersion;
}
}
}
fs.writeFileSync('dist/package.json', JSON.stringify(distPkg, null, 2));

// Update native platform packages
const packages = [
fs.writeFileSync('dist/package.json', `${JSON.stringify(distPkg, null, 2)}\n`);

for (const pkgPath of [
'bandersnatch/npm/darwin-arm64/package.json',
'bandersnatch/npm/linux-x64-gnu/package.json'
];

for (const pkgPath of packages) {
if (fs.existsSync(pkgPath)) {
const pkg = JSON.parse(fs.readFileSync(pkgPath));
// reuse baseVersion from distPkg assuming they are synced
const pkgNewVersion = `${pkg.version.split('-')[0]}-${shortSha}`;
pkg.version = pkgNewVersion;
if (pkg.optionalDependencies && typeof pkg.optionalDependencies === 'object') {
for (const [dep, version] of Object.entries(pkg.optionalDependencies)) {
if (typeof version === 'string' && (version === baseVersion || version.startsWith(baseVersion))) {
pkg.optionalDependencies[dep] = pkgNewVersion;
}
}
}
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
]) {
const pkg = JSON.parse(fs.readFileSync(pkgPath));
if (pkg.version !== baseVersion) {
throw new Error(
`${pkgPath} version ${pkg.version} does not match ${baseVersion}`,
);
}
pkg.version = snapshotVersion;
fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
}
EOF

node update_versions.cjs

- name: Publish platform packages
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,5 @@ jobs:
echo
echo "1. Merge \`release/v${{ steps.version.outputs.version }}\`."
echo "2. The merge will create a draft \`v${{ steps.version.outputs.version }}\` release."
echo "3. Publish the draft release to publish npm version \`${{ steps.version.outputs.version }}-<short-sha>\`."
echo "3. Publish the draft release to publish npm version \`${{ steps.version.outputs.version }}\`."
} >> "$GITHUB_STEP_SUMMARY"