Skip to content

Commit

Permalink
Merge pull request #2 from vamsii777/feat/improve-timezone-handling
Browse files Browse the repository at this point in the history
Restructure & Improve TZDB Processing
  • Loading branch information
vamsii777 authored Nov 21, 2024
2 parents c510e45 + 2be1e6f commit 0d83be2
Show file tree
Hide file tree
Showing 20 changed files with 2,615 additions and 627 deletions.
141 changes: 141 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
name: Create Release

on:
pull_request:
types: [closed]
branches:
- main

jobs:
create-release:
name: Create Release
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'release')
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: read

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Determine Next Version
id: version
run: |
# Get latest release tag (if any)
latest_tag=$(gh release view --json tagName --jq .tagName || echo "v0.0.0")
# Extract major, minor, patch numbers
if [[ $latest_tag =~ v([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
major="${BASH_REMATCH[1]}"
minor="${BASH_REMATCH[2]}"
patch="${BASH_REMATCH[3]}"
else
major=0
minor=0
patch=0
fi
# Determine version bump type from PR labels
if contains(github.event.pull_request.labels.*.name, 'major'); then
major=$((major + 1))
minor=0
patch=0
elif contains(github.event.pull_request.labels.*.name, 'minor'); then
minor=$((minor + 1))
patch=0
else
# Default to patch bump if no major/minor label
patch=$((patch + 1))
fi
new_version="v${major}.${minor}.${patch}"
echo "New version will be: $new_version"
echo "version=$new_version" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Generate Release Notes
id: release-notes
run: |
# Get PR description
DESCRIPTION="${{ github.event.pull_request.body }}"
# Get list of changes since last release
CHANGES=$(gh pr list \
--base main \
--state merged \
--json title,number,mergedAt,labels \
--search "merged:>=$(gh release view --json publishedAt --jq .publishedAt || echo "v0.0.0")")
# Extract PR description and format it
DESCRIPTION=$(echo "$DESCRIPTION" | sed '/<!--.*-->/d')
# Format the release notes
NOTES="## What's Changed
${DESCRIPTION}
**Full Changelog**: https://github.com/${{ github.repository }}/compare/${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }}
## Installation
Add to your \`Package.swift\`:
\`\`\`swift
dependencies: [
.package(url: \"https://github.com/vamsii777/SwiftTZ.git\", from: \"${{ steps.version.outputs.version }}\")
]
\`\`\`
"
# Save to file (handles multiline better than environment variables)
echo "$NOTES" > release_notes.md
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.version.outputs.version }}
name: Release ${{ steps.version.outputs.version }}
body_path: release_notes.md
draft: false
prerelease: false
token: ${{ secrets.GITHUB_TOKEN }}

- name: Update Documentation
if: success()
run: |
# Add any documentation update steps here
echo "Documentation updated for version ${{ steps.version.outputs.version }}"
- name: Notify on Failure
if: failure()
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '❌ Failed to create release. Please check the workflow logs for details.'
})
- name: Update README.md Version
if: success()
run: |
VERSION="${{ steps.version.outputs.version }}"
VERSION_NO_V="${VERSION#v}" # Remove 'v' prefix
# Update version in README.md
sed -i.bak 's/\.package(url: "https:\/\/github\.com\/vamsii777\/SwiftTZ\.git", from: "[0-9]*\.[0-9]*\.[0-9]*")/\.package(url: "https:\/\/github\.com\/vamsii777\/SwiftTZ\.git", from: "'$VERSION_NO_V'")/' README.md
rm README.md.bak
- name: Commit Version Updates
if: success()
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add Package.swift README.md
git commit -m "chore: bump version to ${{ steps.version.outputs.version }}"
git push
31 changes: 0 additions & 31 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,5 @@ jobs:
- name: Build
run: swift build

- name: Run tests
run: swift test

linux-tests:
name: Linux Tests (Swift ${{ matrix.swift }})
runs-on: ubuntu-latest
container:
image: swift:${{ matrix.swift }}-jammy
strategy:
fail-fast: false
matrix:
swift: ["6.0"]

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install curl
run: sudo apt-get install -y curl

- name: Install pkl
run: |
curl -L -o pkl https://github.com/apple/pkl/releases/download/0.27.0/pkl-linux-amd64
chmod +x pkl
mv pkl /usr/local/bin/
pkl --version
- name: Build
run: swift build

- name: Run tests
run: swift test
41 changes: 36 additions & 5 deletions .github/workflows/update-tzdb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jobs:
check-and-update:
name: Check and Update TZDB
runs-on: macos-latest
permissions:
contents: write
pull-requests: write

steps:
- uses: actions/checkout@v4
Expand All @@ -31,17 +34,29 @@ jobs:
- name: Download current zonenow.tab
run: |
curl -o zonenow.tab.new https://raw.githubusercontent.com/eggert/tz/main/zonenow.tab
curl -o zone1970.tab.new https://raw.githubusercontent.com/eggert/tz/main/zone1970.tab
- name: Check for changes
id: check
run: |
changes_detected=false
if [ ! -f "zonenow.tab" ] || ! cmp -s "zonenow.tab" "zonenow.tab.new"; then
echo "changes_detected=true" >> $GITHUB_OUTPUT
echo "Changes detected in zonenow.tab"
mv zonenow.tab.new zonenow.tab
changes_detected=true
else
echo "No changes detected in zonenow.tab"
echo "changes_detected=false" >> $GITHUB_OUTPUT
fi
if [ ! -f "zone1970.tab" ] || ! cmp -s "zone1970.tab" "zone1970.tab.new"; then
echo "Changes detected in zone1970.tab"
mv zone1970.tab.new zone1970.tab
changes_detected=true
else
echo "No changes detected in zone1970.tab"
fi
echo "changes_detected=$changes_detected" >> $GITHUB_OUTPUT
- name: Build project
if: steps.check.outputs.changes_detected == 'true'
Expand All @@ -56,14 +71,28 @@ jobs:
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "chore: Update timezone database"
title: "chore: Update timezone database"
commit-message: "[Automated] Update Time Zone Database"
title: "[Automated] Update Time Zone Database"
body: |
This PR updates the timezone database based on changes in the IANA tzdb.
Changes were automatically detected and generated using the `tzdb-gen` tool.
- Updated `zonenow.tab` from IANA
### Changes
<details>
<summary>View changes</summary>
```diff
# zonenow.tab changes
$(diff -u zonenow.tab.new zonenow.tab || true)
# zone1970.tab changes
$(diff -u zone1970.tab.new zone1970.tab || true)
```
</details>
- Updated `zonenow.tab` and/or `zone1970.tab` from IANA
- Regenerated PKL schema
- Updated Swift generated code
Expand All @@ -73,6 +102,8 @@ jobs:
labels: |
automated
tzdb-update
patch
release
delete-branch: true

- name: Check Generated Files
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
Packages.resolved
Packages.resolved.swiftpm/
42 changes: 0 additions & 42 deletions Package.resolved

This file was deleted.

76 changes: 34 additions & 42 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,47 +1,39 @@
import CompilerPluginSupport
// swift-tools-version: 6.0
import PackageDescription

let package = Package(
name: "SwiftTZ",
platforms: [
.macOS(.v13),
.iOS(.v16),
.watchOS(.v9),
.tvOS(.v16),
.macCatalyst(.v16),
.visionOS(.v1),
],
products: [
.library(name: "SwiftTZ", targets: ["SwiftTZ"]),
.executable(name: "tzdb-gen", targets: ["SwiftTZGenerator"]),
],
dependencies: [
.package(url: "https://github.com/apple/pkl-swift.git", from: "0.3.0")
],
targets: [
// Generator executable
.executableTarget(
name: "SwiftTZGenerator",
dependencies: [
.product(name: "PklSwift", package: "pkl-swift")
]
),

// Main library
.target(
name: "SwiftTZ",
dependencies: [
.product(name: "PklSwift", package: "pkl-swift")
]
),

// Tests
.testTarget(
name: "SwiftTZTests",
dependencies: [
"SwiftTZ"
]
),
]
name: "swifttz",
platforms: [
.macOS(.v13),
.iOS(.v16),
.watchOS(.v9),
.tvOS(.v16),
.macCatalyst(.v16),
.visionOS(.v1)
],
products: [
.library(name: "SwiftTZ", targets: ["SwiftTZ"]),
.executable(name: "tzdb-gen", targets: ["SwiftTZGenerator"]),
],
targets: [
// Generator executable
.executableTarget(
name: "SwiftTZGenerator",
dependencies: []
),

// Main library
.target(
name: "SwiftTZ",
dependencies: []
),

// Tests
.testTarget(
name: "SwiftTZTests",
dependencies: [
"SwiftTZ"
]
),
]
)
Loading

0 comments on commit 0d83be2

Please sign in to comment.