Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSS Support Grant: Milestone 3 - Compatibility Check Workflow #221

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions .github/ISSUE_TEMPLATE/compatibility.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: "Compatibility issue: Flow CLI {{ env.FLOW_VERSION }} and Flow JT {{ env.PACKAGE_VERSION }}"
labels: bug
---

We've identified compatibility issue between following tools:

- FlowCLI v{{ env.FLOW_VERSION }}
- Flow JS Testing v{{ env.PACKAGE_VERSION }}
9 changes: 9 additions & 0 deletions .github/actions/check-compatibility.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const {setOutput, getPackageVersion, checkPrevious} = require("./utils")

const cliVersion = process.env.FLOW_VERSION
const packageVersion = getPackageVersion()
const finish = checkPrevious(cliVersion, packageVersion)

setOutput("cliVersion", cliVersion)
setOutput("packageVersion", packageVersion)
setOutput("finish", finish)
4 changes: 4 additions & 0 deletions .github/actions/read-jest-result.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const {getTestResult, setOutput} = require("./utils")

const result = getTestResult()
setOutput("result", result)
31 changes: 31 additions & 0 deletions .github/actions/update-compatibility.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const fs = require("fs")
const prettier = require("prettier")

const cliVersion = process.env.FLOW_VERSION
const packageVersion = process.env.PACKAGE_VERSION
const result = process.env.TEST_RESULT

const update = () => {
const file = fs.readFileSync("./compatibility.json", "utf-8")
const json = JSON.parse(file)

if (!json[cliVersion]) {
json[cliVersion] = {}
}

json[cliVersion][packageVersion] = {
timestamp: new Date().getTime(),
status: result,
}

const pretty = prettier.format(JSON.stringify(json), {
parser: "json",
})

fs.writeFileSync("./compatibility.json", pretty)
}

update(cliVersion, packageVersion, result)

console.log({cliVersion, packageVersion, result})
console.log("Compatibility file has been updated")
39 changes: 39 additions & 0 deletions .github/actions/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const fs = require("fs")

const setOutput = (name, output) => {
fs.appendFileSync(process.env.GITHUB_OUTPUT, `${name}=${output}\n`, "utf-8")
}

const getPackageVersion = () => {
const file = fs.readFileSync("./package.json", "utf-8")
const packageJSON = JSON.parse(file)

return packageJSON.version
}

const checkPrevious = (cliVersion, packageVersion) => {
const file = fs.readFileSync("./compatibility.json", "utf-8")
const json = JSON.parse(file)

if (json[cliVersion]) {
const checkpoint = json[cliVersion][packageVersion]
return !(!checkpoint || checkpoint.status === "fail")
}

return false
}

const getTestResult = () => {
const pathName = "./jest.result.json"
const file = fs.readFileSync(pathName, "utf-8")
const json = JSON.parse(file)

return json.success
}

module.exports = {
setOutput,
getTestResult,
getPackageVersion,
checkPrevious,
}
87 changes: 87 additions & 0 deletions .github/workflows/compatibility-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Compatibility Check

on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *' # Runs every day at midnight UTC

jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 16

- name: Cache Node.js Modules
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-

- name: Install Flow CLI
run: |
# Install latest Flow CLI
sh -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)"

- name: Get Flow CLI version
id: flowVersion
run: |
echo "flow-version=$(echo | flow version | grep 'Version' | sed 's/[^0-9\.]*//g')" >> $GITHUB_OUTPUT

- name: Check compatibility table
id: compatibility
run: node .github/actions/check-compatibility.js
env:
FLOW_VERSION: ${{ steps.flowVersion.outputs.flow-version }}

- name: Install dependencies and run tests
if: ${{ steps.compatibility.outputs.finish == 'false' }}
continue-on-error: true
run: |
npm ci
npm test -- --json --outputFile=jest.result.json

- name: Set Test Result
if: ${{ steps.compatibility.outputs.finish == 'false' }}
id: jestResult
run: node .github/actions/read-jest-result.js

- name: Test Failed - Create issue
uses: JasonEtco/create-an-issue@v2
if: ${{ steps.jestResult.outputs.result == 'false' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FLOW_VERSION: ${{ steps.compatibility.outputs.cliVersion }}
PACKAGE_VERSION: ${{ steps.compatibility.outputs.packageVersion }}
with:
assignees: MaxStalker
search_existing: all
update_existing: false
filename: .github/ISSUE_TEMPLATE/compatibility.md


- name: Update Compatibility Table
if: ${{ steps.compatibility.outputs.finish == 'false' }}
env:
FLOW_VERSION: ${{ steps.compatibility.outputs.cliVersion }}
PACKAGE_VERSION: ${{ steps.compatibility.outputs.packageVersion }}
TEST_RESULT: ${{ steps.jestResult.outputs.result }}
run: |
# Update table
node .github/actions/update-compatibility.js

# Commit files
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git config --global user.name "${GITHUB_ACTOR}"

git add ./compatibility.json
git commit -m "Updated compatibility table"
git push
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
node_modules
dist
.DS_Store
coverage
1 change: 1 addition & 0 deletions compatibility.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}