Merge branch 'vogler:main' into main

This commit is contained in:
KevinMatt 2023-08-28 11:55:19 +08:00 committed by GitHub
commit 53c6b41579
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 80 additions and 7 deletions

View file

@ -20,6 +20,11 @@ jobs:
-
name: Checkout
uses: actions/checkout@v3
-
name: Set environment variables
run: |
echo "BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
echo "NOW=$(date -R)" >> $GITHUB_ENV # date -Iseconds; date +'%Y-%m-%dT%H:%M:%S'
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
@ -29,6 +34,7 @@ jobs:
-
name: Login to Docker Hub
uses: docker/login-action@v2
# if: ${{ secrets.DOCKERHUB_USERNAME && secrets.DOCKERHUB_TOKEN }}
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
@ -44,8 +50,14 @@ jobs:
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64 # ,linux/arm/v7
push: true
build-args: |
COMMIT=${{ github.sha }}
BRANCH=${{ env.BRANCH }}
NOW=${{ env.NOW }}
platforms: linux/amd64,linux/arm64 # ,linux/arm/v7
tags: |
voglerr/free-games-claimer:latest
ghcr.io/vogler/free-games-claimer:latest
cache-from: type=gha
cache-to: type=gha,mode=max

View file

@ -60,12 +60,19 @@ COPY . .
RUN dos2unix *.sh && chmod +x *.sh
COPY docker-entrypoint.sh /usr/local/bin/
ARG COMMIT=""
ARG BRANCH=""
ARG NOW=""
ENV COMMIT=${COMMIT}
ENV BRANCH=${BRANCH}
ENV NOW=${NOW}
LABEL org.opencontainers.image.title="free-games-claimer" \
org.opencontainers.image.name="free-games-claimer" \
org.opencontainers.image.description="Automatically claims free games on the Epic Games Store, Amazon Prime Gaming and GOG" \
org.opencontainers.image.url="https://github.com/vogler/free-games-claimer" \
org.opencontainers.image.source="https://github.com/vogler/free-games-claimer" \
org.opencontainers.image.revision=${COMMIT_SHA} \
org.opencontainers.image.revision=${COMMIT} \
org.opencontainers.image.ref.name=${BRANCH} \
org.opencontainers.image.base.name="ubuntu:jammy" \
org.opencontainers.image.version="latest"

View file

@ -2,6 +2,10 @@
set -eo pipefail # exit on error, error on any fail in pipe (not just last cmd); add -x to print each cmd; see gist bash_strict_mode.md
echo "Version: https://github.com/vogler/free-games-claimer/tree/${COMMIT}"
[ ! -z $BRANCH ] && [ $BRANCH != "main" ] && echo "Branch: ${BRANCH}"
echo "Build: $NOW"
# Remove chromium profile lock.
# When running in docker and then killing it, on the next run chromium displayed a dialog to unlock the profile which made the script time out.
# Maybe due to changed hostname of container or due to how the docker container kills playwright - didn't check.

10
util.js
View file

@ -108,11 +108,11 @@ export const notify = (html) => new Promise((resolve, reject) => {
const title = cfg.notify_title ? `-t ${cfg.notify_title}` : '';
exec(`apprise ${cfg.notify} -i html '${title}' -b '${html}'`, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
if (error.message.includes('command not found')) {
console.info('Run `pip install apprise`. See https://github.com/vogler/free-games-claimer#notifications');
}
return resolve();
console.log(`error: ${error.message}`);
if (error.message.includes('command not found')) {
console.info('Run `pip install apprise`. See https://github.com/vogler/free-games-claimer#notifications');
}
return resolve();
}
if (stderr) console.error(`stderr: ${stderr}`);
if (stdout) console.log(`stdout: ${stdout}`);

50
version.js Normal file
View file

@ -0,0 +1,50 @@
// check if running the latest version
import {log} from 'console';
import { readFileSync } from 'fs';
import { exec } from 'child_process';
const execp = (cmd) => new Promise((resolve, reject) => {
exec(cmd, (error, stdout, stderr) => {
if (stderr) console.error(`stderr: ${stderr}`);
// if (stdout) console.log(`stdout: ${stdout}`);
if (error) {
console.log(`error: ${error.message}`);
if (error.message.includes('command not found')) {
console.info('Install git to check for updates!');
}
return reject();
}
resolve(stdout.trim());
});
});
const git_main = () => readFileSync('.git/refs/heads/main').toString().trim();
let sha, date;
// if (existsSync('/.dockerenv')) { // did not work
if (process.env.NOVNC_PORT) {
log('Running inside Docker.');
['COMMIT', 'BRANCH', 'NOW'].forEach(v => log(` ${v}:`, process.env[v]));
sha = process.env.COMMIT;
date = process.env.NOW;
} else {
log('Not running inside Docker.');
sha = await execp('git rev-parse HEAD');
date = await execp('git show -s --format=%cD'); // same as format as `date -R` (RFC2822)
// date = await execp('git show -s --format=%ch'); // %ch is same as --date=human (short/relative)
}
const gh = await (await fetch('https://api.github.com/repos/vogler/free-games-claimer/commits/main', {
// headers: { accept: 'application/vnd.github.VERSION.sha' }
})).json();
// log(gh);
log('Local commit:', sha, new Date(date));
log('Online commit:', gh.sha, new Date(gh.commit.committer.date));
if (sha == gh.sha) {
log('Running the latest version!')
} else {
log('Not running the latest version!')
}