diff --git a/.github/ISSUE_TEMPLATE/compatibility.md b/.github/ISSUE_TEMPLATE/compatibility.md new file mode 100644 index 00000000..d7ef7b88 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/compatibility.md @@ -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 }} diff --git a/.github/actions/check-compatibility.js b/.github/actions/check-compatibility.js new file mode 100644 index 00000000..0978810d --- /dev/null +++ b/.github/actions/check-compatibility.js @@ -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) diff --git a/.github/actions/read-jest-result.js b/.github/actions/read-jest-result.js new file mode 100644 index 00000000..545f27b7 --- /dev/null +++ b/.github/actions/read-jest-result.js @@ -0,0 +1,4 @@ +const {getTestResult, setOutput} = require("./utils") + +const result = getTestResult() +setOutput("result", result) diff --git a/.github/actions/update-compatibility.js b/.github/actions/update-compatibility.js new file mode 100644 index 00000000..4a266b28 --- /dev/null +++ b/.github/actions/update-compatibility.js @@ -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") diff --git a/.github/actions/utils.js b/.github/actions/utils.js new file mode 100644 index 00000000..27304d53 --- /dev/null +++ b/.github/actions/utils.js @@ -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, +} diff --git a/.github/workflows/compatibility-check.yml b/.github/workflows/compatibility-check.yml new file mode 100644 index 00000000..7a3e1e44 --- /dev/null +++ b/.github/workflows/compatibility-check.yml @@ -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 diff --git a/.gitignore b/.gitignore index 05d339b4..a8800cb9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ node_modules dist .DS_Store +coverage diff --git a/compatibility.json b/compatibility.json new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/compatibility.json @@ -0,0 +1 @@ +{} \ No newline at end of file