ci(release): trigger container build and portainer webhook for specific projects and branches

This commit is contained in:
Palm
2024-07-14 09:57:09 +00:00
committed by PalmDevs
parent a4e357c1ef
commit a20f8345b7
10 changed files with 81 additions and 63 deletions

View File

@@ -53,22 +53,10 @@ jobs:
DOCKER_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.REPOSITORY_PUSH_ACCESS }}
WEBSOCKET_API_PORTAINER_WEBHOOK_URL: ${{ secrets.WEBSOCKET_API_PORTAINER_WEBHOOK_URL }}
DISCORD_BOT_PORTAINER_WEBHOOK_URL: ${{ secrets.DISCORD_BOT_PORTAINER_WEBHOOK_URL }}
run: bunx multi-semantic-release
- name: Set Portainer stack webhook URL based on branch
run: |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
PORTAINER_WEBHOOK_URL=${{ secrets.PORTAINER_WEBHOOK_MAIN_URL }}
else
PORTAINER_WEBHOOK_URL=${{ secrets.PORTAINER_WEBHOOK_DEV_URL }}
fi
echo "PORTAINER_WEBHOOK_URL=$PORTAINER_WEBHOOK_URL" >> $GITHUB_ENV
- name: Trigger Portainer stack update
uses: newarifrh/portainer-service-webhook@v1
with:
webhook_url: ${{ env.PORTAINER_WEBHOOK_URL }}
- name: Purge outdated images
uses: snok/container-retention-policy@v3.0.0
with:

View File

@@ -48,7 +48,8 @@
}
],
"clearWorkspace": true
}
},
true
]
]
}

View File

@@ -1,21 +0,0 @@
{
"plugins": [
[
"@codedependant/semantic-release-docker",
{
"dockerImage": "revanced-bot-websocket-api",
"dockerRegistry": "ghcr.io",
"dockerProject": "revanced",
"dockerContext": "../..",
"dockerPlatform": [
"linux/amd64",
"linux/arm64"
],
"dockerArgs": {
"GITHUB_ACTOR": null,
"GITHUB_TOKEN": null
}
}
]
]
}

View File

@@ -0,0 +1,31 @@
import { $ } from 'execa'
const branch = (await $`git rev-parse --abbrev-ref HEAD`).stdout.trim()
export default {
plugins:
branch === 'main'
? [
[
'@codedependant/semantic-release-docker',
{
dockerImage: 'revanced-bot-websocket-api',
dockerRegistry: 'ghcr.io',
dockerProject: 'revanced',
dockerContext: '../..',
dockerPlatform: ['linux/amd64', 'linux/arm64'],
dockerArgs: {
GITHUB_ACTOR: null,
GITHUB_TOKEN: null,
},
},
],
[
'@semantic-release/exec',
{
publishCmd: 'bun run scripts/trigger-portainer-webhook.ts',
},
],
]
: [],
}

View File

@@ -0,0 +1,4 @@
import { $ } from 'bun'
const URLEnvironmentVariableName = 'WEBSOCKET_API_PORTAINER_WEBHOOK_URL'
await $`INPUT_WEBHOOK_URL=${process.env[URLEnvironmentVariableName]} bun run ../../node_modules/portainer-service-webhook/dist`

View File

@@ -1,21 +0,0 @@
{
"plugins": [
[
"@codedependant/semantic-release-docker",
{
"dockerImage": "revanced-bot-discord",
"dockerRegistry": "ghcr.io",
"dockerProject": "revanced",
"dockerContext": "../..",
"dockerPlatform": [
"linux/amd64",
"linux/arm64"
],
"dockerArgs": {
"GITHUB_ACTOR": null,
"GITHUB_TOKEN": null
}
}
]
]
}

View File

@@ -0,0 +1,31 @@
import { $ } from 'execa'
const branch = (await $`git rev-parse --abbrev-ref HEAD`).stdout.trim()
export default {
plugins:
branch === 'main'
? [
[
'@codedependant/semantic-release-docker',
{
dockerImage: 'revanced-bot-discord',
dockerRegistry: 'ghcr.io',
dockerProject: 'revanced',
dockerContext: '../..',
dockerPlatform: ['linux/amd64', 'linux/arm64'],
dockerArgs: {
GITHUB_ACTOR: null,
GITHUB_TOKEN: null,
},
},
],
[
'@semantic-release/exec',
{
publishCmd: 'bun run scripts/trigger-portainer-webhook.ts',
},
],
]
: [],
}

View File

@@ -0,0 +1,4 @@
import { $ } from 'bun'
const URLEnvironmentVariableName = 'DISCORD_BOT_PORTAINER_WEBHOOK_URL'
await $`INPUT_WEBHOOK_URL=${process.env[URLEnvironmentVariableName]} bun run ../../node_modules/portainer-service-webhook/dist`

View File

@@ -34,10 +34,9 @@
"@codedependant/semantic-release-docker": "^5.0.3",
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@revanced/bot-api": "workspace:*",
"@revanced/bot-shared": "workspace:*",
"@saithodev/semantic-release-backmerge": "^4.0.1",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/exec": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^10.1.0",
"@tsconfig/strictest": "^2.0.5",

View File

@@ -1,13 +1,15 @@
diff --git a/lib/multi-semantic-release.js b/lib/multi-semantic-release.js
index 1247e618244dc35f6d60d1e484fbd1a84e504b2a..4b6f1bb5aae5219db2069412f56094af0e33a664 100644
index 1247e618244dc35f6d60d1e484fbd1a84e504b2a..fc8dbf1c418351f2c25698e3fc3fab478693f125 100644
--- a/lib/multi-semantic-release.js
+++ b/lib/multi-semantic-release.js
@@ -114,6 +114,9 @@ async function releasePackage(package_, createInlinePlugin, multiContext, flags)
@@ -114,6 +114,11 @@ async function releasePackage(package_, createInlinePlugin, multiContext, flags)
options.ci = flags.ci === undefined ? options.ci : flags.ci;
options.branches = flags.branches ? castArray(flags.branches) : options.branches;
+ // Patching so plugins from globalOptions are also inherited.
+ // If the third element in the array is set to true, the plugin will not be inherited.
+ options.plugins = [...(multiContext.globalOptions.plugins || []), ...(options.plugins || [])]
+ .filter(plugin => Array.isArray(plugin) ? !plugin[2] : true)
+
// This options are needed for plugins that do not rely on `pluginOptions` and extract them independently.
options._pkgOptions = packageOptions;