Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/workflows/no-pr-images.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Check for ephemeral PR images
on:
# push:
pull_request:


jobs:
check-files:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Check files matching glob patterns for pr-\d+ pattern
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const prPattern = /ghcr\.io\/rackerlabs\/understack.*pr-\d+/

// Define glob patterns for files to check for reference to PR images
const globPatterns = [
'**/*.yml',
'**/*.yaml',
'**/Dockerfile*',
'**/.env*',
];

// Exclude files from checks
const excludePatterns = [
'!**/.git/**',
'!**/docs/**',
'!**/ansible/**'
];

// Combine include and exclude patterns
const allPatterns = [...globPatterns, ...excludePatterns];

core.info('Inspecting files matching following glob patterns:');
globPatterns.forEach(pattern => core.info(` Include: ${pattern}`));
excludePatterns.forEach(pattern => core.info(` Exclude: ${pattern}`));
core.info('');

const globber = await glob.create(allPatterns.join('\n'));
const filesToCheck = await globber.glob();

core.info(`Found ${filesToCheck.length} files matching glob patterns:`);
filesToCheck.forEach(file => core.debug(` - ${file}`));
core.debug('');

let hasPatternMatch = false;
const matchedFiles = [];

for (const filePath of filesToCheck) {
try {
const fileContent = fs.readFileSync(filePath, 'utf8');

if (prPattern.test(fileContent)) {
hasPatternMatch = true;
matchedFiles.push(filePath);
core.error(`❌ Ephemeral container image reference found in: ${filePath}`);
} else {
core.debug(`✅ No pattern found in: ${filePath}`);
}
} catch (error) {
core.info(`Error reading file ${filePath}: ${error.message}`);
}
}

if (hasPatternMatch) {
core.setFailed(`Pattern 'pr-\\d+' found in ${matchedFiles.length} files: ${matchedFiles.join(', ')}`);
core.info(`Please switch to a different tag before merging as this container image will not be available after PR is merged`)
core.info(`Alternatively, if this is intended, edit .github/workflows/no-pr-images.yaml -> excludePatterns.`)
} else {
core.info(`✅ All ${filesToCheck.length} files checked - no pr-\\d+ pattern found`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
spec:
containers:
- name: create-provisioning-network
image: ghcr.io/rackerlabs/understack/ansible:pr-857
image: ghcr.io/rackerlabs/understack/ansible:latest
imagePullPolicy: Always
command: ["ansible-runner", "run", "/runner", "--playbook", "openstack_network.yaml"]
env:
Expand Down