Skip to content

Commit 4db55ac

Browse files
committed
[ci] Add Github token to fetch draft releases
Signed-off-by: Andrei Kvapil <[email protected]>
1 parent bfd20a5 commit 4db55ac

1 file changed

Lines changed: 26 additions & 20 deletions

File tree

‎.github/workflows/pull-requests-release.yaml‎

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,43 +48,49 @@ jobs:
4848
const tag = `v${m[1]}`;
4949
core.setOutput('tag', tag);
5050
51-
- name: Find draft release and download assets
51+
- name: Find draft release and get asset IDs
5252
id: fetch_assets
5353
uses: actions/github-script@v7
5454
with:
55+
github-token: ${{ secrets.GH_PAT }}
5556
script: |
5657
const tag = '${{ steps.get_tag.outputs.tag }}';
5758
const releases = await github.rest.repos.listReleases({
5859
owner: context.repo.owner,
59-
repo: context.repo.repo
60+
repo: context.repo.repo,
61+
per_page: 100
6062
});
6163
const draft = releases.data.find(r => r.tag_name === tag && r.draft);
6264
if (!draft) {
63-
core.setFailed(`❌ Draft release for ${tag} not found`);
65+
core.setFailed(`Draft release '${tag}' not found`);
6466
return;
6567
}
66-
67-
const getAsset = (name) =>
68-
draft.assets.find(asset => asset.name === name)?.browser_download_url;
69-
70-
const installer = getAsset("cozystack-installer.yaml");
71-
const disk = getAsset("nocloud-amd64.raw.xz");
72-
73-
if (!installer || !disk) {
74-
core.setFailed(`❌ Missing required assets in release: ${[!installer && "cozystack-installer.yaml", !disk && "nocloud-amd64.raw.xz"].filter(Boolean).join(', ')}`);
68+
const findAssetId = (name) =>
69+
draft.assets.find(a => a.name === name)?.id;
70+
const installerId = findAssetId("cozystack-installer.yaml");
71+
const diskId = findAssetId("nocloud-amd64.raw.xz");
72+
if (!installerId || !diskId) {
73+
core.setFailed("Missing required assets");
7574
return;
7675
}
77-
78-
core.setOutput("installer_url", installer);
79-
core.setOutput("disk_url", disk);
80-
81-
- name: Download required assets
76+
core.setOutput("installer_id", installerId);
77+
core.setOutput("disk_id", diskId);
78+
79+
- name: Download assets from GitHub API
8280
run: |
8381
mkdir -p _out/assets
84-
curl -sSL -H "Authorization: token $GH_TOKEN" -o _out/assets/cozystack-installer.yaml "${{ steps.fetch_assets.outputs.installer_url }}"
85-
curl -sSL -H "Authorization: token $GH_TOKEN" -o _out/assets/nocloud-amd64.raw.xz "${{ steps.fetch_assets.outputs.disk_url }}"
82+
curl -sSL \
83+
-H "Authorization: token ${GH_PAT}" \
84+
-H "Accept: application/octet-stream" \
85+
-o _out/assets/cozystack-installer.yaml \
86+
"https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/assets/${{ steps.fetch_assets.outputs.installer_id }}"
87+
curl -sSL \
88+
-H "Authorization: token ${GH_PAT}" \
89+
-H "Accept: application/octet-stream" \
90+
-o _out/assets/nocloud-amd64.raw.xz \
91+
"https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/assets/${{ steps.fetch_assets.outputs.disk_id }}"
8692
env:
87-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
93+
GH_PAT: ${{ secrets.GH_PAT }}
8894

8995
- name: Run tests
9096
run: make test

0 commit comments

Comments
 (0)