Skip to content

Commit

Permalink
prefix: b
Browse files Browse the repository at this point in the history
  • Loading branch information
dplocki committed Jun 24, 2024
1 parent 12aca92 commit 63a4e45
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 78 deletions.
27 changes: 19 additions & 8 deletions .github/workflows/react_on_all_commits_but.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

steps:

- name: "Getting the sources"
- name: Getting the sources
uses: actions/checkout@v4

- name: Check for prefix in commit messages
Expand All @@ -20,15 +20,26 @@ jobs:
run: |
PREFIX="prefix"
git log --format=%B -n 1 $GITHUB_SHA | grep -q "^$PREFIX"
echo "prefix_found=1" >> $GITHUB_OUTPUT
echo "work!" > a.txt
- node: Prepare Node
uses: actions/setup-node@v4
if: steps.check_prefix.outputs.prefix_found == '1'
with:
node-version: 20

- name: Build README.md
run: |
cd build
npm ci
node bookmarklets.js > ../tmp.md
cd ..
mv tmp.md README.md
- name: React on value
uses: EndBug/add-and-commit@v9
if: steps.check_prefix.outputs.prefix_found == '1'
with:
author_name: Your Name
author_email: mail@example.com
message: 'Your commit message'
add: 'a.txt'

author_name: 🤖 ReadmeGenerator
author_email: readmegenerator@github.com
message: 'chore: update README.md'
add: 'README.md'
83 changes: 13 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,13 @@
# 🥔 Special Octo Potato

This is my blasting field for Github Actions. The place to test workflows, actions their result.

## Notes

* Official help for [GitHub Actions](https://help.github.com/en/actions)
* You cannot use the `alpine` image as `runs-on`
* The only available options can be found on the page: [Virtual Environments for GitHub-hosted Runners](https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners)
* You can use a Docker image
* Job names must start with a letter or `_` and contain only alphanumeric characters, `-`, or `_`
* You can react to tags without declaring the branch
* If you have a syntax error in your workflow file, you lose access to the history of previous builds for that workflow
* The workflow must contain at least one job with no dependencies
* If the cron schedule contains a slash `/` character, it needs to be in quotes
* Scheduled tasks seem to have some delay in starting
* The difference between `github.ref_name` and `GITHUB_REF` while dealing with tag: one return only the tag name, the other the full tag name (with prefix)

### Github NPM Packages

There is possibility for publish npm packages directly on Github (as not scoped repository). See [GitHub Packages: Your packages, at home with their code](https://npm.pkg.github.com).

The usage in workflow is described here: [Publishing Node.js packages](https://docs.github.com/en/actions/guides/publishing-nodejs-packages).

Example set-up code:

```yml
- name: "Set up the NPM"
uses: actions/setup-node@v2
with:
node-version: '16'
registry-url: 'https://npm.pkg.github.com'
scope: '@dplocki'
```
Later usage:
```yml
- name: "Compering version"
run: |
echo `npm info @dplocki/generic-conversation-bot version`
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
```
### Create tag
```yml
- name: Create Tag
uses: negz/create-tag@v1
with:
version: v0.1.1
message: Release for version v0.1.1
token: ${{ secrets.GITHUB_TOKEN }}
```
## Multiline scripts in YML
```yml
run: |
cat << EOF > run.py
echo line 1
echo line 2
; no indents on each of this lines
EOF
```
## Links
* [GitHub Actions to securely publish npm packages](https://snyk.io/blog/github-actions-to-securely-publish-npm-packages/)
# 📚🐙 Bookmarklets library

The repository for keeping bookmarklets.

Unfortunetly on Github's markdown you cannot simply add comfortable links, so you have to drag and drop (on the bookmarks' bar) the code by yourself.

## Bookmarklets

### Explain XKCD

```
javascript:(function()%7Bconst%20url%20%3D%20window.location.href%3B%0A%20%20%20%20const%20regex%20%3D%20%2Fhttps%3A%5C%2F%5C%2Fxkcd%5C.com%5C%2F(%5Cd%2B)%5C%2F%2F%3B%0A%20%20%20%20const%20match%20%3D%20url.match(regex)%3B%0A%0A%20%20%20%20if%20(match)%20%7B%0A%20%20%20%20%20%20%20%20window.location.href%20%3D%20%60https%3A%2F%2Fwww.explainxkcd.com%2Fwiki%2Findex.php%2F%24%7Bmatch%5B1%5D%7D%60%3B%0A%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20%20%20alert('That%20is%20not%20a%20XKCD%20page')%3B%0A%20%20%20%20%7D%7D)()%3B
```
14 changes: 14 additions & 0 deletions bookmarklets/explain_xkcd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
### Explain XKCD
If you are on [xkcd](https://xkcd.com), it will redirect you on the proper subpage on the [explain xkcd wiki](https://www.explainxkcd.com/). Otherwise display the alert.
*/
const url = window.location.href;
const regex = /https:\/\/xkcd\.com\/(\d+)\//;
const match = url.match(regex);

if (match) {
window.location.href = `https://www.explainxkcd.com/wiki/index.php/${match[1]}`;
} else {
alert('That is not a XKCD page');
}
50 changes: 50 additions & 0 deletions build/build_readme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const fs = require('fs');
const path = require('path');
const uglifyJS = require("uglify-js");

function* loadPartOfFile(startToken, endToken, fileName) {
const lines = fs.readFileSync(fileName, 'utf8').split('\n');

let isBlock = !startToken;
for (const line of lines) {
if (!isBlock && line === startToken) {
isBlock = true;
continue;
}

if (isBlock && line === endToken) {
isBlock = false;
return;
}

if (isBlock) {
yield line;
}
}
}

function bookmarklet(bookmarkletFilePath) {
return 'javascript:' + encodeURIComponent('(function(){' + uglifyJS.minify(fs.readFileSync(bookmarkletFilePath, "utf8")).code + '})()');
}

const README_START_MARKER = '## Bookmarklets';
const bookmarkletsDirectory = '../bookmarklets';

let result = [...loadPartOfFile(null, README_START_MARKER, '../README.md'), README_START_MARKER, ''];

for (const fileName of fs.readdirSync(bookmarkletsDirectory)) {
const bookmarkletFilePath = path.join(bookmarkletsDirectory, fileName);

result = result.concat([
...loadPartOfFile('/*', '*/', bookmarkletFilePath),
'',
'```bookmarklet',
bookmarklet(bookmarkletFilePath),
'```',
''
]);
}

for (const line of result) {
console.log(line);
}
24 changes: 24 additions & 0 deletions build/package-lock.json

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

5 changes: 5 additions & 0 deletions build/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"uglify-js": "^3.18.0"
}
}
70 changes: 70 additions & 0 deletions oryginal_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# 🥔 Special Octo Potato

This is my blasting field for Github Actions. The place to test workflows, actions their result.

## Notes

* Official help for [GitHub Actions](https://help.github.com/en/actions)
* You cannot use the `alpine` image as `runs-on`
* The only available options can be found on the page: [Virtual Environments for GitHub-hosted Runners](https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners)
* You can use a Docker image
* Job names must start with a letter or `_` and contain only alphanumeric characters, `-`, or `_`
* You can react to tags without declaring the branch
* If you have a syntax error in your workflow file, you lose access to the history of previous builds for that workflow
* The workflow must contain at least one job with no dependencies
* If the cron schedule contains a slash `/` character, it needs to be in quotes
* Scheduled tasks seem to have some delay in starting
* The difference between `github.ref_name` and `GITHUB_REF` while dealing with tag: one return only the tag name, the other the full tag name (with prefix)

### Github NPM Packages

There is possibility for publish npm packages directly on Github (as not scoped repository). See [GitHub Packages: Your packages, at home with their code](https://npm.pkg.github.com).

The usage in workflow is described here: [Publishing Node.js packages](https://docs.github.com/en/actions/guides/publishing-nodejs-packages).

Example set-up code:

```yml
- name: "Set up the NPM"
uses: actions/setup-node@v2
with:
node-version: '16'
registry-url: 'https://npm.pkg.github.com'
scope: '@dplocki'
```
Later usage:
```yml
- name: "Compering version"
run: |
echo `npm info @dplocki/generic-conversation-bot version`
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
```
### Create tag
```yml
- name: Create Tag
uses: negz/create-tag@v1
with:
version: v0.1.1
message: Release for version v0.1.1
token: ${{ secrets.GITHUB_TOKEN }}
```
## Multiline scripts in YML
```yml
run: |
cat << EOF > run.py
echo line 1
echo line 2
; no indents on each of this lines
EOF
```
## Links
* [GitHub Actions to securely publish npm packages](https://snyk.io/blog/github-actions-to-securely-publish-npm-packages/)

0 comments on commit 63a4e45

Please sign in to comment.