Skip to content

Commit

Permalink
Merge pull request #14 from connec/lockfile-format
Browse files Browse the repository at this point in the history
fix: Use toml-patch to minimise Cargo.lock diffs
  • Loading branch information
dirvine authored Jun 29, 2021
2 parents 8a5bd76 + f74dc7c commit 464ba84
Show file tree
Hide file tree
Showing 33 changed files with 2,487 additions and 2,870 deletions.
18 changes: 10 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const core = require('@actions/core');
const exec = require('@actions/exec');
const github = require('@actions/github');
const standardVersion = require('standard-version');
const toml = require('@iarna/toml')
const toml = require('toml-patch')
const fs = require('fs');

const bump = async () => {
Expand Down Expand Up @@ -64,14 +64,15 @@ const bump = async () => {
core.debug(`Commit message added was: ${commit_message}`);

// parse and update cargo.toml
const manifest = toml.parse(fs.readFileSync('Cargo.toml', 'utf8'));
const manifestToml = fs.readFileSync('Cargo.toml', 'utf8');
const manifest = toml.parse(manifestToml);
manifest.package.version = cargo_version;
fs.writeFileSync('Cargo.toml', toml.stringify(manifest));
fs.writeFileSync('Cargo.toml', toml.patch(manifestToml, manifest));

// parse and update Cargo.lock (if present)
let lockfile;
let lockfileToml;
try {
lockfile = toml.parse(fs.readFileSync('Cargo.lock', 'utf8'));
lockfileToml = fs.readFileSync('Cargo.lock', 'utf8');
} catch (error) {
if (error.code === 'ENOENT') {
core.debug('No Cargo.lock to update');
Expand All @@ -80,11 +81,12 @@ const bump = async () => {
}
}

if (lockfile != null) {
if (lockfileToml != null) {
const lockfile = toml.parse(lockfileToml);
const crate = lockfile.package.find(p => p.name === manifest.package.name);
if (crate != null) {
crate.version = cargo_version;
fs.writeFileSync('Cargo.lock', toml.stringify(lockfile));
fs.writeFileSync('Cargo.lock', toml.patch(lockfileToml, lockfile));
} else {
core.warn(`Self crate (${manifest.package.name}) not present in lockfile packages`);
}
Expand Down Expand Up @@ -142,4 +144,4 @@ const bump = async () => {
}


bump()
bump()
12 changes: 5 additions & 7 deletions node_modules/.yarn-integrity

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

278 changes: 0 additions & 278 deletions node_modules/@iarna/toml/CHANGELOG.md

This file was deleted.

14 changes: 0 additions & 14 deletions node_modules/@iarna/toml/LICENSE

This file was deleted.

Loading

0 comments on commit 464ba84

Please sign in to comment.