Publish workflow (SadeghHayeri/GreenTunnel)
The Publish workflow from SadeghHayeri/GreenTunnel, explained and optimized by Latchkey.
CI health: C - fair
Point runs-on at Latchkey and get caching, job timeouts, SHA-pinned actions, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Publish workflow from the SadeghHayeri/GreenTunnel repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: Publish
on:
create:
tags:
- v*
jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
publish-docker-hub:
runs-on: ubuntu-latest
steps:
- name: Retrieve tag
id: retrieve
run: |
DOCKER_IMAGE=sadeghhayeri/green-tunnel
VERSION=${GITHUB_REF#refs/tags/}
TAGS="${DOCKER_IMAGE}:${VERSION}"
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
file: Dockerfile
push: true
tags: ${{ steps.retrieve.outputs.tags }},sadeghhayeri/green-tunnel:latest
publish-docker-hub-for-arm:
runs-on: ubuntu-latest
steps:
- name: Retrieve tag
id: retrieve
run: |
DOCKER_IMAGE=sadeghhayeri/green-tunnel
VERSION=${GITHUB_REF#refs/tags/}
TAGS="${DOCKER_IMAGE}:arm-${VERSION}"
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Change Base Image
run: sed -i 's/node:20-alpine/balenalib\/raspberry-pi-alpine-node/g' Dockerfile
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
file: Dockerfile
push: true
tags: ${{ steps.retrieve.outputs.tags }},sadeghhayeri/green-tunnel:arm-latest
platforms: linux/amd64,linux/armhf,linux/arm64
build-for-mac:
runs-on: macos-latest
needs: [publish-npm]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Dependencies
working-directory: ./gui
run: npm ci
- name: Update GreenTunnel Core
working-directory: ./gui
run: npm install green-tunnel@latest --save
- name: Fix GUI Naming
working-directory: ./gui
run: |
sed -i '' 's/green-tunnel-gui/green-tunnel/g' package.json
sed -i '' 's/green-tunnel-gui/green-tunnel/g' package-lock.json
- name: Generate icons
working-directory: ./gui
run: npm run generate-icons
- name: Build for macOS
working-directory: ./gui
run: npm run package-mac
- name: Zip
working-directory: ./gui/release-builds/green-tunnel-darwin-x64
run: zip -r green-tunnel-macos.zip green-tunnel.app
- name: Save artifact
uses: actions/upload-artifact@v4
with:
name: builds-mac
path: ./gui/release-builds/green-tunnel-darwin-x64/green-tunnel-macos.zip
build-for-windows:
runs-on: windows-latest
needs: [publish-npm]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Dependencies
working-directory: ./gui
run: npm ci
- name: Update GreenTunnel Core
working-directory: ./gui
run: npm install green-tunnel@latest --save
- name: Fix GUI Naming
working-directory: ./gui
run: |
powershell -Command "(gc package.json) -replace 'green-tunnel-gui', 'green-tunnel' | Out-File -encoding ASCII package.json"
powershell -Command "(gc package-lock.json) -replace 'green-tunnel-gui', 'green-tunnel' | Out-File -encoding ASCII package-lock.json"
- name: Generate icons
working-directory: ./gui
run: npm run generate-icons
- name: Build for Windows
working-directory: ./gui
run: npm run package-win
- name: Add Windows Installer
working-directory: ./gui
run: npm run windows-installer
- name: Zip
working-directory: ./gui/release-builds/green-tunnel/windows-installer
run: Compress-Archive -Path green-tunnel-installer.exe -DestinationPath green-tunnel-windows.zip
- name: Save artifact
uses: actions/upload-artifact@v4
with:
name: builds-windows
path: ./gui/release-builds/green-tunnel/windows-installer/green-tunnel-windows.zip
build-for-linux:
runs-on: ubuntu-latest
needs: [publish-npm]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Dependencies
working-directory: ./gui
run: |
npm ci
npm install -g electron-installer-debian
- name: Update GreenTunnel Core
working-directory: ./gui
run: npm install green-tunnel@latest --save
- name: Fix GUI Naming
working-directory: ./gui
run: |
sed -i 's/green-tunnel-gui/green-tunnel/g' package.json
sed -i 's/green-tunnel-gui/green-tunnel/g' package-lock.json
- name: Generate icons
working-directory: ./gui
run: npm run generate-icons
- name: Build for Linux
working-directory: ./gui
run: npm run package-linux
- name: Add Linux Installer
working-directory: ./gui
run: npm run linux-installer
- name: Zip
working-directory: ./gui/release-builds
run: zip -r green-tunnel-debian.zip *.deb
- name: Save artifact
uses: actions/upload-artifact@v4
with:
name: builds-linux
path: ./gui/release-builds/green-tunnel-debian.zip
new-release:
runs-on: ubuntu-latest
needs: [build-for-mac, build-for-windows, build-for-linux]
steps:
- name: Download all build artifacts
uses: actions/download-artifact@v4
with:
pattern: builds-*
merge-multiple: true
path: builds/
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: |
builds/green-tunnel-macos.zip
builds/green-tunnel-windows.zip
builds/green-tunnel-debian.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
The same workflow, on Latchkey
Estimated ~20% faster on cache hits, plus fewer wasted runs and a safer supply chain. Added and changed lines are highlighted.
name: Publish on: create: tags: - v* jobs: publish-npm: timeout-minutes: 30 runs-on: latchkey-small steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: cache: 'npm' node-version: '20' registry-url: https://registry.npmjs.org/ - run: npm ci - run: npm publish env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} publish-docker-hub: timeout-minutes: 30 runs-on: latchkey-small steps: - name: Retrieve tag id: retrieve run: | DOCKER_IMAGE=sadeghhayeri/green-tunnel VERSION=${GITHUB_REF#refs/tags/} TAGS="${DOCKER_IMAGE}:${VERSION}" echo "tags=${TAGS}" >> $GITHUB_OUTPUT - uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Login to DockerHub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Build and push Docker image uses: docker/build-push-action@v6 with: file: Dockerfile push: true tags: ${{ steps.retrieve.outputs.tags }},sadeghhayeri/green-tunnel:latest publish-docker-hub-for-arm: timeout-minutes: 30 runs-on: latchkey-small steps: - name: Retrieve tag id: retrieve run: | DOCKER_IMAGE=sadeghhayeri/green-tunnel VERSION=${GITHUB_REF#refs/tags/} TAGS="${DOCKER_IMAGE}:arm-${VERSION}" echo "tags=${TAGS}" >> $GITHUB_OUTPUT - uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Login to DockerHub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Change Base Image run: sed -i 's/node:20-alpine/balenalib\/raspberry-pi-alpine-node/g' Dockerfile - name: Build and push Docker image uses: docker/build-push-action@v6 with: file: Dockerfile push: true tags: ${{ steps.retrieve.outputs.tags }},sadeghhayeri/green-tunnel:arm-latest platforms: linux/amd64,linux/armhf,linux/arm64 build-for-mac: timeout-minutes: 30 runs-on: macos-latest needs: [publish-npm] steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: cache: 'npm' node-version: '20' - name: Install Dependencies working-directory: ./gui run: npm ci - name: Update GreenTunnel Core working-directory: ./gui run: npm install green-tunnel@latest --save - name: Fix GUI Naming working-directory: ./gui run: | sed -i '' 's/green-tunnel-gui/green-tunnel/g' package.json sed -i '' 's/green-tunnel-gui/green-tunnel/g' package-lock.json - name: Generate icons working-directory: ./gui run: npm run generate-icons - name: Build for macOS working-directory: ./gui run: npm run package-mac - name: Zip working-directory: ./gui/release-builds/green-tunnel-darwin-x64 run: zip -r green-tunnel-macos.zip green-tunnel.app - name: Save artifact uses: actions/upload-artifact@v4 with: name: builds-mac path: ./gui/release-builds/green-tunnel-darwin-x64/green-tunnel-macos.zip build-for-windows: timeout-minutes: 30 runs-on: windows-latest needs: [publish-npm] steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: cache: 'npm' node-version: '20' - name: Install Dependencies working-directory: ./gui run: npm ci - name: Update GreenTunnel Core working-directory: ./gui run: npm install green-tunnel@latest --save - name: Fix GUI Naming working-directory: ./gui run: | powershell -Command "(gc package.json) -replace 'green-tunnel-gui', 'green-tunnel' | Out-File -encoding ASCII package.json" powershell -Command "(gc package-lock.json) -replace 'green-tunnel-gui', 'green-tunnel' | Out-File -encoding ASCII package-lock.json" - name: Generate icons working-directory: ./gui run: npm run generate-icons - name: Build for Windows working-directory: ./gui run: npm run package-win - name: Add Windows Installer working-directory: ./gui run: npm run windows-installer - name: Zip working-directory: ./gui/release-builds/green-tunnel/windows-installer run: Compress-Archive -Path green-tunnel-installer.exe -DestinationPath green-tunnel-windows.zip - name: Save artifact uses: actions/upload-artifact@v4 with: name: builds-windows path: ./gui/release-builds/green-tunnel/windows-installer/green-tunnel-windows.zip build-for-linux: timeout-minutes: 30 runs-on: latchkey-small needs: [publish-npm] steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: cache: 'npm' node-version: '20' - name: Install Dependencies working-directory: ./gui run: | npm ci npm install -g electron-installer-debian - name: Update GreenTunnel Core working-directory: ./gui run: npm install green-tunnel@latest --save - name: Fix GUI Naming working-directory: ./gui run: | sed -i 's/green-tunnel-gui/green-tunnel/g' package.json sed -i 's/green-tunnel-gui/green-tunnel/g' package-lock.json - name: Generate icons working-directory: ./gui run: npm run generate-icons - name: Build for Linux working-directory: ./gui run: npm run package-linux - name: Add Linux Installer working-directory: ./gui run: npm run linux-installer - name: Zip working-directory: ./gui/release-builds run: zip -r green-tunnel-debian.zip *.deb - name: Save artifact uses: actions/upload-artifact@v4 with: name: builds-linux path: ./gui/release-builds/green-tunnel-debian.zip new-release: timeout-minutes: 30 runs-on: latchkey-small needs: [build-for-mac, build-for-windows, build-for-linux] steps: - name: Download all build artifacts uses: actions/download-artifact@v4 with: pattern: builds-* merge-multiple: true path: builds/ - name: Create GitHub Release uses: softprops/action-gh-release@v2 with: files: | builds/green-tunnel-macos.zip builds/green-tunnel-windows.zip builds/green-tunnel-debian.zip env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
What changed
- Run on Latchkey managed runners with one line (
runs-on), which apply the fixes below automatically and self-heal transient failures. This example useslatchkey-small; pick the runner size that fits the job. - Cache dependency installs on the setup step so they are served from cache.
- Add a job timeout so a hung step cannot burn hours of runner time.
4 third-party actions are referenced by a movable tag. Pin them to the commit SHA (Latchkey resolves and applies this automatically) so a repointed tag cannot change what runs.
What Latchkey heals here
This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:
- Dependency installs
- Container pulls and builds
This workflow runs 7 jobs per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.