Skip to content

Commit

Permalink
add update.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
mrshmllow committed Jul 18, 2024
1 parent 66d001c commit d5a8ed4
Show file tree
Hide file tree
Showing 7 changed files with 372 additions and 0 deletions.
82 changes: 82 additions & 0 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Check for Affinity updates

on:
schedule:
- cron: 0 0 * * * # daily
workflow_dispatch:

jobs:
get-current-version:
runs-on: ubuntu-latest
outputs:
current-version: ${{ steps.get-version.outputs.current-version }}
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v27
with:
nix_path: nixpkgs=channel:nixos-unstable
- id: get-version
run: |
echo "current-version=$(nix eval --impure --json --expr 'let nixpkgs = import <nixpkgs> {}; source = nixpkgs.callPackage ./source.nix {}; in source._version')" >> $GITHUB_OUTPUT
get-live-version:
runs-on: ubuntu-latest
outputs:
live-version: ${{ steps.get-version.outputs.live-version }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
- run: pushd grab
- run: npm ci
- id: get-version
run: |
echo "live-version=$(npx ts-node grab.ts version)" >> $GITHUB_OUTPUT
grab-newest:
runs-on: ubuntu-latest
needs:
- get-live-version
- get-current-version
if: ${{needs.get-live-version.outputs.live-version != needs.get-current-version.current-version}}
permissions:
issues: write
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v27
- uses: actions/setup-node@v4
with:
node-version: 18
- run: mkdir -p grab/out && pushd grab
- run: npm ci
- id: download-photo
run: |
wget2 --cut-file-get-vars $(npx ts-node ../grab.ts photo)
- id: download-designer
run: |
wget2 --cut-file-get-vars $(npx ts-node ../grab.ts designer)
- id: download-publisher
run: |
wget2 --cut-file-get-vars $(npx ts-node ../grab.ts publisher)
- id: hash-photo
run: |
echo ::set-output name=hash::$(nix-hash --type sha256 ./affinity-photo-msi-*.exe)
- id: hash-designer
run: |
echo ::set-output name=hash::$(nix-hash --type sha256 ./affinity-designer-msi-*.exe)
- id: hash-publisher
run: |
echo ::set-output name=hash::$(nix-hash --type sha256 ./affinity-publisher-msi-*.exe)
- name: Create Issue
run: |
new_issue_url=$(gh issue create \
--title "bump suite version ${{needs.get-current-version.current-version}} > ${{needs.get-live-version}}" \
--assignee "mrshmllow" \
--label "update" \
--body "$BODY")
env:
BODY: |
## new hashes
photo `${{ steps.hash-photo.outputs.hash}}`
designer `${{ steps.hash-designer.outputs.hash}}`
publisher `${{ steps.hash-designer.outputs.hash}}`
10 changes: 10 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@
"x86_64-linux"
] (system: function nixpkgs.legacyPackages.${system});
in {
devShells = forAllSystems (pkgs: {
default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [nodejs playwright-driver.browsers];
shellHook = ''
export PLAYWRIGHT_BROWSERS_PATH=${pkgs.playwright-driver.browsers}
export PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=true
'';
};
});

packages = forAllSystems (pkgs: let
affinityPath = "$XDG_DATA_HOME/affinity/";
symlink = pkgs.callPackage ./symlink.nix {};
Expand Down
2 changes: 2 additions & 0 deletions grab/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
out/
node_modules/
35 changes: 35 additions & 0 deletions grab/grab.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { chromium, devices } from 'playwright';
import assert from 'node:assert';

(async () => {
const browser = await chromium.launch();
const context = await browser.newContext();
const page = await context.newPage();

const arg = process.argv[2];
let edition = arg;

if (arg === "version") {
edition = "photo";
}

await page.goto(`https://store.serif.com/en-gb/update/windows/${edition}/2/`);

const span = await page.locator("a", {has: page.locator('span:has-text("MSI/EXE (x64) ")')});
const link = await span.getAttribute("href");

await browser.close();

if (arg === "version" && link) {
const regex = /\d+\.\d+\.\d+/;
const match = link.match(regex);

if (!match) return;

console.log(match[0]);

return;
}

console.log(link);
})();
235 changes: 235 additions & 0 deletions grab/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions grab/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": {
"playwright": "1.40.0",
"ts-node": "^10.9.2"
}
}
2 changes: 2 additions & 0 deletions source.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ in {
sha256 = "1rd6ma5idaa88i49mz2d9gl3k1svvpa6sna333p34dbjqdc5y7yq";
url = "https://store.serif.com/en-gb/update/windows/designer/2/";
};

_version = version;
}

0 comments on commit d5a8ed4

Please sign in to comment.