Skip to content

Commit

Permalink
[releng] Add github workflow
Browse files Browse the repository at this point in the history
Signed-off-by: Laurent Fasani <[email protected]>
  • Loading branch information
lfasani committed Nov 14, 2024
1 parent 70aae3e commit de45b9a
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 0 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Continuous integration

on:
push:
paths-ignore:
- "CHANGELOG.adoc"
- "README.adoc"
- "doc/**"
branches:
- "**"
tags:
- "*"
pull_request:
workflow_dispatch:

jobs:
build:
name: Build
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
packages: write
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name

steps:
- name: Checkout
uses: actions/checkout@v4
if: github.event_name != 'pull_request'
with:
fetch-depth: 0

- name: Checkout
uses: actions/checkout@v4
if: github.event_name == 'pull_request'
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Setup Java SDK
uses: actions/setup-java@v4
with:
java-version: 17
distribution: "temurin"

- name: Setup some global environment variables
run: |
echo "git_describe=$(git describe)" >> $GITHUB_ENV
- name: Build the backend
env:
USERNAME: ${{ github.actor }}
PASSWORD: ${{ secrets.PASSWORD }}
run: mvn -U -B -e clean verify -f backend/pom.xml --settings settings.xml

- name: Publish the backend
if: startsWith(github.ref, 'refs/tags/v')
env:
USERNAME: ${{ github.actor }}
PASSWORD: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: mvn -B deploy -DskipTests --settings settings.xml

44 changes: 44 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Pull Request Checks

on:
pull_request:
paths-ignore:
- "CHANGELOG.adoc"
- "README.adoc"
- "doc/**"
types:
[
opened,
synchronize,
reopened,
labeled,
unlabeled,
milestoned,
demilestoned,
]

jobs:
build:
name: Metadata Review
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup Node SDK
uses: actions/setup-node@v3
with:
node-version: 18.7
registry-url: https://npm.pkg.github.com/

- name: Check that the CHANGELOG has been updated
env:
GITHUB_EVENT: ${{ toJSON(github.event) }}
run: node scripts/check-changelog.js

- name: Check that the copyright of the modified files has been updated
env:
GITHUB_EVENT: ${{ toJSON(github.event) }}
run: node scripts/check-copyright.js
4 changes: 4 additions & 0 deletions scripts/bump-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

VERSION="$1"
mvn versions:set -DgroupId=org.eclipse.sirius -DartifactId="*" -DoldVersion="*" -DnewVersion="$VERSION" -f packages/pom.xml
81 changes: 81 additions & 0 deletions scripts/check-changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*******************************************************************************
* Copyright (c) 2022, 2023 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
const childProcess = require("child_process");
const fs = require("fs");

const workspace = process.env.GITHUB_WORKSPACE;
const event = process.env.GITHUB_EVENT;

const body = JSON.parse(event);
const baseSHA = body.pull_request.base.sha;
const headSHA = body.pull_request.head.sha;

const gitLogCommand = `git log --format=format:%H ${baseSHA}..${headSHA}`;
const result = childProcess.execSync(gitLogCommand, { encoding: "utf8" });
const lines = result.split(/\r?\n/);

console.log("The following commits will be reviewed:");
console.log(lines);
console.log();

const changelog = fs.readFileSync(`${workspace}/CHANGELOG.adoc`, {
encoding: "utf8",
});

const invalidContent =
changelog.includes("<<<<<<<") ||
changelog.includes("=======") ||
changelog.includes(">>>>>>>");

const missingIssuesInChangelog = [];
for (let index = 0; index < lines.length; index++) {
const line = lines[index];
const gitShowCommand = `git rev-list --format=%B --max-count=1 ${line}`;
const commitMessage = childProcess.execSync(gitShowCommand, {
encoding: "utf8",
});
const commitMessageLines = commitMessage.split(/\r?\n/);

if (commitMessageLines.length > 1) {
// Skip the first line which only contains the hash of the commit
const title = commitMessageLines[1];

const tagStartIndex = title.indexOf("[");
const tagEndIndex = title.indexOf("]", tagStartIndex);
if (tagStartIndex >= 0 && tagStartIndex < tagEndIndex) {
const tag = title.substring(tagStartIndex + "[".length, tagEndIndex);

const tagAsNumber = Number(tag);
if (!isNaN(tagAsNumber)) {
const issueURL = `https://github.com/eclipse-sirius/sirius-web/issues/${tagAsNumber}`;

if (!changelog.includes(issueURL)) {
missingIssuesInChangelog.push(issueURL);
}
}
}
}
}

if (missingIssuesInChangelog.length > 0) {
console.log(
"The following issues should appear in the CHANGELOG with some documentation"
);
console.log(missingIssuesInChangelog);
process.exit(1);
} else if (invalidContent) {
console.log(
'The CHANGELOG seems to contain Git conflict markers like "<<<<<<<", "=======" or ">>>>>>>"'
);
process.exit(1);
}
55 changes: 55 additions & 0 deletions scripts/check-copyright.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*******************************************************************************
* Copyright (c) 2022 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
const childProcess = require('child_process');
const fs = require('fs');

const workspace = process.env.GITHUB_WORKSPACE;
const event = process.env.GITHUB_EVENT;

const body = JSON.parse(event);
const baseSHA = body.pull_request.base.sha;
const headSHA = body.pull_request.head.sha;

const gitLogCommand = `git diff --name-only ${baseSHA}...${headSHA}`;
const result = childProcess.execSync(gitLogCommand, { encoding: 'utf8' });
const filePaths = result.split(/\r?\n/);

console.log('The following files will be reviewed:')
console.log(filePaths);
console.log();

const filesWithAnInvalidCopyright = [];
for (let index = 0; index < filePaths.length; index++) {
const filePath = filePaths[index];

if (filePath.endsWith('.java') || filePath.endsWith('.ts') || filePath.endsWith('.tsx') || filePath.endsWith('.js')) {
if (fs.existsSync(filePath)) {
const file = fs.readFileSync(`${workspace}/${filePath}`, { encoding: 'utf8' });
const lines = file.split(/\r?\n/);

if (lines.length > 2 && lines[1].includes('Copyright')) {
const currentYear = new Date().getFullYear();
if (!lines[1].includes(currentYear.toString())) {
console.log(`${filePath} : ${lines[1]}`);
filesWithAnInvalidCopyright.push(filePath);
}
}
}
}
}

if (filesWithAnInvalidCopyright.length > 0) {
console.log('The following files should have their copyright updated');
console.log(filesWithAnInvalidCopyright);
process.exit(1);
}

0 comments on commit de45b9a

Please sign in to comment.