Skip to content

Ike expects a version of Telepresence you cannot get (easily) #1296

Ike expects a version of Telepresence you cannot get (easily)

Ike expects a version of Telepresence you cannot get (easily) #1296

Workflow file for this run

name: Release Pull Request
on:
issue_comment:
types: created
jobs:
changelog:
if: |
startsWith(github.event.comment.body, '/changelog')
&& (contains(github.event.comment.author_association, 'MEMBER')
|| contains(github.event.comment.author_association, 'OWNER')
|| contains(github.event.comment.author_association, 'COLLABORATOR'))
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Fetch all tags
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- name: Set GitHub user
env:
GIT_USER: ${{secrets.GIT_USER}}
GIT_EMAIL: ${{secrets.GIT_EMAIL}}
run: |
git config --local user.name "${GIT_USER}"
git config --local user.email "${GIT_EMAIL}"
- name: Checkout PR branch
id: checkout
uses: actions/github-script@v6
with:
github-token: ${{secrets.GH_RELEASE_TOKEN}}
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
const prHead = pr.data.head.sha;
core.setOutput("pr_head", prHead);
core.setOutput("pr_title", pr.data.title.trim());
const result = await github.request("POST /repos/:owner/:repo/statuses/:sha", {
owner: context.repo.owner,
repo: context.repo.repo,
sha: prHead,
context: 'release / changelog',
state: 'pending',
});
const { spawnSync } = require("child_process")
const { status, stderr } = spawnSync(`git fetch origin pull/${pr.data.number}/head:${pr.data.head.ref} && git checkout ${pr.data.head.ref} && git push --set-upstream origin ${pr.data.head.ref}`, {shell: true});
if (status != 0) {
core.exportVariable("STATUS", JSON.stringify({ sha: prHead,
context: 'release / changelog',
state: 'error',
description: 'Failed checking out PR branch',
}));
core.setFailed('Failed checking out PR branch');
}
- name: Validate
id: validation
uses: actions/github-script@v6
with:
github-token: ${{secrets.GH_RELEASE_TOKEN}}
script: |
const prTitle = "${{ steps.checkout.outputs.pr_title }}";
const prTitleWords = prTitle.split(' ');
const version = prTitleWords[prTitleWords.length - 1];
core.setOutput("version", version);
const { spawnSync } = require("child_process");
const { status, stderr } = spawnSync(`./scripts/release/validate.sh ${version}`, {shell: true});
if (status != 0) {
const prHead = "${{ steps.checkout.outputs.pr_head }}";
core.exportVariable("STATUS", JSON.stringify({ sha: prHead,
context: 'release / changelog',
state: 'failure',
description: 'Failed validating release Pull Request',
details: stderr.toString(),
}));
core.setFailed('Validation failed!');
}
- name: Generate changelog
if: success()
uses: actions/github-script@v6
env:
GHC_GITHUB_TOKEN: ${{secrets.GH_RELEASE_TOKEN}}
with:
github-token: ${{secrets.GH_RELEASE_TOKEN}}
script: |
const version = "${{ steps.validation.outputs.version }}";
const prHead = "${{ steps.checkout.outputs.pr_head }}";
const changelogCmd = `sed -i '/changelog:generate/q' docs/modules/ROOT/pages/release_notes/${version}.adoc && $(curl -sL http://git.io/install-ghc | bash -s -- --path-only)/ghc generate -r maistra/istio-workspace --format adoc >> docs/modules/ROOT/pages/release_notes/${version}.adoc`;
const { spawnSync } = require("child_process");
const { status, stderr } = spawnSync(changelogCmd, {shell: true});
if (status != 0) {
core.exportVariable("STATUS", JSON.stringify({ sha: prHead,
context: 'release / changelog',
state: 'failure',
description: 'Failed generating changelog',
details: stderr.toString(),
}));
core.setFailed('Failed generating changelog');
} else {
const pushCmd = `git add . && git commit -m"release: adds changelog for ${version}" -m"/skip-e2e" -m"/skip-build" && git push && git rev-parse --short HEAD`;
const { status, stderr, stdout } = spawnSync(pushCmd, {shell: true});
if (status != 0) {
core.exportVariable("STATUS", JSON.stringify({ sha: prHead,
context: 'release / changelog',
state: 'error',
description: 'Failed committing release changelog',
}));
core.setFailed('Failed committing changelog');
} else {
const { status, stderr, stdout } = spawnSync('echo -n $(git rev-parse HEAD)', {shell: true});
core.exportVariable("STATUS", JSON.stringify({ sha: stdout.toString(),
context: 'release / changelog',
state: 'success',
description: 'Changelog generated',
}));
}
}
- name: Publish job status and comment with details
if: always()
uses: actions/github-script@v6
with:
github-token: ${{secrets.GH_RELEASE_TOKEN}}
script: |
const status = ${{env.STATUS}};
const result = await github.request("POST /repos/:owner/:repo/statuses/:sha", {
owner: context.repo.owner,
repo: context.repo.repo,
sha: status.sha,
context: status.context,
state: status.state,
description: status.description,
target_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}",
});
if (status.details) {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `#### ⚠ ${status.description}\n\n${status.details}`,
});
}
release:
if: |
startsWith(github.event.comment.body, '/release')
&& (contains(github.event.comment.author_association, 'MEMBER')
|| contains(github.event.comment.author_association, 'OWNER')
|| contains(github.event.comment.author_association, 'COLLABORATOR'))
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Fetch all tags
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- name: Set GitHub user
env:
GIT_USER: ${{secrets.GIT_USER}}
GIT_EMAIL: ${{secrets.GIT_EMAIL}}
run: |
git config --local user.name "${GIT_USER}"
git config --local user.email "${GIT_EMAIL}"
- name: Checkout PR branch
id: checkout
uses: actions/github-script@v6
with:
github-token: ${{secrets.GH_RELEASE_TOKEN}}
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
const prHead = pr.data.head.sha;
core.setOutput("pr_head", prHead);
core.setOutput("pr_title", pr.data.title.trim());
const result = await github.request("POST /repos/:owner/:repo/statuses/:sha", {
owner: context.repo.owner,
repo: context.repo.repo,
sha: prHead,
context: 'release / commits',
state: 'pending',
});
const { spawnSync } = require("child_process")
const { status, stderr } = spawnSync(`git fetch origin pull/${pr.data.number}/head:${pr.data.head.ref} && git checkout ${pr.data.head.ref} && git push --set-upstream origin ${pr.data.head.ref}`, {shell: true});
if (status != 0) {
core.exportVariable("STATUS", JSON.stringify({ sha: prHead,
context: 'release / commits',
state: 'error',
description: 'Failed checking out PR branch',
}));
core.setFailed('Failed checking out PR branch');
}
- name: Validate
id: validation
uses: actions/github-script@v6
with:
github-token: ${{secrets.GH_RELEASE_TOKEN}}
script: |
const prTitle = "${{ steps.checkout.outputs.pr_title }}";
const prTitleWords = prTitle.split(' ');
const version = prTitleWords[prTitleWords.length - 1];
core.setOutput("version", version);
const { spawnSync } = require("child_process");
const { status, stderr } = spawnSync(`./scripts/release/validate.sh ${version}`, {shell: true});
if (status != 0) {
const prHead = "${{ steps.checkout.outputs.pr_head }}";
core.exportVariable("STATUS", JSON.stringify({ sha: prHead,
context: 'release / commits',
state: 'failure',
description: 'Failed validating release Pull Request',
details: stderr.toString(),
}));
core.setFailed('Validation failed!');
}
- name: Release commits
uses: actions/github-script@v6
with:
github-token: ${{secrets.GH_RELEASE_TOKEN}}
script: |
const version = "${{ steps.validation.outputs.version }}";
const { spawnSync } = require("child_process");
const { status, stderr} = spawnSync(`./scripts/release/release.sh -v ${version}`, {shell: true});
if (status != 0) {
const prHead = "${{ steps.checkout.outputs.pr_head }}";
core.exportVariable("STATUS", JSON.stringify({ sha: prHead,
context: 'release / commits',
state: 'failure',
description: 'Unable to create release-related commits',
details: stderr.toString(),
}));
core.setFailed(`Release failed!`);
} else {
const { status, stderr, stdout } = spawnSync('echo -n $(git rev-parse HEAD)', {shell: true});
core.exportVariable("STATUS", JSON.stringify({ sha: stdout.toString(),
context: 'release / commits',
state: 'success',
description: 'Additional release-related commits created',
}));
}
- name: Publish job status and comment with details
if: always()
uses: actions/github-script@v6
with:
github-token: ${{secrets.GH_RELEASE_TOKEN}}
script: |
const status = ${{env.STATUS}};
const result = await github.request("POST /repos/:owner/:repo/statuses/:sha", {
owner: context.repo.owner,
repo: context.repo.repo,
sha: status.sha,
context: status.context,
state: status.state,
description: status.description,
target_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}",
});
if (status.details) {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `#### ⚠ ${status.description}\n\n${status.details}`,
});
}
shipit:
if: |
startsWith(github.event.comment.body, '/shipit')
&& (contains(github.event.comment.author_association, 'MEMBER')
|| contains(github.event.comment.author_association, 'OWNER')
|| contains(github.event.comment.author_association, 'COLLABORATOR'))
runs-on: ubuntu-latest
steps:
- name: Populate PR Head
id: pr_head
uses: actions/github-script@v6
with:
github-token: ${{secrets.GH_RELEASE_TOKEN}}
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
core.setOutput("sha", pr.data.head.sha);
- name: Rebase on master
uses: actions/github-script@v6
with:
github-token: ${{secrets.GH_RELEASE_TOKEN}}
script: |
const prHead = "${{ steps.pr_head.outputs.sha }}";
github.request("POST /repos/:owner/:repo/statuses/:sha", {
owner: context.repo.owner,
repo: context.repo.repo,
sha: prHead,
context: 'release / shipit',
state: 'pending',
});
github.rest.pulls.merge({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
merge_method: 'rebase'
}).then(() => {
github.request("POST /repos/:owner/:repo/statuses/:sha", {
owner: context.repo.owner,
repo: context.repo.repo,
sha: prHead,
context: 'release / shipit',
state: 'success',
description: 'New version has been shipped!',
target_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}",
});
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '🎇 🎉 🎆 New version has been shipped! 🚀🚀🚀'
});
}).catch((data) => {
github.request("POST /repos/:owner/:repo/statuses/:sha", {
owner: context.repo.owner,
repo: context.repo.repo,
sha: prHead,
context: 'release / shipit',
state: 'error',
description: `${data.message}`,
target_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}",
});
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `#### ⚠ Failed rebasing release PR\n\n${data.message}`
});
core.setFailed('Release rebase failed!');
});
help:
if: |
startsWith(github.event.comment.body, '/help')
&& (contains(github.event.comment.author_association, 'MEMBER')
|| contains(github.event.comment.author_association, 'OWNER')
|| contains(github.event.comment.author_association, 'COLLABORATOR'))
runs-on: ubuntu-latest
steps:
- name: Comment with docs
id: comment-help
uses: actions/github-script@v6
with:
github-token: ${{secrets.GH_RELEASE_TOKEN}}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "### ℹ️ Available commands\n\n * `/changelog` will append changelog based on the closed PRs since last release to provided release notes.\n\n * `/release` will add release-related commits to this PR on your behalf. \n\n * `/shipit` will rebase everything on master branch and trigger actual release process"
});