mirror of
https://github.com/tenrok/axios.git
synced 2026-06-23 20:40:40 +03:00
chore(ci): fixed release notification action; (#6063)
This commit is contained in:
@@ -0,0 +1,41 @@
|
|||||||
|
name: notify
|
||||||
|
|
||||||
|
on:
|
||||||
|
#workflow_run:
|
||||||
|
# workflows: ["publish"]
|
||||||
|
# types:
|
||||||
|
# - completed
|
||||||
|
#repository_dispatch:
|
||||||
|
# types: [ notify ]
|
||||||
|
release:
|
||||||
|
types: [ published ]
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
tag:
|
||||||
|
required: true
|
||||||
|
jobs:
|
||||||
|
notify:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
#if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
|
||||||
|
steps:
|
||||||
|
#- name: Dump GitHub context
|
||||||
|
# env:
|
||||||
|
# GITHUB_CONTEXT: ${{ toJson(github) }}
|
||||||
|
# run: echo "$GITHUB_CONTEXT"
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: git config
|
||||||
|
run: |
|
||||||
|
git config user.name "${GITHUB_ACTOR}"
|
||||||
|
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
|
||||||
|
- name: Setup node
|
||||||
|
uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 18
|
||||||
|
cache: npm
|
||||||
|
- run: npm ci
|
||||||
|
- name: Notify published PRs
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: node ./bin/actions/notify_published.js --tag ${{ github.event.inputs.tag || github.event.release.tag_name }}
|
||||||
@@ -56,8 +56,3 @@ jobs:
|
|||||||
run: npm publish --provenance --access public
|
run: npm publish --provenance --access public
|
||||||
env:
|
env:
|
||||||
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
|
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
|
||||||
###### NOTIFY & TAG published PRs ######
|
|
||||||
- name: Notify and tag published PRs
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
run: node ./bin/actions/notify_published.js --tag v${{ steps.package-version.outputs.current-version }}
|
|
||||||
|
|||||||
@@ -105,6 +105,18 @@ export default class GithubAPI {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async getLatestTag() {
|
||||||
|
try{
|
||||||
|
const {stdout} = await exec(`git for-each-ref refs/tags --sort=-taggerdate --format='%(refname)' --count=1`);
|
||||||
|
|
||||||
|
return stdout.split('/').pop();
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
static normalizeTag(tag){
|
||||||
|
return tag ? 'v' + tag.replace(/^v/, '') : '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const {prototype} = GithubAPI;
|
const {prototype} = GithubAPI;
|
||||||
|
|||||||
+18
-6
@@ -5,7 +5,7 @@ import fs from "fs/promises";
|
|||||||
import {colorize} from "./helpers/colorize.js";
|
import {colorize} from "./helpers/colorize.js";
|
||||||
import {getReleaseInfo} from "./contributors.js";
|
import {getReleaseInfo} from "./contributors.js";
|
||||||
|
|
||||||
const normalizeTag = (tag) => tag.replace(/^v/, '');
|
const normalizeTag = (tag) => tag ? 'v' + tag.replace(/^v/, '') : '';
|
||||||
|
|
||||||
class RepoBot {
|
class RepoBot {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
@@ -29,7 +29,17 @@ class RepoBot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async notifyPRPublished(id, tag) {
|
async notifyPRPublished(id, tag) {
|
||||||
const pr = await this.github.getPR(id);
|
let pr;
|
||||||
|
|
||||||
|
try {
|
||||||
|
pr = await this.github.getPR(id);
|
||||||
|
} catch (err) {
|
||||||
|
if(err.response?.status === 404) {
|
||||||
|
throw new Error(`PR #${id} not found (404)`);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
tag = normalizeTag(tag);
|
tag = normalizeTag(tag);
|
||||||
|
|
||||||
@@ -41,7 +51,7 @@ class RepoBot {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.github.appendLabels(id, ['v' + tag]);
|
await this.github.appendLabels(id, [tag]);
|
||||||
|
|
||||||
if (isBot || labels.find(({name}) => name === 'automated pr') || (await this.github.isCollaborator(login))) {
|
if (isBot || labels.find(({name}) => name === 'automated pr') || (await this.github.isCollaborator(login))) {
|
||||||
return false;
|
return false;
|
||||||
@@ -56,7 +66,7 @@ class RepoBot {
|
|||||||
author,
|
author,
|
||||||
release: {
|
release: {
|
||||||
tag,
|
tag,
|
||||||
url: `https://github.com/${this.owner}/${this.repo}/releases/tag/v${tag}`
|
url: `https://github.com/${this.owner}/${this.repo}/releases/tag/${tag}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -64,6 +74,8 @@ class RepoBot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async notifyPublishedPRs(tag) {
|
async notifyPublishedPRs(tag) {
|
||||||
|
tag = normalizeTag(tag);
|
||||||
|
|
||||||
const release = await getReleaseInfo(tag);
|
const release = await getReleaseInfo(tag);
|
||||||
|
|
||||||
if (!release) {
|
if (!release) {
|
||||||
@@ -80,9 +92,9 @@ class RepoBot {
|
|||||||
try {
|
try {
|
||||||
console.log(colorize()`${i++}) Notify PR #${pr.id}`)
|
console.log(colorize()`${i++}) Notify PR #${pr.id}`)
|
||||||
const result = await this.notifyPRPublished(pr.id, tag);
|
const result = await this.notifyPRPublished(pr.id, tag);
|
||||||
console.log(result ? 'OK' : 'Skipped');
|
console.log('✔️', result ? 'Label, comment' : 'Label');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn(colorize('green', 'red')` Failed notify PR ${pr.id}: ${err.message}`);
|
console.warn(colorize('green', 'red')`❌ Failed notify PR ${pr.id}: ${err.message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,24 @@
|
|||||||
import minimist from "minimist";
|
import minimist from "minimist";
|
||||||
import RepoBot from '../RepoBot.js';
|
import RepoBot from '../RepoBot.js';
|
||||||
|
import fs from 'fs/promises';
|
||||||
|
|
||||||
const argv = minimist(process.argv.slice(2));
|
const argv = minimist(process.argv.slice(2));
|
||||||
console.log(argv);
|
console.log(argv);
|
||||||
|
|
||||||
const tag = argv.tag;
|
let {tag} = argv;
|
||||||
|
|
||||||
if (!tag) {
|
|
||||||
throw new Error('tag must be specified');
|
|
||||||
}
|
|
||||||
|
|
||||||
const bot = new RepoBot();
|
|
||||||
|
|
||||||
(async() => {
|
(async() => {
|
||||||
|
if (!tag || tag === true) {
|
||||||
|
const {version} = JSON.parse((await fs.readFile('./package.json')).toString());
|
||||||
|
|
||||||
|
tag = 'v' + version;
|
||||||
|
} else if (typeof tag !== 'string') {
|
||||||
|
|
||||||
|
throw new Error('tag must be a string');
|
||||||
|
}
|
||||||
|
|
||||||
|
const bot = new RepoBot();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await bot.notifyPublishedPRs(tag);
|
await bot.notifyPublishedPRs(tag);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import axios from '../index.js';
|
|||||||
|
|
||||||
const {GITHUB_TOKEN} = process.env;
|
const {GITHUB_TOKEN} = process.env;
|
||||||
|
|
||||||
|
GITHUB_TOKEN ? console.log(`[GITHUB_TOKEN OK]`) : console.warn(`[GITHUB_TOKEN is not defined]`);
|
||||||
|
|
||||||
export default axios.create({
|
export default axios.create({
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: GITHUB_TOKEN ? `token ${GITHUB_TOKEN}` : null
|
Authorization: GITHUB_TOKEN ? `token ${GITHUB_TOKEN}` : null
|
||||||
|
|||||||
Reference in New Issue
Block a user