Skip to content

Commit

Permalink
+workflow files
Browse files Browse the repository at this point in the history
  • Loading branch information
yousecjoe committed Jan 20, 2025
1 parent 490fb17 commit 7dc1715
Show file tree
Hide file tree
Showing 10 changed files with 2,012 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/branches.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Check automated branches

on:
pull_request_target:
branches:
- main
- latest
- examples

jobs:
notice:
name: Notice for automated branches
runs-on: ubuntu-latest
steps:
- name: Comment on pull request
uses: actions/github-script@v6
with:
script: |
const {issue:{number:issue_number}, repo:{owner, repo}} = context
github.rest.issues.createComment({issue_number, owner, repo, body:[
"Hello there 👋!",
"",
"It seems you have opened a pull request on either `main`, `latest` or `examples`.",
"These branches are fully-automated and do not accept human contributions.",
"",
"* To contribute to *metrics* code, open a pull request to `master` branch",
"* To contribute to *metrics* presets, open a pull request to `presets` branch",
"",
"Thanks for your cooperation 🦾!"
].join("\n")})
- name: Change base branch
run: exit 1
271 changes: 271 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
name: Continuous integration

on:
push:
branches: [ master ]

jobs:

# Build, test and analyze
build-test-analyze:
name: Build, test and analyze
if: "!contains(github.event.head_commit.message, '[skip test]')"
uses: lowlighter/metrics/.github/workflows/test.yml@master

# Format code
format:
name: Format code
runs-on: ubuntu-latest
needs: [ build-test-analyze ]
if: always() && (needs.build-test-analyze.result == 'success' || needs.build-test-analyze.result == 'skipped')
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Checkout master
run: git checkout master
- name: Format code
run: |
npm install -g dprint
mkdir -v -p /home/runner/.cache/dprint/cache
npx dprint fmt --config .github/config/dprint.json
- name: Publish formatted code
run: |
set +e
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
git add --all
git commit -m "chore: code formatting"
git push
set -e
# Update plugins and template indexes, along with README.md
update-indexes:
name: Publish rebuilt metrics indexes
runs-on: ubuntu-latest
needs: [ format ]
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup NodeJS
uses: actions/setup-node@v3
with:
node-version: 20
- name: Pull changes
run: |
git checkout master
git pull
- name: Setup metrics
run: npm ci
- name: Publish rebuild metrics indexes
run: npm run build -- publish

# Rebase main branch on master
update-main:
name: Rebase main on master
runs-on: ubuntu-latest
needs: [ update-indexes ]
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup NodeJS
uses: actions/setup-node@v3
with:
node-version: 20
- name: Pull
run: git pull
- name: Checkout main
run: git checkout main
- name: Rebase main on master
run: git merge master
- name: Push main
run: git push origin main

# Build docker image from master and publish it to GitHub registry
docker-master:
name: Publish master to GitHub registry
runs-on: ubuntu-latest
needs: [ update-indexes ]
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Login to GitHub registry
run: echo ${{ github.token }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Build docker image
run: docker build -t ghcr.io/lowlighter/metrics:master .
- name: Publish to GitHub registry
run: docker push ghcr.io/lowlighter/metrics:master
- name: Tag docker image (beta) and publish to GitHub registry
run: |
set +e
METRICS_VERSION=$(cat package.json | grep -Po '(?<="version": ")\d+[.]\d+(?=[.]0-beta")')
METRICS_VERSION_BETA="$METRICS_VERSION-beta"
set -e
if [[ ! -z "$METRICS_VERSION" ]]; then
echo "Beta version: v$METRICS_VERSION_BETA"
docker tag ghcr.io/lowlighter/metrics:master ghcr.io/lowlighter/metrics:$(echo "v$METRICS_VERSION_BETA")
docker push ghcr.io/lowlighter/metrics:$(echo "v$METRICS_VERSION_BETA")
fi
- name: Tag docker image (main) and publish to GitHub registry
run: |
docker tag ghcr.io/lowlighter/metrics:master ghcr.io/lowlighter/metrics:main
docker push ghcr.io/lowlighter/metrics:main
# Deploy to beta-metrics.lecoq.io
deploy-master:
name: Deploy lowlighter/metrics@master
runs-on: ubuntu-latest
needs: [ docker-master ]
steps:
- name: Deploy web instance
run: "curl -X POST -H 'Authorization: ${{ secrets.WEB_DEPLOY_BETA_TOKEN }}' https://beta-metrics.lecoq.io/.control/stop"
- name: Wait for redeploy
run: sleep 120
- name: Check deployment status
run: "curl --retry 15 --retry-delay 60 https://beta-metrics.lecoq.io/.version"

# Test lowlighter/metrics@master
action-master-test:
name: Test lowlighter/metrics@master
runs-on: ubuntu-latest
needs: [ docker-master ]
steps:
- name: Run tests
uses: lowlighter/metrics@master
with:
token: MOCKED_TOKEN
plugins_errors_fatal: yes
dryrun: yes
use_mocked_data: yes
verify: yes

# Publish examples
publish-examples:
name: Publish examples
needs: [ action-master-test ]
uses: lowlighter/metrics/.github/workflows/examples.yml@master
secrets:
METRICS_TOKEN: ${{ secrets.METRICS_TOKEN }}
METRICS_TOKEN_WITH_SCOPES: ${{ secrets.METRICS_TOKEN_WITH_SCOPES }}
METRICS_TOKEN_PERSONAL: ${{ secrets.METRICS_TOKEN_PERSONAL }}
CHESS_TOKEN: ${{ secrets.CHESS_TOKEN }}
PAGESPEED_TOKEN: ${{ secrets.PAGESPEED_TOKEN }}
GOOGLE_MAP_TOKEN: ${{ secrets.GOOGLE_MAP_TOKEN }}
SPLATOON_TOKEN: ${{ secrets.SPLATOON_TOKEN }}
SPLATOON_STATINK_TOKEN: ${{ secrets.SPLATOON_STATINK_TOKEN }}
SIXTEEN_PERSONALITIES_URL: ${{ secrets.SIXTEEN_PERSONALITIES_URL }}
SPOTIFY_TOKENS: ${{ secrets.SPOTIFY_TOKENS }}
STOCK_TOKEN: ${{ secrets.STOCK_TOKEN }}
TWITTER_TOKEN: ${{ secrets.TWITTER_TOKEN }}
WAKATIME_TOKEN: ${{ secrets.WAKATIME_TOKEN }}

# Publish examples (presets)
publish-examples-presets:
name: Publish examples (presets)
needs: [ action-master-test ]
uses: lowlighter/metrics/.github/workflows/examples.presets.yml@master

# Build docker image from master and publish it to GitHub registry with release tag
docker-release:
name: Publish release to GitHub registry
runs-on: ubuntu-latest
needs: [ publish-examples ]
if: contains(github.event.head_commit.message, '[release]')
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Login to GitHub registry
run: echo ${{ github.token }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Pull docker image (master)
run: docker pull ghcr.io/lowlighter/metrics:master
- name: Tag docker image (release)
env:
GITHUB_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
run: docker tag ghcr.io/lowlighter/metrics:master ghcr.io/lowlighter/metrics:$(echo $GITHUB_COMMIT_MESSAGE | grep -Po 'v\d+[.]\d+')
- name: Publish release to GitHub registry
env:
GITHUB_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
run: docker push ghcr.io/lowlighter/metrics:$(echo $GITHUB_COMMIT_MESSAGE | grep -Po 'v\d+[.]\d+')
- name: Tag docker image (latest)
run: docker tag ghcr.io/lowlighter/metrics:master ghcr.io/lowlighter/metrics:latest
- name: Publish latest to GitHub registry
run: docker push ghcr.io/lowlighter/metrics:latest

# Rebase latest branch on master
update-latest:
name: Rebase latest on master
runs-on: ubuntu-latest
needs: [ docker-release ]
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup NodeJS
uses: actions/setup-node@v3
with:
node-version: 20
- name: Setup metrics
run: npm ci
- name: Pull
run: git pull
- name: Checkout latest
run: git checkout latest
- name: Rebase latest on master
run: git merge master
- name: Push latest
run: git push origin latest

# Test lowlighter/metrics@latest
action-latest-test:
name: Test lowlighter/metrics@latest
runs-on: ubuntu-latest
needs: [ update-latest ]
steps:
- name: Run tests
uses: lowlighter/metrics@latest
with:
token: MOCKED_TOKEN
plugins_errors_fatal: yes
dryrun: yes
use_mocked_data: yes
verify: yes

# Deploy to metrics.lecoq.io
deploy-latest:
name: Deploy lowlighter/metrics@latest
runs-on: ubuntu-latest
needs: [ docker-release, deploy-master ]
steps:
- name: Deploy web instance
run: "curl -X POST -H 'Authorization: ${{ secrets.WEB_DEPLOY_TOKEN }}' https://metrics.lecoq.io/.control/stop"
- name: Wait for redeploy
run: sleep 120
- name: Check deployment status
run: "curl --retry 15 --retry-delay 60 https://metrics.lecoq.io/.version"

# Publish GitHub release
publish-release:
name: Publish release
runs-on: ubuntu-latest
needs: [ action-latest-test, deploy-latest ]
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup NodeJS
uses: actions/setup-node@v3
with:
node-version: 20
- name: Setup metrics
run: npm ci
- name: Publish release
run: node .github/scripts/release.mjs
env:
GITHUB_TOKEN: ${{ github.token }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
21 changes: 21 additions & 0 deletions .github/workflows/clean.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Clean untagged docker images

on:
release:
types:
- published
workflow_dispatch:

jobs:
clean:
name: Clean untagged docker images
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Run script
run: ./delete_ghcr_dangling_images.sh lowlighter metrics
working-directory: .github/actions/ghcr-clean
env:
GITHUB_TOKEN: ${{ secrets.GHCR_BOT_TOKEN }}
27 changes: 27 additions & 0 deletions .github/workflows/examples.presets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Publish examples (presets)
on:
schedule:
- cron: "0 16 1/2 * *"
workflow_dispatch:
workflow_call:
jobs:
examples:
runs-on: ubuntu-latest
if: "github.repository == 'lowlighter/metrics'"
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup NodeJS
uses: actions/setup-node@v3
with:
node-version: 20
- name: Setup metrics
run: npm ci
- name: Publish presets examples
run: npm run presets -- publish
env:
GITHUB_TOKEN: ${{ github.token }}


Loading

1 comment on commit 7dc1715

@github-actions
Copy link

@github-actions github-actions bot commented on 7dc1715 Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

🔴 Please review

See the 📜action log for details.

Unrecognized words (6)

bitcoin
coingecko
dajneem
eur
jpy
usd

Previously acknowledged words that are now absent Fnc gionkunz panosoft
To accept ✔️ these unrecognized words as correct (and remove the previously acknowledged and now absent words), run the following commands

... in a clone of the [email protected]:yousecjoe/metrics.git repository
on the master branch (ℹ️ how do I use this?):

update_files() {
perl -e '
my @expect_files=qw('".github/actions/spelling/expect.txt"');
@ARGV=@expect_files;
my @stale=qw('"$patch_remove"');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
next if /^(?:$re)(?:(?:\r|\n)*$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/actions/spelling/expect.txt";
use File::Path qw(make_path);
use File::Basename qw(dirname);
make_path (dirname($new_expect_file));
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"$patch_add"');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a)."-".$a cmp lc($b)."-".$b} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;
system("git", "add", $new_expect_file);
'
}

comment_json=$(mktemp)
curl -L -s -S \
-H "Content-Type: application/json" \
"https://api.github.com/repos/yousecjoe/metrics/comments/151521553" > "$comment_json"
comment_body=$(mktemp)
jq -r ".body // empty" "$comment_json" | tr -d "\\r" > $comment_body
rm $comment_json

patch_remove=$(perl -ne 'next unless s{^</summary>(.*)</details>$}{$1}; print' < "$comment_body")

patch_add=$(perl -e '$/=undef; $_=<>; if (m{Unrecognized words[^<]*</summary>\n*```\n*([^<]*)```\n*</details>$}m) { print "$1" } elsif (m{Unrecognized words[^<]*\n\n((?:\w.*\n)+)\n}m) { print "$1" };' < "$comment_body")

update_files
rm $comment_body
git add -u
Warnings (2)

See the 📜action log for details.

ℹ️ Warnings Count
ℹ️ limited-references 1
ℹ️ no-newline-at-eof 1

See ℹ️ Event descriptions for more information.

If the flagged items are false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Please sign in to comment.