feat: add go-releaser

This commit is contained in:
Jan De Dobbeleer 2021-10-06 21:43:18 +02:00 committed by Jan De Dobbeleer
parent 4cbb3e6cf3
commit 5b5666b5b0
12 changed files with 304 additions and 310 deletions

View file

@ -1,41 +0,0 @@
on:
pull_request:
paths-ignore:
- 'README.md'
- 'CONTRIBUTING.md'
- 'COPYING'
- 'docs/**'
- '.github/*.md'
- '.github/FUNDING.yml'
name: Build Code
jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
goarch: [amd64]
include:
- os: ubuntu-latest
goarch: arm64
- os: ubuntu-latest
goarch: arm
- os: windows-latest
goarch: 386
- os: windows-latest
goarch: arm64
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: ${{ github.workspace }}/src
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Checkout code
uses: actions/checkout@v2
- name: Build
run: go build
env:
GOARCH: ${{ matrix.goarch }}

28
.github/workflows/build.yml vendored Normal file
View file

@ -0,0 +1,28 @@
on:
pull_request:
paths-ignore:
- 'README.md'
- 'CONTRIBUTING.md'
- 'COPYING'
- 'docs/**'
- '.github/*.md'
- '.github/FUNDING.yml'
name: Build Code
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Checkout code
uses: actions/checkout@v2
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
args: build --rm-dist --snapshot
workdir: src

21
.github/workflows/homebrew.yml vendored Normal file
View file

@ -0,0 +1,21 @@
name: Homebrew
on:
release:
types: [published]
jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: Notify Homebrew Repo 🙋🏾‍♀️
uses: actions/github-script@v5
with:
github-token: ${{ secrets.GH_PAT }}
script: |
await github.request('POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches', {
owner: 'jandedobbeleer',
repo: 'homebrew-oh-my-posh',
workflow_id: 'release.yml',
ref: 'main',
inputs: {"version": process.env.GITHUB_REF.replace('refs/tags/v', '')}
})

67
.github/workflows/inno.yml vendored Normal file
View file

@ -0,0 +1,67 @@
name: Inno
on:
release:
types: [published]
jobs:
publish:
runs-on: windows-latest
strategy:
matrix:
arch: [amd64, arm64]
defaults:
run:
shell: pwsh
working-directory: ${{ github.workspace }}/packages/inno
steps:
- name: Checkout code 👋
uses: actions/checkout@v2
- name: Build installer 📦
id: build
run: |
$version = $env:GITHUB_REF.TrimStart("refs/tags/v")
./build.ps1 -Architecture ${{ matrix.arch }} -Version $version
- name: Get release ⬇️
id: get_release
uses: bruceadams/get-release@v1.2.3
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Upload artifacts 🆙
uses: actions/github-script@v5
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
console.log('environment', process.versions);
const fs = require('fs').promises;
const { repo: { owner, repo }, sha } = context;
console.log({ owner, repo, sha });
for (let file of await fs.readdir('./packages/inno/Output')) {
console.log('uploading', file);
await github.rest.repos.uploadReleaseAsset({
owner, repo,
release_id: ${{ steps.get_release.outputs.id }},
name: file,
data: await fs.readFile(`./packages/inno/Output/${file}`)
});
}
notify:
runs-on: ubuntu-latest
needs: publish
steps:
- name: Notify Winget Build 🙋🏾‍♀️
uses: actions/github-script@v5
with:
github-token: ${{ secrets.GH_PAT }}
script: |
await github.request('POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches', {
owner: 'jandedobbeleer',
repo: '${{ github.event.repository.name }}',
workflow_id: 'winget.yml',
ref: 'main',
inputs: {"version": process.env.GITHUB_REF.replace('refs/tags/v', '')}
})

19
.github/workflows/powershell.yml vendored Normal file
View file

@ -0,0 +1,19 @@
name: PowerShell
on:
release:
types: [published]
jobs:
publish:
runs-on: ubuntu-latest
defaults:
run:
shell: pwsh
working-directory: ${{ github.workspace }}/packages/powershell/oh-my-posh
steps:
- name: Checkout code 👋
uses: actions/checkout@v2
- name: Pack & Push 📦
run: |
$version = $env:GITHUB_REF.TrimStart("refs/tags/v")
./deploy.ps1 -ModuleVersion $version -Repository PSGallery -RepositoryAPIKey ${{ secrets.PSGALLERY_KEY }}

View file

@ -7,18 +7,20 @@ on:
paths:
- 'src/**'
- 'packages/**'
- '.github/*'
jobs:
release:
changelog:
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
version: ${{ steps.changelog.outputs.version }}
body: ${{ steps.changelog.outputs.clean_changelog }}
tag: ${{ steps.changelog.outputs.tag }}
skipped: ${{ steps.changelog.outputs.skipped }}
steps:
- name: Checkout code
- name: Checkout code 👋
uses: actions/checkout@v2
- name: Create changelog
- name: Create changelog ✍️
id: changelog
uses: TriPSs/conventional-changelog-action@v3
with:
@ -27,268 +29,53 @@ jobs:
output-file: "false"
skip-commit: "true"
skip-on-empty: "true"
- name: Create Github Release
id: create_release
uses: actions/create-release@v1
if: ${{ steps.changelog.outputs.skipped == 'false' }}
env:
GITHUB_TOKEN: ${{ secrets.github_token }}
with:
tag_name: ${{ steps.changelog.outputs.tag }}
release_name: ${{ steps.changelog.outputs.tag }}
body: ${{ steps.changelog.outputs.clean_changelog }}
artifacts:
needs: release
if: ${{ needs.release.outputs.skipped == 'false' }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
goarch: [amd64]
include:
- os: ubuntu-latest
goarch: arm64
- os: ubuntu-latest
goarch: arm
- os: windows-latest
goarch: 386
- os: windows-latest
goarch: arm64
runs-on: ${{ matrix.os }}
needs: changelog
if: ${{ needs.changelog.outputs.skipped == 'false' }}
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ github.workspace }}/src
outputs:
hash_linux: ${{ steps.hash.outputs.hash_ubuntu-latest }}
hash_macos: ${{ steps.hash.outputs.hash_macos-latest }}
hash_windows: ${{ steps.hash.outputs.hash_windows-latest }}
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Checkout code
uses: actions/checkout@v2
- name: Asset name
id: artifact
run: |
if ($IsLinux) {
$artifact = "posh-linux-${{ matrix.goarch }}"
Write-Output "::set-output name=name::$($artifact)"
return
}
if ($IsMacOS) {
$artifact = "posh-darwin-${{ matrix.goarch }}"
Write-Output "::set-output name=name::$($artifact)"
return
}
if ($IsWindows) {
$artifact = "posh-windows-${{ matrix.goarch }}.exe"
Write-Output "::set-output name=name::$($artifact)"
return
}
shell: pwsh
- name: Build
id: build
run: go build -o ${{ steps.artifact.outputs.name }} -ldflags="-X 'main.Version=${{ needs.release.outputs.version }}'"
env:
GOARCH: ${{ matrix.goarch }}
- name: Hash
id: hash
run: |
$fileHash = Get-FileHash ${{ steps.artifact.outputs.name }} -Algorithm SHA256
$fileHash.Hash | Out-File -Encoding 'UTF8' ${{ steps.artifact.outputs.name }}.sha256
Write-Output "::set-output name=hash_${{ matrix.os }}::$($fileHash.Hash)"
shell: pwsh
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: src/${{ steps.artifact.outputs.name }}
asset_name: ${{ steps.artifact.outputs.name }}
asset_content_type: application/octet-stream
- name: Upload Hash Asset
id: upload-hash-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: src/${{ steps.artifact.outputs.name }}.sha256
asset_name: ${{ steps.artifact.outputs.name }}.sha256
asset_content_type: text/plain
themes:
needs: release
if: ${{ needs.release.outputs.skipped == 'false' }}
runs-on: ubuntu-latest
outputs:
hash_themes: ${{ steps.hash.outputs.hash_themes }}
defaults:
run:
- name: Install Go 🗳
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Checkout code 👋
uses: actions/checkout@v2
- name: Tag HEAD 😸
run: git tag ${{ needs.changelog.outputs.tag }}
- name: Run GoReleaser 🚀
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
args: build --rm-dist
workdir: src
- name: Zip theme files 🤐
run: |
$compress = @{
Path = "../themes/*.omp.json"
CompressionLevel = "Fastest"
DestinationPath = "./dist/themes.zip"
}
Compress-Archive @compress
shell: pwsh
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Zip theme files
run: |
$compress = @{
Path = "themes\*.json"
CompressionLevel = "Fastest"
DestinationPath = "themes.zip"
}
Compress-Archive @compress
- name: Hash
id: hash
run: |
$fileHash = Get-FileHash themes.zip -Algorithm SHA256
$fileHash.Hash | Out-File -Encoding 'UTF8' themes.zip.sha256
Write-Output "::set-output name=hash_themes::$($fileHash.Hash)"
- name: Upload Themes
id: upload-themes
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: themes.zip
asset_name: themes.zip
asset_content_type: application/octet-stream
- name: Upload Themes Hash
id: upload-hash-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: themes.zip.sha256
asset_name: themes.zip.sha256
asset_content_type: text/plain
homebrew:
needs: release
if: ${{ needs.release.outputs.skipped == 'false' }}
runs-on: ubuntu-latest
env:
GH_KEY: ${{ secrets.GH_PAT }}
steps:
- name: Push Version
run: |
curl -XPOST -u "jandedobbeleer:$GH_KEY" \
-H "Accept: application/vnd.github.everest-preview+json" \
-H "Content-Type: application/json" https://api.github.com/repos/jandedobbeleer/homebrew-oh-my-posh/actions/workflows/release.yml/dispatches \
--data '{"ref": "main", "inputs": {"version": "${{ needs.release.outputs.version }}"} }'
powershell:
needs: [release, artifacts]
if: ${{ needs.release.outputs.skipped == 'false' }}
runs-on: ubuntu-latest
defaults:
run:
- name: Add hashes 🤫
run: |
Get-ChildItem ./dist -Exclude *.yaml | Get-Unique |
Foreach-Object {
$zipHash = Get-FileHash $_.FullName -Algorithm SHA256
$zipHash.Hash | Out-File -Encoding 'UTF8' "./dist/$($_.Name).sha256"
}
shell: pwsh
working-directory: ${{ github.workspace }}/packages/powershell/oh-my-posh
env:
PSGALLERY_KEY: ${{ secrets.PSGALLERY_KEY }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Pack and push
run: ./deploy.ps1 -BinVersion ${{ needs.release.outputs.version }} -ModuleVersion ${{ needs.release.outputs.version }} -Repository PSGallery -RepositoryAPIKey $env:PSGALLERY_KEY
scoop:
needs: [release, artifacts]
if: ${{ needs.release.outputs.skipped == 'false' }}
runs-on: ubuntu-latest
defaults:
run:
shell: pwsh
working-directory: ${{ github.workspace }}/packages/scoop
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Update Template
run: ./build.ps1 -Version ${{ needs.release.outputs.version }}
- name: Upload Scoop JSON
id: upload-scoop-json
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ${{ github.workspace }}/packages/scoop/oh-my-posh.json
asset_name: oh-my-posh.json
asset_content_type: text/plain
- name: Upload Scoop Archive
id: upload-scoop-post-install
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ${{ github.workspace }}/packages/scoop/posh-windows-amd64.7z
asset_name: posh-windows-amd64.7z
asset_content_type: application/octet-stream
- name: Upload Scoop Archive Hash
id: upload-scoop-post-install-hash
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ${{ github.workspace }}/packages/scoop/posh-windows-amd64.7z.sha256
asset_name: posh-windows-amd64.7z.sha256
asset_content_type: text/plain
inno:
needs: [release, artifacts]
if: ${{ needs.release.outputs.skipped == 'false' }}
runs-on: windows-latest
strategy:
matrix:
arch: [amd64, arm64]
defaults:
run:
shell: pwsh
working-directory: ${{ github.workspace }}/packages/inno
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Build installer
run: ./build.ps1 -Architecture ${{ matrix.arch }} -Version ${{ needs.release.outputs.version }}
- name: Output Hash
id: hash
run: |
$hash = Get-Content -Path Output/install-${{ matrix.arch }}.exe.sha256
Write-Output "::set-output name=hash_inno_${{ matrix.arch }}::$($hash)"
- name: Upload Inno Installer
id: upload-inno-installer
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ${{ github.workspace }}/packages/inno/Output/install-${{ matrix.arch }}.exe
asset_name: install-${{ matrix.arch }}.exe
asset_content_type: text/plain
- name: Upload Inno Installer Hash
id: upload-inno-installer-hash
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ${{ github.workspace }}/packages/inno/Output/install-${{ matrix.arch }}.exe.sha256
asset_name: install-${{ matrix.arch }}.exe.sha256
asset_content_type: text/plain
winget:
needs: [release, inno]
if: ${{ needs.release.outputs.skipped == 'false' }}
runs-on: windows-latest
defaults:
run:
shell: pwsh
working-directory: ${{ github.workspace }}/packages/winget
env:
WINGETCREATE_TOKEN: ${{ secrets.WINGETCREATE_TOKEN }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Create manifest and submit PR
run: ./build.ps1 -Version ${{ needs.release.outputs.version }} -Token $env:WINGETCREATE_TOKEN
- name: Release 🎓
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.changelog.outputs.tag }}
body: ${{ needs.changelog.outputs.clean_changelog }}
fail_on_unmatched_files: true
token: ${{ secrets.GH_PAT }}
files: |
src/dist/posh-*
src/dist/themes.*

46
.github/workflows/scoop.yml vendored Normal file
View file

@ -0,0 +1,46 @@
name: Scoop
on:
release:
types: [published]
jobs:
publish:
runs-on: ubuntu-latest
defaults:
run:
shell: pwsh
working-directory: ${{ github.workspace }}/packages/scoop
steps:
- name: Checkout code 👋
uses: actions/checkout@v2
- name: Get release ⬇️
id: get_release
uses: bruceadams/get-release@v1.2.3
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Update Template ✍️
run: |
$version = $env:GITHUB_REF.TrimStart("refs/tags/v")
./build.ps1 -Version $version
- name: Upload artifacts 🆙
uses: actions/github-script@v5
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
console.log('environment', process.versions);
const fs = require('fs').promises;
const { repo: { owner, repo }, sha } = context;
console.log({ owner, repo, sha });
for (let file of await fs.readdir('./packages/scoop/dist')) {
console.log('uploading', file);
await github.rest.repos.uploadReleaseAsset({
owner, repo,
release_id: ${{ steps.get_release.outputs.id }},
name: file,
data: await fs.readFile(`./packages/scoop/dist/${file}`)
});
}

24
.github/workflows/winget.yml vendored Normal file
View file

@ -0,0 +1,24 @@
name: Winget
on:
workflow_dispatch:
inputs:
version:
description: 'The latest version'
required: true
jobs:
publish:
runs-on: windows-latest
defaults:
run:
shell: pwsh
working-directory: ${{ github.workspace }}/packages/winget
env:
WINGETCREATE_TOKEN: ${{ secrets.WINGETCREATE_TOKEN }}
steps:
- name: Checkout code 👋
uses: actions/checkout@v2
- name: Create manifest and submit PR 📦
run: |
$version = ${{ github.event.inputs.version }}
./build.ps1 -Version $version -Token $env:WINGETCREATE_TOKEN

3
.gitignore vendored
View file

@ -158,3 +158,6 @@ Output/
# images
*.png
# go releaser
/src/dist

View file

@ -1,8 +1,5 @@
Param
(
[parameter(Mandatory=$true)]
[string]
$BinVersion,
[parameter(Mandatory=$true)]
[string]
$ModuleVersion,

View file

@ -6,6 +6,7 @@ Param
)
New-Item -Path "." -Name "package/bin" -ItemType Directory
New-Item -Path "." -Name "dist" -ItemType "directory"
Copy-Item -Path "../../themes" -Destination "./package" -Recurse
# Download the files and pack them
@ -13,17 +14,20 @@ Copy-Item -Path "../../themes" -Destination "./package" -Recurse
$download = "https://github.com/jandedobbeleer/oh-my-posh/releases/download/v$Version/$($_.name)"
Invoke-WebRequest $download -Out "./package/bin/$($_.outName)"
}
$zipDestination = "./dist/posh-windows-amd64.7z"
$compress = @{
Path = "./package/*"
CompressionLevel = "Fastest"
DestinationPath = "./posh-windows-amd64.7z"
DestinationPath = $zipDestination
}
Compress-Archive @compress
$zipHash = Get-FileHash ./posh-windows-amd64.7z -Algorithm SHA256
$zipHash = Get-FileHash $zipDestination -Algorithm SHA256
$content = Get-Content '.\oh-my-posh.json' -Raw
$content = $content.Replace('<VERSION>', $Version)
$content = $content.Replace('<HASH>', $zipHash.Hash)
$content | Out-File -Encoding 'UTF8' './oh-my-posh.json'
$zipHash.Hash | Out-File -Encoding 'UTF8' 'posh-windows-amd64.7z.sha256'
$content | Out-File -Encoding 'UTF8' './dist/oh-my-posh.json'
$zipHash.Hash | Out-File -Encoding 'UTF8' './dist/posh-windows-amd64.7z.sha256'
Remove-Item ./package/ -Recurse

39
src/.goreleaser.yml Normal file
View file

@ -0,0 +1,39 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
before:
hooks:
- go mod tidy
builds:
-
binary: "posh-{{ .Os }}-{{ .Arch }}"
no_unique_dist_dir: true
ldflags:
- -X main.Version={{.Version}}
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
- arm
- 386
ignore:
- goos: darwin
goarch: 386
- goos: linux
goarch: 386
- goos: darwin
goarch: arm
- goos: windows
goarch: arm
- goos: darwin
goarch: arm64
archives:
- id: oh-my-posh
format: binary
name_template: "posh-{{ .Os }}-{{ .Arch }}"
checksum:
name_template: 'checksums.txt'
changelog:
skip: true