Add automated releases
This commit is contained in:
4
.github/index.mjs
vendored
4
.github/index.mjs
vendored
@@ -46,8 +46,8 @@
|
||||
if (mode === "publish") {
|
||||
console.log(`Pushing staged changes: \n${[...staged].map(file => ` - ${file}`).join("\n")}`)
|
||||
const gitted = await git
|
||||
.addConfig("user.name", "GitHub Action")
|
||||
.addConfig("user.email", "<>")
|
||||
.addConfig("user.name", "github-actions[bot]")
|
||||
.addConfig("user.email", "41898282+github-actions[bot]@users.noreply.github.com")
|
||||
.add([...staged])
|
||||
.commit("Auto-regenerate files")
|
||||
.push("origin", "master")
|
||||
|
||||
60
.github/release.mjs
vendored
Normal file
60
.github/release.mjs
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
//Imports
|
||||
import github from "@actions/github"
|
||||
import paths from "path"
|
||||
import url from "url"
|
||||
import sgit from "simple-git"
|
||||
|
||||
//Git setup
|
||||
const __metrics = paths.join(paths.dirname(url.fileURLToPath(import.meta.url)), "..")
|
||||
const git = sgit(__metrics)
|
||||
|
||||
//Setup octokit
|
||||
const token = process.env.GITHUB_TOKEN
|
||||
const rest = github.getOctokit(token)
|
||||
|
||||
//Environment
|
||||
const maintainer = "lowlighter"
|
||||
const repository = process.env.GITHUB_REPOSITORY.match(/^(?<owner>[\s\S]+)[/](?<name>[\s\S]+)$/)?.groups ?? null
|
||||
const version = process.env.GITHUB_COMMIT_MESSAGE.match(/(?<version>v\d+[.]\d+)/)?.groups?.version ?? null
|
||||
|
||||
//Check arguments
|
||||
if ((!repository)||(!repository.name)||(!repository.owner))
|
||||
throw new Error(`Could not parse repository "${process.env.GITHUB_REPOSITORY}"`)
|
||||
console.log(`Repository: ${repository.owner}/${repository.name}`)
|
||||
if (!version)
|
||||
throw new Error(`Could not parse version from "${process.env.GITHUB_COMMIT_MESSAGE}"`)
|
||||
console.log(`Version: ${version}`)
|
||||
|
||||
//Load related issue
|
||||
const {data:{items:issues}} = await rest.search.issuesAndPullRequests({
|
||||
q:`repo:${repository.owner}/${repository.name} is:issue is:open author:${maintainer} assignee:${maintainer} Release ${version} in:title`
|
||||
})
|
||||
|
||||
//Ensure that there is exactly one issue matching
|
||||
if (issues.length < 1)
|
||||
throw new Error(`No matching issues found`)
|
||||
if (issues.length > 1)
|
||||
throw new Error(`Multiple issues found (${issues.length} matching)`)
|
||||
const [patchnote] = issues
|
||||
console.log(`Using issue#${patchnote.number}: ${patchnote.title}`)
|
||||
|
||||
//Check whether release already exists
|
||||
try {
|
||||
const {data:{id}} = await rest.repos.getReleaseByTag({owner:repository.owner, repo:repository.name, tag:version})
|
||||
console.log(`Release ${version} already exists (#${id}), will replace it`)
|
||||
await rest.repos.deleteRelease({owner:repository.owner, repo:repository.name, release_id:id})
|
||||
console.log(`Deleting tag ${version}`)
|
||||
await git.push(["--delete", "origin", version])
|
||||
await new Promise(solve => setTimeout(solve, 15*1000))
|
||||
}
|
||||
catch {
|
||||
console.log(`Release ${version} does not exists yet, will create it`)
|
||||
}
|
||||
|
||||
//Publish release
|
||||
await rest.repos.createRelease({owner:repository.owner, repo:repository.name, tag_name:version, name:`Version ${version}`, body:patchnote.body})
|
||||
console.log(`Successfully published`)
|
||||
|
||||
//Close patchnote issue
|
||||
await rest.issues.update({owner:repository.owner, repo:repository.name, issue_number:patchnote.number, state:"closed"})
|
||||
console.log(`Closed #${patchnote.number}`)
|
||||
46
.github/workflows/workflow.yml
vendored
46
.github/workflows/workflow.yml
vendored
@@ -137,6 +137,31 @@ jobs:
|
||||
- name: Publish latest to GitHub registry
|
||||
run: docker push ghcr.io/lowlighter/metrics:latest
|
||||
|
||||
# Rebase latest branch on master
|
||||
update-latest:
|
||||
name: Rebase latest on master
|
||||
runs-on: ubuntu-latest
|
||||
needs: [ docker-release ]
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/master' && contains(github.event.head_commit.message, '[release]')
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Setup NodeJS
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 15
|
||||
- name: Setup metrics
|
||||
run: npm ci
|
||||
- name: Checkout latest
|
||||
run: git checkout latest
|
||||
- name: Rebase latest on master
|
||||
run: git merge master
|
||||
- name: Push latest
|
||||
run: git push origin latest
|
||||
|
||||
# Test lowlighter/metrics@latest
|
||||
action-latest-test:
|
||||
name: Test lowlighter/metrics@latest
|
||||
@@ -153,6 +178,27 @@ jobs:
|
||||
use_mocked_data: yes
|
||||
verify: yes
|
||||
|
||||
# Publish GitHub release
|
||||
publish-release:
|
||||
name:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [ action-latest-test ]
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/master' && contains(github.event.head_commit.message, '[release]')
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
- name: Setup NodeJS
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 15
|
||||
- name: Setup metrics
|
||||
run: npm ci
|
||||
- name: Publish release
|
||||
run: node .github/release.mjs
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
||||
GITHUB_REPOSITORY: ${{ github.repository }}
|
||||
|
||||
# Deploy to metrics.lecoq.io
|
||||
deploy-master:
|
||||
name: Deploy lowlighter/metrics@master
|
||||
|
||||
Reference in New Issue
Block a user