Skip to content

Commit 56fce58

Browse files
authored
Fix archive.yml
1 parent ac9ee4c commit 56fce58

1 file changed

Lines changed: 58 additions & 69 deletions

File tree

‎.github/workflows/archive.yml‎

Lines changed: 58 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,70 @@
1-
name: Archive website (pax + gzip + signify)
1+
name: Archive website
22

33
on:
4-
schedule:
5-
- cron: '0 0 * * *' # Once per day at 00:00 UTC
4+
push:
5+
branches:
6+
- main
67
workflow_dispatch:
78

8-
permissions:
9-
contents: write
10-
119
jobs:
1210
archive:
1311
runs-on: ubuntu-latest
14-
name: Archive website on OpenBSD
15-
1612
env:
17-
GH_TOKEN: ${{ github.token }}
18-
SIGNIFY_KEY: ${{ secrets.SIGNIFY_KEY }}
13+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
14+
REPO: ${{ github.repository }}
15+
VM_SSH_USER: runner
16+
VM_SSH_HOST: 127.0.0.1
17+
VM_SSH_PORT: 2224
18+
VM_REPO_DIR: /home/runner/work/${{ github.repository }}
1919

2020
steps:
2121
- name: Checkout repository
22-
uses: actions/checkout@v4
23-
24-
- name: Run archive job in OpenBSD
25-
uses: vmactions/openbsd-vm@v1
26-
with:
27-
usesh: false
28-
envs: 'GH_TOKEN SIGNIFY_KEY'
29-
sync: rsync
30-
copyback: false
31-
prepare: |
32-
pkg_add -I git
33-
34-
run: |
35-
set -e
36-
37-
echo "Running on:"
38-
uname -a
39-
40-
# Repo info
41-
REPO_NAME=$(basename "$GITHUB_REPOSITORY")
42-
ARCHIVE_DIR=archive
43-
TMP_DIR=/tmp/archive
44-
45-
mkdir -p "$TMP_DIR" "$ARCHIVE_DIR"
46-
47-
ARCHIVE="$TMP_DIR/$REPO_NAME.tar.gz"
48-
CHECKSUM="$TMP_DIR/$REPO_NAME.tar.gz.sha256"
49-
SIGNATURE="$TMP_DIR/$REPO_NAME.tar.gz.sig"
50-
51-
rm -f "$ARCHIVE" "$CHECKSUM" "$SIGNATURE"
52-
53-
# Create archive
54-
pax -w -x tar . | gzip -n -9 > "$ARCHIVE"
55-
56-
# Checksum
57-
sha256 -q "$ARCHIVE" > "$CHECKSUM"
58-
59-
# Write signify key (no passphrase)
60-
printf "%s\n" "$SIGNIFY_KEY" > /root/archive.sec
61-
chmod 600 /root/archive.sec
62-
63-
# Sign archive
64-
signify -S -s /root/archive.sec -m "$ARCHIVE"
65-
66-
# Replace archive directory contents
67-
rsync -av --delete "$TMP_DIR/" "$ARCHIVE_DIR/"
68-
69-
# Git config
70-
git config user.name "github-actions[bot]"
71-
git config user.email "github-actions[bot]@users.noreply.github.com"
72-
73-
# Commit changes
22+
uses: actions/checkout@v3
23+
24+
- name: Generate temporary Ed25519 SSH key
25+
id: sshkey
26+
run: |
27+
ssh-keygen -t ed25519 -f $HOME/temp_ed25519 -N "" -q
28+
echo "PRIVATE_KEY=$(cat $HOME/temp_ed25519)" >> $GITHUB_ENV
29+
echo "PUBLIC_KEY=$(cat $HOME/temp_ed25519.pub)" >> $GITHUB_ENV
30+
31+
- name: Add temporary public key to VM
32+
run: |
33+
sshpass -p "$VM_ROOT_PASSWORD" ssh -o StrictHostKeyChecking=no -p $VM_SSH_PORT $VM_SSH_USER@$VM_SSH_HOST \
34+
"mkdir -p ~/.ssh && echo \"$PUBLIC_KEY\" >> ~/.ssh/authorized_keys"
35+
36+
- name: Prepare VM repository
37+
run: |
38+
mkdir -p ~/.ssh
39+
echo "$PRIVATE_KEY" > ~/.ssh/id_ed25519
40+
chmod 600 ~/.ssh/id_ed25519
41+
ssh-keyscan -p $VM_SSH_PORT $VM_SSH_HOST >> ~/.ssh/known_hosts
42+
43+
ssh -p $VM_SSH_PORT $VM_SSH_USER@$VM_SSH_HOST bash -c "'
44+
cd $VM_REPO_DIR || exit 1
45+
git init 2>/dev/null || true
46+
git remote add origin https://x-access-token:${GH_TOKEN}@github.com/${REPO}.git 2>/dev/null || true
47+
git config user.name \"github-actions[bot]\"
48+
git config user.email \"github-actions[bot]@users.noreply.github.com\"
49+
'"
50+
51+
- name: Create archive using pax + gzip
52+
run: |
53+
pax -w -p e archive | gzip > archive.tar.gz
54+
55+
- name: Sync archive to VM and commit
56+
run: |
57+
scp -P $VM_SSH_PORT archive.tar.gz $VM_SSH_USER@$VM_SSH_HOST:$VM_REPO_DIR/
58+
ssh -p $VM_SSH_PORT $VM_SSH_USER@$VM_SSH_HOST bash -c "'
59+
cd $VM_REPO_DIR
60+
gzip -dc archive.tar.gz | pax -r -p e
61+
rm archive.tar.gz
7462
git add archive/
75-
git commit -m "Archive website [skip ci]" || echo "Nothing to commit"
76-
77-
# Push changes using GH_TOKEN
78-
git push https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git main
79-
80-
# Optional: cleanup temporary files
81-
rm -rf "$TMP_DIR"
63+
git commit -m \"Archive website [skip ci]\" || echo \"Nothing to commit\"
64+
GIT_CURL_VERBOSE=1 GIT_TRACE=1 git push origin main || echo \"Push failed or nothing to push\"
65+
'"
66+
67+
- name: Remove temporary SSH key from VM
68+
run: |
69+
ssh -p $VM_SSH_PORT $VM_SSH_USER@$VM_SSH_HOST \
70+
"sed -i \"/$(echo $PUBLIC_KEY | sed 's/[\/&]/\\&/g')/d\" ~/.ssh/authorized_keys"

0 commit comments

Comments
 (0)