-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1508 from api3dao/packaging-prevent-merge
Add CI job to enable/disable GH PR merging
- Loading branch information
Showing
6 changed files
with
174 additions
and
19 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import sodium from 'libsodium-wrappers'; | ||
import { Octokit } from '@octokit/core'; | ||
import { go } from '@api3/promise-utils'; | ||
import { logger } from '@api3/airnode-utilities'; | ||
|
||
const OWNER = 'api3dao'; | ||
const REPOSITORY = 'airnode'; | ||
|
||
const toggleMerge = async (flag: boolean) => { | ||
logger.log(`Setting 'ENABLE_MERGE' flag to '${flag}' for repository '${OWNER}/${REPOSITORY}'`); | ||
|
||
const githubToken = process.env.GITHUB_TOKEN; | ||
if (!githubToken) { | ||
throw new Error('Missing GitHub token'); | ||
} | ||
|
||
const octokit = new Octokit({ | ||
auth: githubToken, | ||
}); | ||
|
||
const goPubKey = await go(() => | ||
octokit.request(`GET /repos/${OWNER}/${REPOSITORY}/actions/secrets/public-key`, { | ||
owner: OWNER, | ||
repo: REPOSITORY, | ||
}) | ||
); | ||
if (!goPubKey.success) { | ||
throw new Error(`Can't obtain GitHub repository public key: ${goPubKey.error}`); | ||
} | ||
|
||
const repositoryPublicKey = goPubKey.data.data.key as string; | ||
const repositoryPublicKeyId = goPubKey.data.data.key_id as string; | ||
|
||
logger.log(`Repository public key: ${repositoryPublicKey} with ID ${repositoryPublicKeyId}`); | ||
|
||
const goSodium = await go(() => sodium.ready); | ||
if (!goSodium.success) { | ||
throw new Error(`Can't load the sodium encryption library: ${goSodium.error}`); | ||
} | ||
|
||
// Convert Secret & Base64 key to Uint8Array. | ||
const binKey = sodium.from_base64(repositoryPublicKey, sodium.base64_variants.ORIGINAL); | ||
const binSecret = sodium.from_string(`${flag}`); | ||
|
||
// Encrypt the secret using LibSodium | ||
const encSecret = sodium.crypto_box_seal(binSecret, binKey); | ||
|
||
// Convert encrypted Uint8Array to Base64 | ||
const base64Secret = sodium.to_base64(encSecret, sodium.base64_variants.ORIGINAL); | ||
|
||
const goSecret = await go(() => | ||
octokit.request(`PUT /repos/${OWNER}/${REPOSITORY}/actions/secrets/ENABLE_MERGE`, { | ||
owner: OWNER, | ||
repo: REPOSITORY, | ||
secret_name: 'ENABLE_MERGE', | ||
encrypted_value: base64Secret, | ||
key_id: repositoryPublicKeyId, | ||
}) | ||
); | ||
if (!goSecret.success) { | ||
throw new Error(`Can't update GitHub repository secret: ${goSecret.error}`); | ||
} | ||
}; | ||
|
||
export const enableMerge = () => toggleMerge(true); | ||
export const disableMerge = () => toggleMerge(false); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2398,6 +2398,19 @@ | |
before-after-hook "^2.2.0" | ||
universal-user-agent "^6.0.0" | ||
|
||
"@octokit/core@^4.1.0": | ||
version "4.1.0" | ||
resolved "https://registry.yarnpkg.com/@octokit/core/-/core-4.1.0.tgz#b6b03a478f1716de92b3f4ec4fd64d05ba5a9251" | ||
integrity sha512-Czz/59VefU+kKDy+ZfDwtOIYIkFjExOKf+HA92aiTZJ6EfWpFzYQWw0l54ji8bVmyhc+mGaLUbSUmXazG7z5OQ== | ||
dependencies: | ||
"@octokit/auth-token" "^3.0.0" | ||
"@octokit/graphql" "^5.0.0" | ||
"@octokit/request" "^6.0.0" | ||
"@octokit/request-error" "^3.0.0" | ||
"@octokit/types" "^8.0.0" | ||
before-after-hook "^2.2.0" | ||
universal-user-agent "^6.0.0" | ||
|
||
"@octokit/endpoint@^7.0.0": | ||
version "7.0.2" | ||
resolved "https://registry.yarnpkg.com/@octokit/endpoint/-/endpoint-7.0.2.tgz#11ee868406ba7bb1642e61bbe676d641f79f02be" | ||
|
@@ -2421,6 +2434,11 @@ | |
resolved "https://registry.yarnpkg.com/@octokit/openapi-types/-/openapi-types-13.13.0.tgz#c9bd7fafd41984176a806938e0a56b7c39425014" | ||
integrity sha512-EQ7/LFp2nb1bU5vhLvfEsImi7RvGXp081ytaMRQXDyVcpLpmOCUMafYfHL72BA7wCOnEmJR0LznBS6sCAIlm9Q== | ||
|
||
"@octokit/openapi-types@^14.0.0": | ||
version "14.0.0" | ||
resolved "https://registry.yarnpkg.com/@octokit/openapi-types/-/openapi-types-14.0.0.tgz#949c5019028c93f189abbc2fb42f333290f7134a" | ||
integrity sha512-HNWisMYlR8VCnNurDU6os2ikx0s0VyEjDYHNS/h4cgb8DeOxQ0n72HyinUtdDVxJhFy3FWLGl0DJhfEWk3P5Iw== | ||
|
||
"@octokit/plugin-enterprise-rest@^6.0.1": | ||
version "6.0.1" | ||
resolved "https://registry.yarnpkg.com/@octokit/plugin-enterprise-rest/-/plugin-enterprise-rest-6.0.1.tgz#e07896739618dab8da7d4077c658003775f95437" | ||
|
@@ -2484,6 +2502,13 @@ | |
dependencies: | ||
"@octokit/openapi-types" "^13.11.0" | ||
|
||
"@octokit/types@^8.0.0": | ||
version "8.0.0" | ||
resolved "https://registry.yarnpkg.com/@octokit/types/-/types-8.0.0.tgz#93f0b865786c4153f0f6924da067fe0bb7426a9f" | ||
integrity sha512-65/TPpOJP1i3K4lBJMnWqPUJ6zuOtzhtagDvydAWbEXpbFYA0oMKKyLb95NFZZP0lSh/4b6K+DQlzvYQJQQePg== | ||
dependencies: | ||
"@octokit/openapi-types" "^14.0.0" | ||
|
||
"@opencensus/[email protected]": | ||
version "0.0.9" | ||
resolved "https://registry.yarnpkg.com/@opencensus/core/-/core-0.0.9.tgz#b16f775435ee309433e4126af194d37313fc93b3" | ||
|
@@ -3050,6 +3075,11 @@ | |
"@types/level-errors" "*" | ||
"@types/node" "*" | ||
|
||
"@types/libsodium-wrappers@^0.7.10": | ||
version "0.7.10" | ||
resolved "https://registry.yarnpkg.com/@types/libsodium-wrappers/-/libsodium-wrappers-0.7.10.tgz#a6ebde70d3b4af960fd802af8d0e3c7cfe281eb2" | ||
integrity sha512-BqI9B92u+cM3ccp8mpHf+HzJ8fBlRwdmyd6+fz3p99m3V6ifT5O3zmOMi612PGkpeFeG/G6loxUnzlDNhfjPSA== | ||
|
||
"@types/lodash@^4.14.186": | ||
version "4.14.186" | ||
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.186.tgz#862e5514dd7bd66ada6c70ee5fce844b06c8ee97" | ||
|
@@ -11270,6 +11300,18 @@ libnpmpublish@^6.0.4: | |
semver "^7.3.7" | ||
ssri "^9.0.0" | ||
|
||
libsodium-wrappers@^0.7.10: | ||
version "0.7.10" | ||
resolved "https://registry.yarnpkg.com/libsodium-wrappers/-/libsodium-wrappers-0.7.10.tgz#13ced44cacb0fc44d6ac9ce67d725956089ce733" | ||
integrity sha512-pO3F1Q9NPLB/MWIhehim42b/Fwb30JNScCNh8TcQ/kIc+qGLQch8ag8wb0keK3EP5kbGakk1H8Wwo7v+36rNQg== | ||
dependencies: | ||
libsodium "^0.7.0" | ||
|
||
libsodium@^0.7.0: | ||
version "0.7.10" | ||
resolved "https://registry.yarnpkg.com/libsodium/-/libsodium-0.7.10.tgz#c2429a7e4c0836f879d701fec2c8a208af024159" | ||
integrity sha512-eY+z7hDrDKxkAK+QKZVNv92A5KYkxfvIshtBJkmg5TSiCnYqZP3i9OO9whE79Pwgm4jGaoHgkM4ao/b9Cyu4zQ== | ||
|
||
lines-and-columns@^1.1.6: | ||
version "1.2.4" | ||
resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.2.4.tgz#eca284f75d2965079309dc0ad9255abb2ebc1632" | ||
|