Skip to content

Commit b7a948d

Browse files
authored
feat(automation): add action to tag and push packages (#136)
1 parent 429a815 commit b7a948d

File tree

2 files changed

+86
-11
lines changed

2 files changed

+86
-11
lines changed

.github/workflows/tag.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Tag Packages
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
env:
10+
BUN_VERSION: 1.1.43
11+
CARGO_TERM_COLOR: always
12+
RUST_BINARY_NAME: tangram
13+
RUST_REPO: tangramdotdev/tangram
14+
RUST_REV: 57c9cd4f999f381c9e03e8ff2ba807b22c0d72b2
15+
16+
jobs:
17+
tag-and-push:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Check out workflow repository
22+
uses: actions/checkout@v4
23+
24+
- name: Check out Rust repository
25+
uses: actions/checkout@v4
26+
with:
27+
repository: ${{ env.RUST_REPO }}
28+
path: tangram
29+
ref: ${{ env.RUST_REV }}
30+
31+
- name: Install Rust toolchain
32+
uses: dtolnay/rust-toolchain@stable
33+
with:
34+
components: rustfmt, clippy
35+
36+
- name: Install Bun
37+
uses: oven-sh/setup-bun@v1
38+
with:
39+
bun-version: ${{ env.BUN_VERSION }}
40+
41+
- name: Cache Rust dependencies
42+
uses: actions/cache@v3
43+
with:
44+
path: |
45+
~/.cargo/registry
46+
~/.cargo/git
47+
tangram/target
48+
key: ${{ runner.os }}-cargo-${{ hashFiles('tangram/**/Cargo.lock') }}
49+
restore-keys: |
50+
${{ runner.os }}-cargo-
51+
52+
- name: Build Tangram
53+
working-directory: tangram
54+
run: cargo build --verbose --release
55+
56+
- name: Copy Tangram to path
57+
run: |
58+
mkdir -p ./bin
59+
cp ./tangram/target/release/${{ env.RUST_BINARY_NAME }} ./bin/
60+
echo "./bin" >> $GITHUB_PATH
61+
62+
- name: Tag and push all packages
63+
shell: bash
64+
run: |
65+
bun run auto -p
66+

scripts/package_automation.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ const checkAction = async (tangram: string, path: string): Promise<Result> => {
405405
/** Perform the `publish` action for a package name. If the existing tag is out of date, tag and push the new package. */
406406
const publishAction = async (tangram: string, name: string, path: string): Promise<Result> => {
407407
log("publishing...");
408+
408409
// Check in the package, store the ID.
409410
const packageIdResult = await checkinPackage(tangram, path);
410411
if (packageIdResult.kind !== "ok") {
@@ -415,19 +416,27 @@ const publishAction = async (tangram: string, name: string, path: string): Promi
415416
return result("checkinError", `no ID for ${path}`);
416417
}
417418

418-
log(`tagging ${name}...`);
419-
const tagResult = await tagPackage(tangram, name, path);
420-
if (tagResult.kind !== "ok") {
421-
return tagResult;
422-
}
419+
// Check if the tag already matches this ID.
420+
let existing = await existingTaggedItem(tangram, name);
423421

424-
// Push the tag.
425-
const pushTagResult = await push(tangram, name);
426-
if (pushTagResult.kind !== "ok") {
427-
return pushTagResult;
428-
}
422+
if (packageId === existing) {
423+
log(`Existing tag for ${name} matches current ID:`, existing);
424+
return ok(`${name} unchanged, no action taken.`);
425+
} else {
426+
log(`tagging ${name}...`);
427+
const tagResult = await tagPackage(tangram, name, path);
428+
if (tagResult.kind !== "ok") {
429+
return tagResult;
430+
}
431+
432+
// Push the tag.
433+
const pushTagResult = await push(tangram, name);
434+
if (pushTagResult.kind !== "ok") {
435+
return pushTagResult;
436+
}
429437

430-
return ok(`tagged ${name}: ${packageId}`);
438+
return ok(`tagged ${name}: ${packageId}`);
439+
}
431440
};
432441

433442
/** Perform the upload action for a path. Will do the default build first. */

0 commit comments

Comments
 (0)