name: update-deps permissions: contents: read concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true on: workflow_dispatch: schedule: - cron: '0 9 * * *' push: branches: - 'master' jobs: update: runs-on: ubuntu-24.04 environment: update-deps # secrets are gated by this environment timeout-minutes: 10 permissions: contents: write pull-requests: write strategy: fail-fast: false matrix: dep: - docker - regctl - undock steps: - name: GitHub auth token from GitHub App id: write-app uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 with: client-id: ${{ secrets.GHACTIONS_REPO_WRITE_APP_ID }} private-key: ${{ secrets.GHACTIONS_REPO_WRITE_APP_PRIVATE_KEY }} owner: docker repositories: setup-docker-action permission-contents: write permission-pull-requests: write - name: Checkout uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: token: ${{ steps.write-app.outputs.token }} fetch-depth: 0 persist-credentials: false - name: Update dependency id: update uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 env: INPUT_DEP: ${{ matrix.dep }} with: script: | const fs = require('fs'); const path = require('path'); const dep = core.getInput('dep', {required: true}); function escapeRegExp(value) { return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); } function tsConstStringPattern(key) { return new RegExp(`^(const ${escapeRegExp(key)} = ')([^']*)(';)$`, 'm'); } async function readJsonFromActionsToolkit(relativePath) { const response = await github.rest.repos.getContent({ owner: 'docker', repo: 'actions-toolkit', path: relativePath, ref: 'main' }); if (Array.isArray(response.data) || response.data.type !== 'file') { throw new Error(`Expected ${relativePath} to be a file`); } return JSON.parse(Buffer.from(response.data.content, response.data.encoding).toString('utf8')); } async function readLatestTag(relativePath) { const tag = (await readJsonFromActionsToolkit(relativePath))?.latest?.tag_name; if (!tag) { throw new Error(`Unable to resolve latest tag from ${relativePath}`); } return tag; } const dependencyConfigs = { docker: { name: 'Docker version', branch: 'deps/docker-version', sourcePath: '.github/docker-releases.json', sourceUrl: 'https://github.com/docker/actions-toolkit/blob/main/.github/docker-releases.json' }, regctl: { name: 'Regctl version', branch: 'deps/regctl-version', sourcePath: '.github/regclient-releases.json', sourceUrl: 'https://github.com/docker/actions-toolkit/blob/main/.github/regclient-releases.json', key: 'regctlDefaultVersion' }, undock: { name: 'Undock version', branch: 'deps/undock-version', sourcePath: '.github/undock-releases.json', sourceUrl: 'https://github.com/docker/actions-toolkit/blob/main/.github/undock-releases.json', key: 'undockDefaultVersion' } }; const config = dependencyConfigs[dep]; if (!config) { core.setFailed(`Unknown dependency ${dep}`); return; } const tag = await readLatestTag(config.sourcePath); const version = dep === 'docker' ? tag.replace(/^docker-/, '') : tag; const targetPath = dep === 'docker' ? '.github/workflows/ci.yml' : 'src/main.ts'; const absolutePath = path.join(process.env.GITHUB_WORKSPACE, targetPath); const content = fs.readFileSync(absolutePath, 'utf8'); const replacements = dep === 'docker' ? [ {pattern: /^( DOCKER_VERSION: )(v\S+)()$/m, version}, {pattern: /^( - )(v\S+)()$/m, version}, {pattern: /^( - type=image,tag=)(\S+)()$/m, version: version.replace(/^v/, '')} ] : [{pattern: tsConstStringPattern(config.key), version}]; let updatedContent = content; let previousVersion; for (const replacement of replacements) { const match = updatedContent.match(replacement.pattern); if (!match) { throw new Error(`Missing ${replacement.pattern} in ${targetPath}`); } previousVersion ??= match[2]; updatedContent = updatedContent.replace(replacement.pattern, (_, prefix, current, suffix) => `${prefix}${replacement.version}${suffix}`); } const changed = updatedContent !== content; if (changed) { fs.writeFileSync( absolutePath, updatedContent, 'utf8' ); core.info(`New ${config.name} ${version} found`); } else { core.info(`No workspace changes needed for ${config.name}`); } core.info(`Resolved ${config.name} from ${config.sourceUrl}`); core.setOutput('changed', String(changed)); core.setOutput('branch', config.branch); core.setOutput('title', `chore(deps): update ${config.name} from ${previousVersion} to ${version}`); core.setOutput('before', previousVersion); core.setOutput('after', version); core.setOutput('source-url', config.sourceUrl); core.setOutput('description', dep === 'docker' ? `This updates the pinned Docker version in \`${targetPath}\` from \`${previousVersion}\` to \`${version}\`, including the binary and image test matrix entries.` : `This updates the pinned default in \`${targetPath}\` from \`${previousVersion}\` to \`${version}\` and refreshes generated \`dist\` content.`); - name: Build if: steps.update.outputs.changed == 'true' && matrix.dep != 'docker' uses: docker/bake-action@59cb1203cd42bcefd40a1b6d73b589e48c86040e # v7.5.0 with: source: . targets: build - name: Create pull request uses: peter-evans/create-pull-request@3ffccacd46053766916f087ce41d627c0b8cf2d1 # v8.1.3 with: base: master branch: ${{ steps.update.outputs.branch }} token: ${{ steps.write-app.outputs.token }} commit-message: ${{ steps.update.outputs.title }} title: ${{ steps.update.outputs.title }} signoff: true sign-commits: true delete-branch: true body: | ${{ steps.update.outputs.description }} The source of truth for this update is ${{ steps.update.outputs.source-url }}.