Skip to content

Commit a6aceeb

Browse files
authored
Merge pull request #30 from atlassian/chore/update-build-pipelines
Update CI pipeline and npm scripts, and improve README
2 parents 30011ab + 458b5ee commit a6aceeb

4 files changed

Lines changed: 146 additions & 95 deletions

File tree

.github/workflows/ci.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
permissions:
12+
contents: read
13+
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
ci:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v6
24+
25+
- name: Setup Node.js
26+
uses: actions/setup-node@v6
27+
with:
28+
node-version-file: ".nvmrc"
29+
30+
- name: Install dependencies
31+
run: npm ci
32+
33+
- name: Typecheck
34+
run: npm run typecheck
35+
36+
- name: Lint & Format check
37+
run: npm run lint
38+
39+
- name: Unit tests
40+
run: npm run test:coverage
41+
42+
- name: Build
43+
run: npm run build

.github/workflows/release.yml

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,58 @@
1-
name: Publish on Push
1+
name: Release
22

33
on:
4-
push:
5-
branches:
6-
- main
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: "Version bump type"
8+
required: true
9+
type: choice
10+
options:
11+
- patch
12+
- minor
13+
- major
714

815
jobs:
9-
build:
16+
release:
1017
runs-on: ubuntu-latest
1118
permissions:
12-
contents: read
19+
contents: write
1320
id-token: write
1421
steps:
15-
- name: Checkout repository
16-
uses: actions/checkout@v4
22+
- name: Checkout
23+
uses: actions/checkout@v6
1724

1825
- name: Setup Node.js
19-
uses: actions/setup-node@v4
26+
uses: actions/setup-node@v6
2027
with:
21-
node-version: 23
28+
node-version-file: ".nvmrc"
2229

2330
- name: Install dependencies
2431
run: npm ci
2532

26-
- name: Test project
27-
run: npm t
28-
29-
- name: Build project
30-
run: npm run build
33+
- name: Configure git
34+
run: |
35+
git config user.name "github-actions[bot]"
36+
git config user.email "github-actions[bot]@users.noreply.github.com"
3137
32-
- name: Debug
38+
- name: Bump version
39+
id: bump
3340
run: |
34-
echo "${{ secrets.NPM_USERNAME }}" | cut -c 1-3
41+
npm version ${{ inputs.version }} -m "chore: release v%s"
42+
echo "version=$(node -p 'require("./package.json").version')" >> "$GITHUB_OUTPUT"
43+
44+
- name: Push version commit and tag
45+
run: git push --follow-tags
46+
47+
- name: Get Artifact Publish Token
48+
uses: atlassian-labs/artifact-publish-token@v1.0.1
49+
with:
50+
output-modes: npm
3551

3652
- name: Publish to npm
37-
run: |
38-
echo "registry=https://packages.atlassian.com/api/npm/npm-public/" >> ~/.npmrc
39-
echo "@atlassian:registry=https://packages.atlassian.com/api/npm/npm-public/" >> ~/.npmrc
40-
echo "//packages.atlassian.com/api/npm/npm-public/:username=${{ secrets.NPM_USERNAME }}" >> ~/.npmrc
41-
echo "//packages.atlassian.com/api/npm/npm-public/:_password=${{ secrets.NPM_PASSWORD }}" >> ~/.npmrc
42-
echo "//packages.atlassian.com/api/npm/npm-public/:email=zxu2@atlassian.com" >> ~/.npmrc
43-
echo "//packages.atlassian.com/api/npm/npm-public/:always-auth=true" >> ~/.npmrc
44-
45-
npm publish
53+
run: npm publish --userconfig .npmrc-public
54+
55+
- name: Create GitHub Release
56+
env:
57+
GH_TOKEN: ${{ github.token }}
58+
run: gh release create "v${{ steps.bump.outputs.version }}" --generate-notes

README.md

Lines changed: 54 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,88 @@
11
# Date Time API
22

3-
[![Atlassian license](https://img.shields.io/badge/license-Apache%202.0-blue.svg?style=flat-square)](LICENSE) [![npm version](https://img.shields.io/npm/v/@atlassian/date-time.svg?style=flat-square)](https://www.npmjs.com/package/@atlassian/date-time) [![workflow status](https://github.com/atlassian/date-time-api/actions/workflows/release.yml/badge.svg?event=push)](https://github.com/atlassian/date-time-api/actions/workflows/release.yml?query=event%3Apush) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](CONTRIBUTING.md)
3+
[![Atlassian license](https://img.shields.io/badge/license-Apache%202.0-blue.svg?style=flat-square)](LICENSE)
4+
[![npm version](https://img.shields.io/npm/v/@atlassian/date-time.svg?style=flat-square)](https://www.npmjs.com/package/@atlassian/date-time)
5+
[![CI](https://github.com/atlassian/date-time-api/actions/workflows/ci.yml/badge.svg)](https://github.com/atlassian/date-time-api/actions/workflows/ci.yml)
6+
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](CONTRIBUTING.md)
47

5-
## Introduction
8+
A comprehensive library for date and time manipulation in JavaScript. Provides utilities for parsing, validating, and formatting dates and times.
69

7-
The Date Time API is a comprehensive library designed to simplify date and time manipulation in JavaScript. It provides a wide range of utilities for parsing, validating and formatting dates and times, making it easier for developers to handle date-time operations in their applications.
10+
## Installation
11+
12+
```bash
13+
npm install @atlassian/date-time
14+
```
815

916
## Usage
1017

1118
```javascript
1219
import * as dateTime from "@atlassian/date-time";
20+
```
1321

14-
// Parse a date string
15-
const date = dateTime.parse("2024-01-01");
16-
console.log(date); // Outputs: "Mon Jan 01 2024 00:00:00 GMT+0000 (Coordinated Universal Time)"
17-
18-
// Get date pattern
19-
const pattern = dateTime.getDatePattern("en-US");
20-
console.log(pattern); // Outputs: "mm/dd/yyyy"
21-
22-
// Validate a date string
23-
const isValid = dateTime.validate("2024-01-01");
24-
console.log(isValid); // Outputs: true
22+
### Parsing & Validation
2523

26-
// Format a plain date
27-
const plainDate = dateTime.formatPlainDate(new Date());
28-
console.log(plainDate); // Outputs: "2024-01-01"
24+
```javascript
25+
dateTime.parse("2024-01-01");
26+
// → Mon Jan 01 2024 00:00:00 GMT+0000
2927

30-
// Format a plain time
31-
const plainTime = dateTime.formatPlainTime(new Date());
32-
console.log(plainTime); // Outputs: "12:00:00"
28+
dateTime.validate("2024-01-01");
29+
// → true
3330

34-
// Format a plain date-time
35-
const plainDateTime = dateTime.formatPlainDateTime(new Date());
36-
console.log(plainDateTime); // Outputs: "2024-01-01T12:00:00"
31+
dateTime.getDatePattern("en-US");
32+
// → "mm/dd/yyyy"
33+
```
3734

38-
// Format a numeric date
39-
const numericDate = dateTime.formatNumericDate(new Date(), "en-US");
40-
console.log(numericDate); // Outputs: "1/1/2024"
35+
### Formatting Dates & Times
4136

42-
// Format a date
43-
const formattedDate = dateTime.formatDate(new Date(), "en-US");
44-
console.log(formattedDate); // Outputs: "Jan 1, 2024"
37+
```javascript
38+
dateTime.formatPlainDate(new Date());
39+
// → "2024-01-01"
4540

46-
// Format a time
47-
const formattedTime = dateTime.formatTime(new Date(), "en-US");
48-
console.log(formattedTime); // Outputs: "12:00:00 PM"
41+
dateTime.formatPlainTime(new Date());
42+
// → "12:00:00"
4943

50-
// Format a date-time
51-
const formattedDateTime = dateTime.formatDateTime(new Date(), "en-US");
52-
console.log(formattedDateTime); // Outputs: "Jan 1, 2024, 12:00:00 PM"
44+
dateTime.formatPlainDateTime(new Date());
45+
// → "2024-01-01T12:00:00"
46+
```
5347

54-
// Format a date-time with options
55-
const formattedDateTimeWithOptions = dateTime.formatDateTimeByOptions({ second: undefined }, new Date(), "en-US");
56-
console.log(formattedDateTimeWithOptions); // Outputs: "Jan 1, 2024, 12:00 PM"
48+
### Locale-aware Formatting
5749

58-
// Format a duration
59-
const duration = dateTime.formatDuration(new Date(2024, 0, 1), new Date(2024, 0, 2), "en-US");
60-
console.log(duration); // Outputs: "1 day 1 hour 1 minute 1 second"
50+
```javascript
51+
dateTime.formatNumericDate(new Date(), "en-US");
52+
// "1/1/2024"
6153

62-
// Format a duration with custom options
63-
const durationWithOptions = dateTime.formatDurationByOptions({ unitDisplay: "narrow" }, new Date(2024, 0, 1), new Date(2024, 0, 2), "en-US");
64-
console.log(durationWithOptions); // Outputs: "1d 1h 1m 1s"
65-
```
54+
dateTime.formatDate(new Date(), "en-US");
55+
// → "Jan 1, 2024"
6656

67-
## Installation
57+
dateTime.formatTime(new Date(), "en-US");
58+
// → "12:00:00 PM"
6859

69-
To install the Date Time API, use npm:
60+
dateTime.formatDateTime(new Date(), "en-US");
61+
// → "Jan 1, 2024, 12:00:00 PM"
7062

71-
```bash
72-
npm install @atlassian/date-time
63+
dateTime.formatDateTimeByOptions({ second: undefined }, new Date(), "en-US");
64+
// → "Jan 1, 2024, 12:00 PM"
7365
```
7466

75-
## Build
67+
### Duration Formatting
7668

77-
To build the Date Time API, use npm:
69+
```javascript
70+
dateTime.formatDuration(new Date(2024, 0, 1), new Date(2024, 0, 2), "en-US");
71+
// → "1 day 1 hour 1 minute 1 second"
7872

79-
```bash
80-
npm run build
73+
dateTime.formatDurationByOptions({ unitDisplay: "narrow" }, new Date(2024, 0, 1), new Date(2024, 0, 2), "en-US");
74+
// → "1d 1h 1m 1s"
8175
```
8276

83-
## Tests
84-
85-
To run the tests, use the following command:
77+
## Development
8678

8779
```bash
88-
npm test
80+
npm run typecheck # Type checking
81+
npm run lint # ESLint + Prettier check
82+
npm run format # Auto-fix lint + format
83+
npm test # Run unit tests
84+
npm run build # Build for production
85+
npm run checks # Run all checks
8986
```
9087

9188
## Contributions

package.json

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,16 @@
1010
"import": "./dist/bundle.mjs"
1111
},
1212
"scripts": {
13-
"build": "npm run build:tsc && npm run build:webpack",
14-
"build:tsc": "tsc --project tsconfig.json",
15-
"build:webpack": "webpack",
16-
"format": "npm run format:lint && npm run format:prettier",
17-
"format:lint": "eslint --fix .",
18-
"format:prettier": "prettier --write .",
19-
"test": "npm run test:tsc && npm run test:lint && npm run test:jest -- --coverage",
20-
"test:tsc": "tsc --noEmit",
21-
"test:prettier": "prettier --check .",
22-
"test:lint": "eslint .",
23-
"test:jest": "LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 TZ=Asia/Sydney jest",
24-
"prepublishOnly": "rm -rf dist && npm run test && npm run build"
13+
"typecheck": "tsc --noEmit",
14+
"lint": "eslint && prettier --check .",
15+
"format": "eslint --fix && prettier --write .",
16+
"test": "LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 TZ=Asia/Sydney jest",
17+
"test:coverage": "npm run test -- --coverage",
18+
"checks": "npm run typecheck && npm run lint && npm run test:coverage",
19+
"build": "npm run build:types && npm run build:bundle",
20+
"build:types": "tsc --project tsconfig.json",
21+
"build:bundle": "webpack",
22+
"prepublishOnly": "rm -rf dist && npm run checks && npm run build"
2523
},
2624
"repository": {
2725
"type": "git",

0 commit comments

Comments
 (0)