-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: throttle the push flows for slow builds
- Loading branch information
1 parent
f22a0b1
commit 90a89c3
Showing
6 changed files
with
175 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: 'Check if artifact exists' | ||
|
||
inputs: | ||
name: | ||
description: 'Name of the artifact to check' | ||
required: true | ||
|
||
outputs: | ||
exists: | ||
description: 'Whether the artifact exists' | ||
value: ${{ steps.check.outputs.exists }} | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: 'Check if artifact exists' | ||
id: check | ||
env: | ||
ARTIFACT_NAME: ${{ inputs.name }} | ||
REPO: ${{ github.repository }} | ||
shell: bash | ||
#language=bash | ||
run: | | ||
file=$(gh api "repos/$REPO/actions/artifacts" | jq ".artifacts[] | select(.name == \"$ARTIFACT_NAME\")") | ||
if [ -n "$file" ]; then | ||
echo "exists=true" >> $GITHUB_OUTPUT | ||
else | ||
echo "exists=false" >> $GITHUB_OUTPUT | ||
fi |
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,67 @@ | ||
name: 'Schedule workflow run' | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
paths: | ||
- images/prestashop/** | ||
- images/shopware/** | ||
- images/wordpress/** | ||
|
||
jobs: | ||
prepare: | ||
runs-on: ubuntu-22.04 | ||
strategy: | ||
matrix: | ||
image: | ||
- prestashop | ||
- shopware | ||
- wordpress | ||
steps: | ||
- uses: tj-actions/changed-files@v45 | ||
id: changed-files | ||
with: | ||
files: 'images/${{ matrix.image }}/**' | ||
|
||
- name: 'Prepare' | ||
if: steps.changed-files.outputs.test_any_changed == 'true' | ||
id: prepare | ||
env: | ||
IMAGE: ${{ matrix.image }} | ||
shell: bash | ||
#language=bash | ||
run: | | ||
echo "filename=.lock-$IMAGE.txt" >> $GITHUB_OUTPUT | ||
echo "artifact-name=workflow-lock-$IMAGE" >> $GITHUB_OUTPUT | ||
- name: 'Check if lock file exists' | ||
if: steps.changed-files.outputs.test_any_changed == 'true' | ||
uses: ./.github/actions/check-artifact | ||
id: check-lock | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
name: ${{ steps.prepare.outputs.artifact-name }} | ||
|
||
- if: steps.changed-files.outputs.test_any_changed == 'true' && steps.check-lock.outputs.exists == 'true' | ||
shell: bash | ||
#language=bash | ||
run: echo "Lock file already exists." | ||
|
||
- name: 'Create lock file' | ||
if: steps.changed-files.outputs.test_any_changed == 'true' && steps.check-lock.outputs.exists == 'false' | ||
env: | ||
FILENAME: ${{ steps.prepare.outputs.filename }} | ||
shell: bash | ||
#language=bash | ||
run: | | ||
echo "$(date)" > $FILENAME | ||
- name: 'Upload lock artifact' | ||
uses: actions/upload-artifact@v4 | ||
if: steps.changed-files.outputs.test_any_changed == 'true' && steps.check-lock.outputs.exists == 'false' | ||
with: | ||
name: ${{ steps.prepare.outputs.artifact-name}} | ||
path: ${{ steps.prepare.outputs.filename }} |
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,77 @@ | ||
name: 'Trigger scheduled workflows' | ||
|
||
on: | ||
# Run every day at 18:00 UTC | ||
schedule: | ||
- cron: '0 18 * * *' | ||
|
||
# Or trigger manually | ||
workflow_dispatch: | ||
|
||
jobs: | ||
run: | ||
runs-on: ubuntu-22.04 | ||
strategy: | ||
matrix: | ||
image: | ||
- prestashop | ||
- shopware | ||
- wordpress | ||
steps: | ||
- name: 'Prepare' | ||
id: prepare | ||
env: | ||
IMAGE: ${{ matrix.image }} | ||
shell: bash | ||
#language=bash | ||
run: | | ||
echo "filename=.lock-$IMAGE.txt" >> $GITHUB_OUTPUT | ||
echo "artifact-name=workflow-lock-$IMAGE" >> $GITHUB_OUTPUT | ||
- name: 'Check if workflow is already pending' | ||
id: check-lock | ||
env: | ||
ARTIFACT_NAME: ${{ steps.prepare.outputs.artifact-name }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
REPO: ${{ github.repository }} | ||
shell: bash | ||
#language=bash | ||
run: | | ||
file=$(gh api "repos/$REPO/actions/artifacts" | jq ".artifacts[] | select(.name == \"$ARTIFACT_NAME\")") | ||
if [ -n "$file" ]; then | ||
echo "has-lock=true" >> $GITHUB_OUTPUT | ||
else | ||
echo "has-lock=false" >> $GITHUB_OUTPUT | ||
fi | ||
- name: Run actual job | ||
if: steps.check-lock.outputs.has-lock == 'true' | ||
env: | ||
IMAGE: ${{ matrix.image }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
shell: bash | ||
#language=bash | ||
run: | | ||
gh workflow run "build-$IMAGE.yml" | ||
echo "Job 'build-$IMAGE' dispatched." | ||
- name: 'Release the lock' | ||
if: steps.check-lock.outputs.has-lock == 'true' | ||
shell: bash | ||
env: | ||
ARTIFACT_NAME: ${{ steps.prepare.outputs.artifact-name }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
REPO: ${{ github.repository }} | ||
#language=bash | ||
run: | | ||
artifactId=$(gh api "/repos/$REPO/actions/artifacts" --jq ".artifacts[] | select(.name == \"$ARTIFACT_NAME\") | .id") | ||
if [ -n "$artifactId" ]; then | ||
gh api --method DELETE "/repos/$REPO/actions/artifacts/$artifactId" | ||
echo "Lock artifact deleted successfully." | ||
else | ||
echo "No lock artifact found." | ||
exit 1 | ||
fi |