这是indexloc提供的服务,不要输入任何密码
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
57 changes: 29 additions & 28 deletions .github/workflows/tagging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
jobs:
check-version-files:
runs-on: ubuntu-latest
name: Find modified VERSION files in the resources and services directories
name: Find modified VERSION files in the helpers, resources, and services directories
outputs:
module-directories: ${{ steps.changed-version-files.outputs.all_changed_files }}
module-count: ${{ steps.changed-version-files.outputs.all_changed_files_count }}
Expand All @@ -25,6 +25,7 @@ jobs:
matrix: true
dir_names: "true"
files: |
helpers/*/VERSION
resources/*/VERSION
services/*/VERSION

Expand All @@ -50,33 +51,33 @@ jobs:
with:
script: |
const fs = require('node:fs');

const moduleDirectory = '${{ matrix.directory }}';
const filename = `${ moduleDirectory }/VERSION`;

core.info(`Processing file "${filename}".`);

try {

const components = moduleDirectory.split('/');
const moduleType = components[0];
const moduleName = components.slice(1).join('/').toLowerCase();

core.info(`Parsing version file for ${moduleType} module "${moduleName}"`);

const version = fs.readFileSync(filename, 'utf8').trim();

core.info(`Validating the contents of ${filename}.`);

// https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
const semverRegex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;

if (semverRegex.test(version)) {

core.info("The VERSION file contains a valid semantic version string.");
const tag = `${moduleName}/${version}`.toLowerCase();
core.info(`The "${tag}" tag will be used for the new version of the module.`);

const data = {
"directory": moduleDirectory,
"filename": filename,
Expand All @@ -85,23 +86,23 @@ jobs:
"type": moduleType,
"version": version
};

core.exportVariable('MODULE_VERSION', JSON.stringify(data));

} else {

// Add an error for the invalid value and decorate the code in the PR by including an annotation.
core.error("A version file must contain exactly one valid semantic version string as defined at https://semver.org/.", {
title: "Invalid VERSION file",
file: filename,
startLine: 0,
startColumn: 0
});

// Ensure the step fails by using a non-zero return value.
process.exitCode = 1;
}

} catch (err) {
core.setFailed(err);
}
Expand All @@ -114,14 +115,14 @@ jobs:
script: |
const m = JSON.parse(process.env.MODULE_VERSION);
try {

await github.rest.git.getRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `tags/${ m.tag }`
});


const errorMessage = `Version ${m.version} of the ${m.type} module "${m.name}" cannot be created because the Git tag "${ m.tag}" already exists. Change the contents of the file to a different version if you intend to create a new Git tag.`;
// The error method is used instead of setFailed method so that the code can be annotated.
core.error(errorMessage, {
Expand All @@ -130,10 +131,10 @@ jobs:
startLine: 0,
startColumn: 0
});

// Set the exit code to a non-zero value to fail the step.
process.exitCode = 1;

} catch (err) {
if (err.status == 404) {
core.info(`The "${m.tag}" Git tag does not exist. A new Github release and Git tag will be created.`)
Expand All @@ -147,9 +148,9 @@ jobs:
with:
retries: '3'
script: |

const m = JSON.parse(process.env.MODULE_VERSION);

const sourceUrl = `git::ssh://git@github.com/${{ github.repository }}//${m.directory}?ref=${m.tag}`;
const name = m.tag;
const tag = m.tag;
Expand All @@ -159,11 +160,11 @@ jobs:
To use this version of the module, set the \`source\` argument of the module call to the following value.
\`${sourceUrl}\`.

This release was generated by [run ${{ github.run_number }} of the "${{ github.workflow }}" workflow](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) in response to pull request #${{ github.event.number }}.
This release was generated by [run ${{ github.run_number }} of the "${{ github.workflow }}" workflow](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) after pull request #${{ github.event.number }} was merged.
`;

if (context.payload.pull_request.state == 'closed') {

await github.rest.repos.createRelease({
body: body,
name: name,
Expand All @@ -172,7 +173,7 @@ jobs:
tag_name: tag,
target_commitish: '${{ github.sha }}'
});

} else {
core.notice(`The "${name}" Github release and the "${tag}" Git tag will not be created until the pull request has been merged.`);
core.info("The following is a preview of the release body.");
Expand Down
2 changes: 1 addition & 1 deletion resources/module-b/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.0
1.1.1
Loading