Skip to content

Commit

Permalink
release-pr
Browse files Browse the repository at this point in the history
  • Loading branch information
nalchevanidze committed Mar 31, 2022
1 parent 0b4ac84 commit 78de93c
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 52 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/create-release-draft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Prepare Release Changelog
id: changelog
run: |
npm run prepare:release
npm run release:prepare
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -41,14 +41,15 @@ jobs:
run: |
stack sdist
- name: Commit changes
- name: Create Release PR
run: |
git config --global user.name "${{ secrets.USER_NAME }}"
git config --global user.email "${{ secrets.USER_EMAIL }}"
git add .
git status
git commit -m "release-${{ steps.changelog.outputs.version }}"
git push https://${{ secrets.GITHUB_TOKEN }}@github.com/morpheusgraphql/morpheus-graphql.git HEAD:release-${{ steps.changelog.outputs.version }}
npm run release:pr ${{ steps.changelog.outputs.version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create Release Draft
uses: actions/create-release@v1
Expand Down
25 changes: 0 additions & 25 deletions .github/workflows/test-push.yaml

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"check:spelling": "cspell --cache --no-progress '**/*.hs'",
"check:packages": "ts-node scripts/check-packages.ts",
"changelog": "ts-node scripts/changelog.ts",
"prepare:release": "ts-node scripts/prepare-release.ts"
"release:prepare": "ts-node scripts/prepare-release.ts",
"release:pr": "ts-node scripts/release-pr.ts"
},
"devDependencies": {
"@types/js-yaml": "^4.0.5",
Expand Down
12 changes: 5 additions & 7 deletions scripts/lib/changelog/get-pull-requests.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { pluck, uniq } from "ramda";
import { ghApiGQL, GH_ORG, GH_REPO } from "../utils/gq-api";
import { Maybe } from "../utils/types";
import { batchMap, getPRNumber, ghApi } from "../utils/utils";
import { batchMap, getPRNumber } from "../utils/utils";
import { parseLabel, PR_TYPE, SCOPE } from "./pull-request-types";

const githubOrg = "morpheusgraphql";
const githubRepo = "morpheus-graphql";

type AsoccRP = {
number: number;
repository: { nameWithOwner: string };
Expand Down Expand Up @@ -35,9 +33,9 @@ type GithubPR = {
const getGithub =
<O>(f: (_: unknown) => string) =>
async (xs: unknown[]): Promise<O[]> => {
const { repository } = await ghApi(`
const { repository } = await ghApiGQL(`
{
repository(owner: "${githubOrg}", name: "${githubRepo}") {
repository(owner: "${GH_ORG}", name: "${GH_REPO}") {
${xs.map(f).join("\n")}
}
}
Expand Down Expand Up @@ -107,7 +105,7 @@ const getAsoccPR = ({
}: Commit): Maybe<number> => {
const number = associatedPullRequests.nodes.find(
({ repository: { nameWithOwner } }) =>
nameWithOwner === `${githubOrg}/${githubRepo}`
nameWithOwner === `${GH_ORG}/${GH_REPO}`
)?.number;

return number ?? getPRNumber(message);
Expand Down
9 changes: 9 additions & 0 deletions scripts/lib/utils/git.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { execSync } from "child_process";
import { GH_ORG, GH_REPO, GITHUB_TOKEN } from "./gq-api";

const exec = (command: string) =>
execSync(command, {
Expand All @@ -11,4 +12,12 @@ const lastTag = () => exec("git describe --abbrev=0 --tags");
const commitsAfter = (tag: string): string[] =>
exec(`git rev-list --reverse ${tag}..`).split("\n");

export const push = (name: string) => {
exec(`git commit -m "${name}"`);

exec(
`git push https://${GITHUB_TOKEN}@github.com/${GH_ORG}/${GH_REPO}.git HEAD:${name}`
);
};

export { getDate, lastTag, commitsAfter };
27 changes: 27 additions & 0 deletions scripts/lib/utils/gq-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import axios from "axios";

export const GH_ORG = "morpheusgraphql";

export const GH_REPO = "morpheus-graphql";

const { GITHUB_TOKEN } = process.env;

if (!GITHUB_TOKEN) {
throw new Error("missing variable: GITHUB_TOKEN");
}

export const ghApiREST = (path: string, body: {}) =>
axios
.post(`https://api.github.com/${path}`, JSON.stringify(body), {
headers: {
authorization: `Bearer ${GITHUB_TOKEN}`,
"content-type": "application/json",
accept: "Accept: application/vnd.github.v3+json",
},
})
.then(({ data }) => data.data)
.catch((err) => Promise.reject(err.message));

export const ghApiGQL = (query: string) => ghApiREST("graphql", { query });

export { GITHUB_TOKEN };
15 changes: 0 additions & 15 deletions scripts/lib/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import axios from "axios";

const { GITHUB_TOKEN } = process.env;

export const getPRNumber = (msg: string) => {
const num = / \(#(?<prNumber>[0-9]+)\)$/m.exec(msg)?.groups?.prNumber;
return num ? parseInt(num, 10) : undefined;
Expand All @@ -22,17 +18,6 @@ export const batchMap = async <T>(
return (await Promise.all(commitInfoPromises)).flat();
};

export const ghApi = (query: string) =>
axios
.post("https://api.github.com/graphql", JSON.stringify({ query }), {
headers: {
authorization: `Bearer ${GITHUB_TOKEN}`,
"content-type": "application/json",
},
})
.then(({ data }) => data.data)
.catch((err) => Promise.reject(err.message));

export const isKey = <T extends string>(
obj: Record<T, unknown>,
key?: string | null
Expand Down
18 changes: 18 additions & 0 deletions scripts/release-pr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { push } from "./lib/utils/git";
import { ghApiREST, GH_ORG, GH_REPO } from "./lib/utils/gq-api";
import { exit } from "./lib/utils/utils";

const openRelease = (version: string) => {
const branchName = `publish-release-${version}`;

push(branchName);
return ghApiREST(`repos/${GH_ORG}/${GH_REPO}/pulls`, {
head: branchName,
base: "master",
owner: GH_ORG,
repo: GH_REPO,
title: `Publish release ${version}`,
});
};

openRelease(process.argv[2]).catch(exit);

0 comments on commit 78de93c

Please sign in to comment.