Skip to content

Commit

Permalink
Merge pull request #4 from busticated/feature/publishing
Browse files Browse the repository at this point in the history
feature/publishing
  • Loading branch information
busticated authored Oct 15, 2023
2 parents 933a65b + 4fbbe98 commit e586bda
Show file tree
Hide file tree
Showing 17 changed files with 728 additions and 38 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,47 @@ on:
workflow_dispatch:

jobs:
info:
name: Harvest Commit Info
runs-on: ubuntu-latest
outputs:
tags: ${{ steps.info.outputs.tags }}
steps:
- name: Checkout Source Code
uses: actions/checkout@v3
with:
fetch-tags: true
- name: Set Info
id: info
run: ./bin/ci-set-commit-info.sh

debug:
name: Debug
needs: info
runs-on: ubuntu-latest
steps:
- name: Log Info
run: |
echo ":::: GIT REF: ${{github.ref}}"
echo ":::: GIT REF_NAME: ${{github.ref_name}}"
echo ":::: TAGS: ${{needs.info.outputs.tags}}"
- name: Test Tag Check
if: contains(needs.info.outputs.tags, '@')
run: |
echo ":::: FOUND TAGS"
test:
name: Run Tests
needs: [info, debug]
uses: ./.github/workflows/test.yaml
secrets: inherit

publish:
name: Publish Crates
needs: [info, debug, test]
if: github.ref_name == 'main' && contains(needs.info.outputs.tags, '@')
uses: ./.github/workflows/publish.yaml
secrets: inherit
with:
tags: ${{needs.info.outputs.tags}}

30 changes: 30 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Publish

on:
workflow_call:
inputs:
tags:
type: string
required: true
secrets:
CARGO_REGISTRY_TOKEN:
required: true

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout Source Code
uses: actions/checkout@v3
with:
fetch-tags: true
- name: Install Rust Toolchain (stable)
uses: dtolnay/rust-toolchain@stable
- name: Setup Project
run: cargo xtask setup
- name: Publish to Crates.io
if: contains(inputs.tags, '@')
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo xtask crate:publish

16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,22 @@ Run `cargo xtask help` to see any other docs-related commands that are available
</p>
</details>

<details id="develop-publish-crate">
<summary><b>How to publish crates</b></summary>
<p>

To publish a crate to the [crates.io](https://crates.io) registry, follow these steps:

1. Checkout the `main` branch: `git checkout main`
2. Run `cargo xtask crate:release` and follow the prompts
3. Verify all checks pass: `cargo xtask ci`
4. Push to remote: `git push origin main --follow-tags`

Each crate you select for publishing will be assigned its new version and all changes will be committed and tagged in `git`. The assigned tag will be formatted like `name@version` (e.g. `detect-newline-style@1.0.0`). After pushing to the remote, CI will execute the publishing steps and if all goes well, your crate will be available on [crates.io](https://crates.io).

</p>
</details>

<details id="develop-todo">
<summary><b>How to view and add TODO source code comments</b></summary>
<p>
Expand Down
24 changes: 24 additions & 0 deletions bin/ci-set-commit-info.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

echo
echo ":::: GIT Commit:"
git log -1

echo
echo ":::: GIT Tags:"
git tag --points-at HEAD

taglistStr=$(git tag --points-at HEAD)
declare -a taglist=($taglistStr)
tags=""

for tag in "${taglist[@]}"; do
tags="${tags} ${tag}"
done

echo
echo ":::: Set Action Output: Tags:"
echo "tags=$tags" >> $GITHUB_OUTPUT
echo $tags
echo

14 changes: 14 additions & 0 deletions crates/detect-newline-style/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,20 @@ mod tests {
assert_eq!(eol, LineEnding::LF);
}

#[test]
fn it_uses_default_when_text_has_no_line_breaks() {
let input = "no line breaks";
let eol = LineEnding::find(input, LineEnding::LF);
assert_eq!(eol, LineEnding::LF);
}

#[test]
fn it_uses_default_when_text_is_empty() {
let input = "";
let eol = LineEnding::find(input, LineEnding::LF);
assert_eq!(eol, LineEnding::LF);
}

#[test]
fn it_finds_preferred_line_ending_defaulting_to_cr_endings() {
let input = "\rthis\rprefers\r\nobsolete endings\n";
Expand Down
23 changes: 23 additions & 0 deletions crates/node-js-release-info/src/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,29 @@ mod tests {
assert_eq!(arch, NodeJSArch::PPC64LE);
}

#[test]
fn it_serializes_to_str() {
let text = format!("{}", NodeJSArch::X64);

assert_eq!(text, "x64");

let text = format!("{}", NodeJSArch::X86);

assert_eq!(text, "x86");

let text = format!("{}", NodeJSArch::ARM64);

assert_eq!(text, "arm64");

let text = format!("{}", NodeJSArch::ARMV7L);

assert_eq!(text, "armv7l");

let text = format!("{}", NodeJSArch::PPC64LE);

assert_eq!(text, "ppc64le");
}

#[test]
fn it_initializes_using_current_environment() {
NodeJSArch::from_env().unwrap();
Expand Down
19 changes: 19 additions & 0 deletions crates/node-js-release-info/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,25 @@ mod tests {
assert_eq!(ext, NodeJSPkgExt::Msi);
}

#[test]
fn it_serializes_to_str() {
let text = format!("{}", NodeJSPkgExt::Targz);

assert_eq!(text, "tar.gz");

let text = format!("{}", NodeJSPkgExt::Tarxz);

assert_eq!(text, "tar.xz");

let text = format!("{}", NodeJSPkgExt::Zip);

assert_eq!(text, "zip");

let text = format!("{}", NodeJSPkgExt::Msi);

assert_eq!(text, "msi");
}

#[test]
#[should_panic(
expected = "called `Result::unwrap()` on an `Err` value: UnrecognizedExt(\"NOPE!\")"
Expand Down
15 changes: 15 additions & 0 deletions crates/node-js-release-info/src/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,21 @@ mod tests {
assert_eq!(os, NodeJSOS::Windows);
}

#[test]
fn it_serializes_to_str() {
let text = format!("{}", NodeJSOS::Linux);

assert_eq!(text, "linux");

let text = format!("{}", NodeJSOS::Darwin);

assert_eq!(text, "darwin");

let text = format!("{}", NodeJSOS::Windows);

assert_eq!(text, "win");
}

#[test]
fn it_initializes_using_current_environment() {
NodeJSOS::from_env().unwrap();
Expand Down
4 changes: 3 additions & 1 deletion xtask/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[package]
name = "xtask"
description = "internal-only crate used to orchestrate repo tasks"
version = "0.1.0"
edition = "2021"

Expand All @@ -9,4 +10,5 @@ edition = "2021"
duct = "0.13.*"
inquire = "0.6.*"
regex = "1.*"
toml = "0.8.*"
semver = "1.*"
toml_edit = "0.20.*"
Loading

0 comments on commit e586bda

Please sign in to comment.