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 0aa37e6
Show file tree
Hide file tree
Showing 7 changed files with 387 additions and 0 deletions.
97 changes: 97 additions & 0 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
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: npm ci
working-directory: ./grab
- name: Install Playwright Browsers
working-directory: ./grab
run: npx playwright install --with-deps
- id: get-version
working-directory: ./grab
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.outputs.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: sudo apt install -y wget2
- run: mkdir -p grab/out
- run: npm ci
working-directory: ./grab
- name: Install Playwright Browsers
working-directory: ./grab
run: npx playwright install --with-deps
- id: download-photo
working-directory: ./grab/out
run: |
wget2 --cut-file-get-vars $(npx ts-node ../grab.ts photo)
- id: download-designer
working-directory: ./grab/out
run: |
wget2 --cut-file-get-vars $(npx ts-node ../grab.ts designer)
- id: download-publisher
working-directory: ./grab/out
run: |
wget2 --cut-file-get-vars $(npx ts-node ../grab.ts publisher)
- id: hash-photo
working-directory: ./grab/out
run: |
echo "photo-hash=$(nix-hash --type sha256 ./affinity-photo-msi-*.exe)" >> $GITHUB_OUTPUT
- id: hash-designer
working-directory: ./grab/out
run: |
echo "designer-hash=$(nix-hash --type sha256 ./affinity-designer-msi-*.exe)" >> $GITHUB_OUTPUT
- id: hash-publisher
working-directory: ./grab/out
run: |
echo "publisher-hash=$(nix-hash --type sha256 ./affinity-publisher-msi-*.exe)" >> $GITHUB_OUTPUT
- 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.photo-hash}}`
designer `${{ steps.hash-designer.outputs.designer-hash}}`
publisher `${{ steps.hash-designer.outputs.publisher-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"
}
}
Loading

0 comments on commit 0aa37e6

Please sign in to comment.