Merge pull request #16 from Teslemetry/changeset-release/main #64
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish | |
| on: | |
| push: | |
| branches: | |
| - main | |
| concurrency: ${{ github.workflow }}-${{ github.ref }} | |
| jobs: | |
| release: | |
| name: Release | |
| runs-on: ubuntu-latest | |
| environment: production | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| id-token: write | |
| steps: | |
| - name: Checkout Repo | |
| uses: actions/checkout@v4 | |
| - name: Install pnpm | |
| uses: pnpm/action-setup@v2 | |
| with: | |
| version: 9 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| registry-url: "https://registry.npmjs.org" | |
| always-auth: true | |
| cache: "pnpm" | |
| - name: Install Dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Upgrade npm for OIDC support | |
| run: npm install -g npm@latest | |
| - name: Build | |
| run: pnpm -r run build | |
| - name: Create Release Pull Request or Publish to npm | |
| id: changesets | |
| uses: changesets/action@v1 | |
| with: | |
| publish: pnpm run ci:publish | |
| commit: "chore: version packages" | |
| title: "chore: version packages" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Check for specific package releases | |
| id: check_releases | |
| if: steps.changesets.outputs.published == 'true' | |
| run: | | |
| node -e ' | |
| const published = JSON.parse(process.env.PUBLISHED_PACKAGES || "[]"); | |
| const nodeRed = published.find(p => p.name === "@teslemetry/node-red-contrib-teslemetry"); | |
| const n8n = published.find(p => p.name === "@teslemetry/n8n-nodes-teslemetry"); | |
| if (nodeRed) { | |
| console.log("Found Node-RED release: " + nodeRed.version); | |
| require("fs").appendFileSync(process.env.GITHUB_OUTPUT, "node_red_version=" + nodeRed.version + "\n"); | |
| } | |
| if (n8n) { | |
| console.log("Found n8n release: " + n8n.version); | |
| require("fs").appendFileSync(process.env.GITHUB_OUTPUT, "n8n_version=" + n8n.version + "\n"); | |
| } | |
| ' | |
| env: | |
| PUBLISHED_PACKAGES: ${{ steps.changesets.outputs.publishedPackages }} | |
| - name: Discord Notification (Node-RED) | |
| if: steps.check_releases.outputs.node_red_version | |
| env: | |
| DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_NODERED }} | |
| VERSION: ${{ steps.check_releases.outputs.node_red_version }} | |
| run: | | |
| curl -H "Content-Type: application/json" \ | |
| -d "{\"username\": \"Teslemetry Release\", \"content\": \"🚀 **New Release**\n**@teslemetry/node-red-contrib-teslemetry** version **$VERSION** is now available!\"}" \ | |
| $DISCORD_WEBHOOK | |
| - name: Discord Notification (n8n) | |
| if: steps.check_releases.outputs.n8n_version | |
| env: | |
| DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_N8N }} | |
| VERSION: ${{ steps.check_releases.outputs.n8n_version }} | |
| run: | | |
| curl -H "Content-Type: application/json" \ | |
| -d "{\"username\": \"Teslemetry Release\", \"content\": \"🚀 **New Release**\n**@teslemetry/n8n-nodes-teslemetry** version **$VERSION** is now available!\"}" \ | |
| $DISCORD_WEBHOOK | |
| - name: Check for Homey package release | |
| id: check_homey | |
| if: steps.changesets.outputs.published == 'true' | |
| run: | | |
| node -e ' | |
| const published = JSON.parse(process.env.PUBLISHED_PACKAGES || "[]"); | |
| const homey = published.find(p => p.name === "com.teslemetry"); | |
| if (homey) { | |
| console.log("Found Homey package release: " + homey.version); | |
| require("fs").appendFileSync(process.env.GITHUB_OUTPUT, "homey_version=" + homey.version + "\n"); | |
| require("fs").appendFileSync(process.env.GITHUB_OUTPUT, "should_publish_homey=true\n"); | |
| } | |
| ' | |
| env: | |
| PUBLISHED_PACKAGES: ${{ steps.changesets.outputs.publishedPackages }} | |
| - name: Update Homey App Version | |
| if: steps.check_homey.outputs.should_publish_homey == 'true' | |
| working-directory: ./packages/homey | |
| run: | | |
| # Update .homeycompose/app.json version to match package.json | |
| node -e ' | |
| const fs = require("fs"); | |
| const packageJson = JSON.parse(fs.readFileSync("package.json", "utf8")); | |
| const appJson = JSON.parse(fs.readFileSync(".homeycompose/app.json", "utf8")); | |
| appJson.version = packageJson.version; | |
| fs.writeFileSync(".homeycompose/app.json", JSON.stringify(appJson, null, 2)); | |
| ' | |
| - name: Validate Homey App | |
| if: steps.check_homey.outputs.should_publish_homey == 'true' | |
| uses: athombv/github-action-homey-app-validate@master | |
| with: | |
| level: verified | |
| - name: Publish Homey App | |
| if: steps.check_homey.outputs.should_publish_homey == 'true' | |
| uses: athombv/github-action-homey-app-publish@master | |
| id: publish_homey | |
| with: | |
| personal_access_token: ${{ secrets.HOMEY_PAT }} | |
| - name: Discord Notification (Homey) | |
| if: steps.check_homey.outputs.homey_version | |
| env: | |
| DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_HOMEY }} # You'd need to add this secret | |
| VERSION: ${{ steps.check_homey.outputs.homey_version }} | |
| run: | | |
| curl -H "Content-Type: application/json" \ | |
| -d "{\"username\": \"Teslemetry Release\", \"content\": \"🏠 **New Homey App Release**\n**Teslemetry for Homey** version **$VERSION** is now available!\"}" \ | |
| $DISCORD_WEBHOOK || echo "Discord webhook not configured for Homey" |