Skip to content

Commit

Permalink
feat(automation): add action to tag and push packages (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
deciduously authored Jan 9, 2025
1 parent 429a815 commit b7a948d
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 11 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Tag Packages

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
BUN_VERSION: 1.1.43
CARGO_TERM_COLOR: always
RUST_BINARY_NAME: tangram
RUST_REPO: tangramdotdev/tangram
RUST_REV: 57c9cd4f999f381c9e03e8ff2ba807b22c0d72b2

jobs:
tag-and-push:
runs-on: ubuntu-latest

steps:
- name: Check out workflow repository
uses: actions/checkout@v4

- name: Check out Rust repository
uses: actions/checkout@v4
with:
repository: ${{ env.RUST_REPO }}
path: tangram
ref: ${{ env.RUST_REV }}

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy

- name: Install Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: ${{ env.BUN_VERSION }}

- name: Cache Rust dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
tangram/target
key: ${{ runner.os }}-cargo-${{ hashFiles('tangram/**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Build Tangram
working-directory: tangram
run: cargo build --verbose --release

- name: Copy Tangram to path
run: |
mkdir -p ./bin
cp ./tangram/target/release/${{ env.RUST_BINARY_NAME }} ./bin/
echo "./bin" >> $GITHUB_PATH
- name: Tag and push all packages
shell: bash
run: |
bun run auto -p
31 changes: 20 additions & 11 deletions scripts/package_automation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ const checkAction = async (tangram: string, path: string): Promise<Result> => {
/** Perform the `publish` action for a package name. If the existing tag is out of date, tag and push the new package. */
const publishAction = async (tangram: string, name: string, path: string): Promise<Result> => {
log("publishing...");

// Check in the package, store the ID.
const packageIdResult = await checkinPackage(tangram, path);
if (packageIdResult.kind !== "ok") {
Expand All @@ -415,19 +416,27 @@ const publishAction = async (tangram: string, name: string, path: string): Promi
return result("checkinError", `no ID for ${path}`);
}

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

// Push the tag.
const pushTagResult = await push(tangram, name);
if (pushTagResult.kind !== "ok") {
return pushTagResult;
}
if (packageId === existing) {
log(`Existing tag for ${name} matches current ID:`, existing);
return ok(`${name} unchanged, no action taken.`);
} else {
log(`tagging ${name}...`);
const tagResult = await tagPackage(tangram, name, path);
if (tagResult.kind !== "ok") {
return tagResult;
}

// Push the tag.
const pushTagResult = await push(tangram, name);
if (pushTagResult.kind !== "ok") {
return pushTagResult;
}

return ok(`tagged ${name}: ${packageId}`);
return ok(`tagged ${name}: ${packageId}`);
}
};

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

0 comments on commit b7a948d

Please sign in to comment.