1- name : Check if ISO can be built
1+ name : Build ISO
22
33on :
4- push :
5- branches : [ "main" ]
64 pull_request :
7- branches : [ "main" ]
5+ branches :
6+ - main
87 workflow_dispatch :
98 schedule :
10- # Run the workflow every day at midnight
11- - cron : 0 0 * * *
9+ - cron : ' 0 0 * * *' # Run the workflow every day at midnight
1210
1311jobs :
1412 build :
@@ -20,17 +18,86 @@ jobs:
2018
2119 - name : Set up Arch Linux Container
2220 run : |
23- if ! docker run --privileged --name arch-container -d -v ${{ github.workspace }}:/workdir archlinux:latest sleep infinity; then
24- echo "Failed to start Arch Linux container." && exit 1
25- fi
21+ docker run --privileged --name arch-container -d -v ${{ github.workspace }}:/workdir archlinux:latest sleep infinity
2622
27- - name : Update and Build ISO in Arch Container
23+ - name : Build ISO in Arch Container
2824 run : |
29- if ! docker exec arch-container bash -c "
25+ set -e
26+ docker exec arch-container bash -c "
3027 pacman -Syu --noconfirm &&
3128 pacman -S --noconfirm git archiso grub &&
3229 cd /workdir &&
3330 mkarchiso -v -w workdir/ -o out/ .
34- "; then
35- echo "Failed to build ISO." && exit 1
36- fi
31+ "
32+
33+ - name : Rename ISO to Arch.iso
34+ run : |
35+ set -e
36+ docker exec arch-container bash -c "
37+ iso_file=\$(ls /workdir/out/*.iso 2>/dev/null | head -n 1) &&
38+ [ -n \"\$iso_file\" ] && mv \$iso_file /workdir/out/Arch.iso || echo 'No ISO file found.'
39+ "
40+
41+ - name : List ISO files
42+ run : |
43+ docker exec arch-container bash -c "ls -l /workdir/out/" || echo 'Failed to list files.'
44+
45+ - name : Copy ISO to Host
46+ run : |
47+ docker cp arch-container:/workdir/out/Arch.iso ${{ github.workspace }}/ || echo 'Failed to copy ISO to host.'
48+
49+ - name : Get current date
50+ id : date
51+ run : echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
52+
53+ # Create a release on GitHub using GITHUB_TOKEN
54+ - name : Create GitHub Release
55+ id : create_release # Adding an ID to reference the release step
56+ 57+ env :
58+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
59+ with :
60+ tag_name : v${{ github.run_id }}-release
61+ release_name : " Arch Linux Release"
62+ body : |
63+ This release contains the Arch Linux ISO built on ${{ steps.date.outputs.date }}.
64+ draft : false
65+ prerelease : false
66+
67+ # Upload the ISO to the GitHub release with a specific, predictable name
68+ - name : Upload ISO to GitHub Release
69+ uses : actions/upload-release-asset@v1
70+ env :
71+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
72+ with :
73+ upload_url : ${{ steps.create_release.outputs.upload_url }}
74+ asset_path : ${{ github.workspace }}/Arch.iso
75+ asset_name : Arch.iso
76+ asset_content_type : application/octet-stream
77+
78+ # Delete the release after uploading the asset
79+ - name : Delete GitHub Release
80+ env :
81+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
82+ RELEASE_ID : ${{ steps.create_release.outputs.release_id }}
83+ run : |
84+ curl -X DELETE \
85+ -H "Authorization: token $GITHUB_TOKEN" \
86+ -H "Accept: application/vnd.github.v3+json" \
87+ https://api.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID
88+
89+ # Delete the tag associated with the release
90+ - name : Delete Git Tag
91+ env :
92+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
93+ TAG_NAME : v${{ github.run_id }}-release
94+ run : |
95+ curl -X DELETE \
96+ -H "Authorization: token $GITHUB_TOKEN" \
97+ -H "Accept: application/vnd.github.v3+json" \
98+ https://api.github.com/repos/${{ github.repository }}/git/refs/tags/$TAG_NAME
99+
100+ - name : Clean Up
101+ run : |
102+ docker stop arch-container || echo 'Failed to stop the container.'
103+ docker rm arch-container || echo 'Failed to remove the container.'
0 commit comments