Release extension version 0.1.45 (#19) #9
This file contains 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 Release | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- version.json | |
workflow_dispatch: | |
inputs: | |
version: | |
description: "Version to release" | |
required: true | |
jobs: | |
check-version-change: | |
outputs: | |
changed: ${{ steps.check-version.outputs.result }} | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Check if version has changed | |
id: check-version | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const version = '${{ github.event.inputs.version }}' || require('./version.json').version; | |
// Find a release for that version | |
const release = await github.rest.repos.getReleaseByTag({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
tag: `release-v${version}`, | |
}).catch(() => null); | |
// If the release exists, the version has not changed | |
if (release) { | |
console.log(`Version ${version} has an existing release`); | |
console.log(release.data.html_url); | |
core.summary.addLink(`Release v${version}`, release.data.html_url); | |
await core.summary.write(); | |
return "false"; | |
} | |
console.log(`Version ${version} does not have a release`); | |
return true; | |
release: | |
needs: check-version-change | |
if: ${{ needs.check-version-change.outputs.changed == 'true' }} | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
packages: read | |
env: | |
EXT_VERSION: "" # will be set in the workflow | |
outputs: | |
version: ${{ env.EXT_VERSION }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Parse version from package.json | |
run: | | |
echo "EXT_VERSION=$(node -p -e "require('./version.json').version")" >> $GITHUB_ENV | |
- name: Create release and upload release asset | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const fs = require("fs"); | |
const release = await github.rest.repos.createRelease({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
tag_name: "release-v${{ env.EXT_VERSION }}", | |
name: "v${{ env.EXT_VERSION }}", | |
draft: false, | |
prerelease: false | |
}); | |
core.summary.addLink(`Release v${{ env.EXT_VERSION }}`, release.data.html_url); | |
await core.summary.write(); | |
releases-matrix: | |
needs: release | |
name: Release Go Binary | |
runs-on: ubuntu-latest | |
env: | |
EXT_VERSION: ${{ needs.release.outputs.version }} | |
strategy: | |
fail-fast: false | |
matrix: | |
# build and publish in parallel: linux/386, linux/amd64, linux/arm64, windows/386, windows/amd64, darwin/amd64, darwin/arm64 | |
goos: [linux, windows, darwin] | |
goarch: ["386", amd64, arm64] | |
exclude: | |
- goarch: "386" | |
goos: darwin | |
- goarch: arm64 | |
goos: windows | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: wangyoucao577/go-release-action@v1 | |
timeout-minutes: 10 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
goos: ${{ matrix.goos }} | |
goarch: ${{ matrix.goarch }} | |
goversion: "https://dl.google.com/go/go1.21.1.linux-amd64.tar.gz" | |
project_path: "./src" | |
binary_name: "pd-api-service" | |
release_name: "v${{ env.EXT_VERSION }}" | |
build-containers: | |
needs: release | |
env: | |
EXT_VERSION: ${{ needs.release.outputs.version }} | |
name: Build Docker Images | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: docker/setup-buildx-action@v1 | |
- uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./Dockerfile | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: | | |
${{ secrets.DOCKER_USERNAME }}/pd-api-service:latest | |
${{ secrets.DOCKER_USERNAME }}/pd-api-service:${{ env.EXT_VERSION }} | |