Skip to content

Commit 15f8c51

Browse files
authored
Update GitHub Actions archive workflow
1 parent c48bb18 commit 15f8c51

1 file changed

Lines changed: 19 additions & 22 deletions

File tree

‎.github/workflows/archive.yml‎

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Install dependencies
2424
run: |
2525
sudo apt-get update
26-
sudo apt-get install -y signify-openbsd
26+
sudo apt-get install -y signify-openbsd gh
2727
2828
- name: Create Archive, Checksum, and Signature
2929
run: |
@@ -33,29 +33,33 @@ jobs:
3333
uname -a
3434
3535
REPO_NAME=$(basename "$GITHUB_REPOSITORY")
36-
ARCHIVE_DIR=archive
37-
TMP_DIR=/tmp/archive
36+
ARCHIVE_DIR="$GITHUB_WORKSPACE/archive"
37+
TMP_DIR="$GITHUB_WORKSPACE/tmp_archive"
38+
39+
mkdir -p "$ARCHIVE_DIR"
40+
mkdir -p "$TMP_DIR"
3841
3942
ARCHIVE="$TMP_DIR/$REPO_NAME.tar.gz"
4043
CHECKSUM="$TMP_DIR/$REPO_NAME.tar.gz.sha256"
4144
SIGNATURE="$TMP_DIR/$REPO_NAME.tar.gz.sig"
4245
46+
# Remove old files if they exist
4347
rm -f "$ARCHIVE" "$CHECKSUM" "$SIGNATURE"
4448
45-
# Create tar.gz archive in PAX format
46-
tar --format=pax -cf - . | gzip -n -9 > "$ARCHIVE"
49+
# Create tar.gz archive in PAX format without using a pipe
50+
tar --format=pax -czf "$ARCHIVE" .
4751
4852
# Generate SHA256 checksum
4953
sha256sum "$ARCHIVE" | awk '{print $1}' > "$CHECKSUM"
5054
51-
# Write signify key (from secret, with untrusted comment)
52-
printf "untrusted comment: GitHub Actions archive key\n%s\n" "$SIGNIFY_KEY" > /tmp/archive.sec
53-
chmod 600 /tmp/archive.sec
55+
# Create temporary signify key file
56+
printf "untrusted comment: GitHub Actions archive key\n%s\n" "$SIGNIFY_KEY" > "$TMP_DIR/archive.sec"
57+
chmod 600 "$TMP_DIR/archive.sec"
5458
5559
# Sign the archive
56-
signify-openbsd -S -s /tmp/archive.sec -m "$ARCHIVE"
60+
signify-openbsd -S -s "$TMP_DIR/archive.sec" -m "$ARCHIVE"
5761
58-
# Copy archive files to repo archive directory
62+
# Copy archive files to the repo's archive directory
5963
rsync -av --delete "$TMP_DIR/" "$ARCHIVE_DIR/"
6064
6165
- name: Commit and Push Changes via GitHub CLI
@@ -65,25 +69,18 @@ jobs:
6569
# Authenticate GitHub CLI
6670
echo "$GH_TOKEN" | gh auth login --with-token
6771
68-
# Create a commit if changes exist
69-
if gh repo view --json defaultBranchRef | grep -q '"name": "main"'; then
70-
BRANCH="main"
71-
else
72-
BRANCH=$(gh repo view --json defaultBranchRef -q '.defaultBranchRef.name')
73-
fi
74-
75-
gh repo clone "$GITHUB_REPOSITORY" temp-repo
76-
cd temp-repo
77-
78-
rsync -av --delete ../archive/ archive/
79-
72+
# Setup git with GitHub CLI
8073
gh auth setup-git
8174
git config user.name "github-actions[bot]"
8275
git config user.email "github-actions[bot]@users.noreply.github.com"
8376
77+
# Commit changes only if there are any
78+
cd "$GITHUB_WORKSPACE"
8479
if [ -n "$(git status --porcelain)" ]; then
8580
git add archive/
8681
git commit -m "Archive website [skip ci]"
82+
# Detect default branch and push
83+
BRANCH=$(gh repo view --json defaultBranchRef -q '.defaultBranchRef.name')
8784
git push origin "$BRANCH"
8885
else
8986
echo "No changes to commit."

0 commit comments

Comments
 (0)