From b7a948d26d15fb3658ce285fd11f563c95cae5e6 Mon Sep 17 00:00:00 2001 From: Ben Lovy Date: Thu, 9 Jan 2025 16:30:10 -0500 Subject: [PATCH] feat(automation): add action to tag and push packages (#136) --- .github/workflows/tag.yml | 66 +++++++++++++++++++++++++++++++++++ scripts/package_automation.ts | 31 ++++++++++------ 2 files changed, 86 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/tag.yml diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml new file mode 100644 index 00000000..165cf063 --- /dev/null +++ b/.github/workflows/tag.yml @@ -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 + diff --git a/scripts/package_automation.ts b/scripts/package_automation.ts index 5801d81b..bbb10377 100644 --- a/scripts/package_automation.ts +++ b/scripts/package_automation.ts @@ -405,6 +405,7 @@ const checkAction = async (tangram: string, path: string): Promise => { /** 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 => { log("publishing..."); + // Check in the package, store the ID. const packageIdResult = await checkinPackage(tangram, path); if (packageIdResult.kind !== "ok") { @@ -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. */