Skip to content

Commit f242731

Browse files
committed
refactor(ci): move scripts out of workflow file
1 parent 71144d6 commit f242731

File tree

6 files changed

+109
-83
lines changed

6 files changed

+109
-83
lines changed

.github/workflows/build.yml

Lines changed: 14 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,13 @@ jobs:
2020
OLD_COMMIT_N: ${{ github.event.inputs.old_commit_n }}
2121
NEW_COMMIT_N: ${{ github.event.inputs.new_commit_n }}
2222
steps:
23-
- name: Detect new commit
24-
run: |
25-
# Check if a new release is needed
26-
if ["$OLD_COMMIT_N" == "$NEW_COMMIT_N" ]; then exit 1; else exit 0; fi
27-
- name: Set env var
23+
- name: Check last version
24+
run: bash ./ci/check-last-version.bash
25+
- name: Checkout the repo
26+
uses: actions/checkout@v2
27+
- name: Set env vars
2828
id: var
29-
run: |
30-
VER=$(curl -s https://raw.githubusercontent.com/flatwhatson/emacs/pgtk-nativecomp/configure.ac | grep AC_INIT | sed -e 's/^.\+\ \([0-9]\+\.[0-9]\+\.[0-9]\+\?\).\+$/\1/')
31-
VER+="."
32-
VER+="$NEW_COMMIT_N"
33-
export VER="${VER}"
34-
echo "::set-output name=ver::${VER}"
29+
run: . ./ci/set-env-vars.bash
3530
outputs:
3631
ver: ${{ steps.var.outputs.ver }}
3732

@@ -46,47 +41,13 @@ jobs:
4641
NEW_COMMIT_N: ${{ github.event.inputs.new_commit_n }}
4742
PKG_VERSION: ${{ needs.check.outputs.ver }}
4843
steps:
44+
- name: Checkout the repo
45+
uses: actions/checkout@v2
4946
- name: Patch glibc
50-
run: |
51-
# Work-around the issue with glibc 2.33 on old Docker engines
52-
# Extract files directly as pacman is also affected by the issue
53-
patched_glibc=glibc-linux4-2.33-4-x86_64.pkg.tar.zst
54-
curl -LO https://repo.archlinuxcn.org/x86_64/$patched_glibc
55-
bsdtar -C / -xvf $patched_glibc
47+
run: bash ./ci/patch-glibc.bash
5648
- name: Prepare artifacts
57-
run: |
58-
cd /home/pcr
59-
60-
# Get sources
61-
./pull.bash
62-
chown -R pcr:pcr emacs
63-
64-
# Create artifacts
65-
su pcr -c "makepkg"
66-
67-
# Unpack artifacts
68-
mkdir out
69-
tar xf emacs-1-1-x86_64.pkg.tar.zst -C out
70-
rm emacs-1-1-x86_64.pkg.tar.zst
71-
rm out/.BUILDINFO out/.MTREE out/.PKGINFO
72-
tar czf "$PKG_VERSION".tar.gz -C out .
73-
74-
# Get release body
75-
delta=$(echo "$NEW_COMMIT_N - $OLD_COMMIT_N" | bc)
76-
echo -en "# Commits since last release\n\n" > body.md
77-
echo -en "Check [upstream](https://github.com/flatwhatson/emacs/commits) for the full history.\n\n" >> body.md
78-
79-
# Get the list of commits since last release
80-
curl -s "$UPSTREAM_GH"/commits?per_page="$delta" | \
81-
# Parse and retain only the commit message + its url
82-
jq -r '.[] | (.commit.message | capture("(?<id>.+)\n").id) + " [commit](" + .html_url + ")"' | \
83-
# Remove "Merge" commits
84-
sed '/^Merge/,+1 d' | \
85-
# Remove any special char at the beginning of the message
86-
sed 's/^[^[:alnum:]]*//' | \
87-
# Prepend "- " to the message
88-
sed -r 's/(.*)/- \1/' >> body.md
89-
- name: Create Release
49+
run: bash ./ci/prepare-artifacts.bash
50+
- name: Create release
9051
id: create_release
9152
uses: actions/create-release@v1
9253
env:
@@ -97,7 +58,7 @@ jobs:
9758
body_path: /home/pcr/body.md
9859
draft: false
9960
prerelease: false
100-
- name: Upload Release Asset
61+
- name: Upload release asset
10162
id: upload-release-asset
10263
uses: actions/upload-release-asset@v1
10364
env:
@@ -107,38 +68,8 @@ jobs:
10768
asset_path: /home/pcr/${{ needs.check.outputs.ver }}.tar.gz
10869
asset_name: ${{ needs.check.outputs.ver }}.tar.gz
10970
asset_content_type: application/gzip
110-
- name: Prepare and push new version to AUR
71+
- name: Push to AUR
11172
env:
11273
PRIV_KEY: ${{ secrets.PRIV_KEY }}
11374
PUB_KEY: ${{ secrets.PUB_KEY }}
114-
run: |
115-
cd /home/pcr
116-
117-
# Checksum artifacts
118-
sum=$(sha512sum "$PKG_VERSION".tar.gz | sed -r 's/(.*)\s\s.*/\1/')
119-
120-
# Setup SSH
121-
mkdir .ssh
122-
echo "$PUB_KEY" | tr -d '\r' > .ssh/id_aur.pub
123-
echo "$PRIV_KEY" | base64 --decode > .ssh/id_aur
124-
chmod 600 .ssh/id_aur
125-
echo -en 'Host aur.archlinux.org\n IdentityFile /home/pcr/.ssh/id_aur\n User aur\n' > .ssh/config
126-
ssh-keyscan aur.archlinux.org > .ssh/known_hosts
127-
ssh-keyscan 95.216.144.15 >> .ssh/known_hosts
128-
129-
# Setup git
130-
alias mygit="git -c user.name=Méril\ Pilon -c user.email=me@mpsq.org"
131-
mygit clone ssh://aur.archlinux.org/emacs-gcc-wayland-devel-bin.git
132-
cd emacs-gcc-wayland-devel-bin
133-
134-
# Amend package, set pkgver, sha512 sum and pkgrel + fix permissions
135-
sed -i -r -e 's~pkgver=.*~pkgver='$PKG_VERSION'~' PKGBUILD
136-
sed -i -r -e 's~sha512sums=.*~sha512sums=\("'"$sum"'"\)~' PKGBUILD
137-
sed -i -r -e 's/pkgrel=.*/pkgrel=1/' PKGBUILD
138-
rm .SRCINFO
139-
su pcr -c "makepkg --printsrcinfo > .SRCINFO"
140-
141-
# Push changes
142-
mygit add .SRCINFO PKGBUILD
143-
mygit commit -m "Bump to $PKG_VERSION"
144-
mygit push origin master
75+
run: bash ./ci/push-to-aur.bash

ci/check-last-version.bash

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxo pipefail
4+
5+
# Check if a new release is needed
6+
if ["$OLD_COMMIT_N" == "$NEW_COMMIT_N" ]; then exit 1; else exit 0; fi

ci/create-artifacts.bash

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxo pipefail
4+
5+
cd /home/pcr
6+
7+
# Get sources
8+
./pull.bash
9+
chown -R pcr:pcr emacs
10+
11+
# Create artifacts
12+
su pcr -c "makepkg"
13+
14+
# Unpack artifacts
15+
mkdir out
16+
tar xf emacs-1-1-x86_64.pkg.tar.zst -C out
17+
rm emacs-1-1-x86_64.pkg.tar.zst
18+
rm out/.BUILDINFO out/.MTREE out/.PKGINFO
19+
tar czf "$PKG_VERSION".tar.gz -C out .
20+
21+
# Get release body
22+
delta=$(echo "$NEW_COMMIT_N - $OLD_COMMIT_N" | bc)
23+
echo -en "# Commits since last release\n\n" > body.md
24+
echo -en "Check [upstream](https://github.com/flatwhatson/emacs/commits) for the full history.\n\n" >> body.md
25+
26+
# Get the list of commits since last release
27+
curl -s "$UPSTREAM_GH"/commits?per_page="$delta" | \
28+
# Parse and retain only the commit message + its url
29+
jq -r '.[] | (.commit.message | capture("(?<id>.+)\n").id) + " [commit](" + .html_url + ")"' | \
30+
# Remove "Merge" commits
31+
sed '/^Merge/,+1 d' | \
32+
# Remove any special char at the beginning of the message
33+
sed 's/^[^[:alnum:]]*//' | \
34+
# Prepend "- " to the message
35+
sed -r 's/(.*)/- \1/' >> body.md

ci/patch-glibc.bash

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxo pipefail
4+
5+
# Work-around the issue with glibc 2.33 on old Docker engines
6+
# Extract files directly as pacman is also affected by the issue
7+
patched_glibc=glibc-linux4-2.33-4-x86_64.pkg.tar.zst
8+
curl -LO https://repo.archlinuxcn.org/x86_64/$patched_glibc
9+
bsdtar -C / -xvf $patched_glibc

ci/push-to-aur.bash

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxo pipefail
4+
5+
cd /home/pcr
6+
7+
# Checksum artifacts
8+
sum=$(sha512sum "$PKG_VERSION".tar.gz | sed -r 's/(.*)\s\s.*/\1/')
9+
10+
# Setup SSH
11+
mkdir .ssh
12+
echo "$PUB_KEY" | tr -d '\r' > .ssh/id_aur.pub
13+
echo "$PRIV_KEY" | base64 --decode > .ssh/id_aur
14+
chmod 600 .ssh/id_aur
15+
echo -en 'Host aur.archlinux.org\n IdentityFile /home/pcr/.ssh/id_aur\n User aur\n' > .ssh/config
16+
ssh-keyscan aur.archlinux.org > .ssh/known_hosts
17+
ssh-keyscan 95.216.144.15 >> .ssh/known_hosts
18+
19+
# Setup git
20+
alias mygit="git -c user.name=Méril\ Pilon -c user.email=me@mpsq.org"
21+
mygit clone ssh://aur.archlinux.org/emacs-gcc-wayland-devel-bin.git
22+
cd emacs-gcc-wayland-devel-bin
23+
24+
# Amend package, set pkgver, sha512 sum and pkgrel + fix permissions
25+
sed -i -r -e 's~pkgver=.*~pkgver='$PKG_VERSION'~' PKGBUILD
26+
sed -i -r -e 's~sha512sums=.*~sha512sums=\("'"$sum"'"\)~' PKGBUILD
27+
sed -i -r -e 's/pkgrel=.*/pkgrel=1/' PKGBUILD
28+
rm .SRCINFO
29+
su pcr -c "makepkg --printsrcinfo > .SRCINFO"
30+
31+
# Push changes
32+
mygit add .SRCINFO PKGBUILD
33+
mygit commit -m "Bump to $PKG_VERSION"
34+
mygit push origin master

ci/set-env-vars.bash

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxo pipefail
4+
5+
VER=$(curl -s https://raw.githubusercontent.com/flatwhatson/emacs/pgtk-nativecomp/configure.ac | grep AC_INIT | sed -e 's/^.\+\ \([0-9]\+\.[0-9]\+\.[0-9]\+\?\).\+$/\1/')
6+
VER+="."
7+
VER+="$NEW_COMMIT_N"
8+
9+
export VER="${VER}"
10+
11+
echo "::set-output name=ver::${VER}"

0 commit comments

Comments
 (0)