Skip to content

Commit

Permalink
fix: upload better
Browse files Browse the repository at this point in the history
  • Loading branch information
Alxandr committed Mar 20, 2024
1 parent dab0237 commit 153cd28
Show file tree
Hide file tree
Showing 5 changed files with 217 additions and 12 deletions.
45 changes: 45 additions & 0 deletions .github/scripts/upload-packages-to-release.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import * as c from "std/fmt/colors.ts";
import { expandGlob } from "std/fs/mod.ts";
import { Octokit } from "octokit";

const ghToken = Deno.env.get("GITHUB_TOKEN");
const filesGlob = Deno.env.get("FILES_GLOB");
const releaseId = Deno.env.get("RELEASE_ID");

if (!ghToken || !filesGlob || !releaseId) {
console.error("Missing required environment variables");
Deno.exit(1);
}

const github = new Octokit({
auth: ghToken,
});

const release = await github.rest.repos.getRelease({
release_id: Number.parseInt(releaseId, 10),
owner: "Altinn",
repo: "altinn-authorization-utils",
});

console.log(`Uploading files to release ${c.cyan(release.data.tag_name)}`);

for await (const file of expandGlob(filesGlob)) {
const name = file.name;
const path = file.path;

console.log(`Uploading ${c.yellow(name)}`);
const fs = await Deno.open(path, { read: true });

try {
await github.rest.repos.uploadReleaseAsset({
url: release.data.upload_url,
name,
data: fs as any,
release_id: Number.parseInt(releaseId, 10),
owner: "Altinn",
repo: "altinn-authorization-utils",
});
} finally {
fs.close();
}
}
28 changes: 17 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
config-file: release-please-config.json
manifest-file: .release-please-manifest.json

- name: Log release output
env:
RELEASE_OUTPUT: ${{ toJSON(steps.release.outputs) }}
run: 'echo "Release output: $RELEASE_OUTPUT"'

outputs:
release_created: ${{ steps.release.outputs.releases_created }}
paths_released: ${{ steps.release.outputs.paths_released }}
Expand All @@ -39,11 +39,11 @@ jobs:
if: needs.release-please.outputs.release_created == 'true'
needs:
- release-please

strategy:
matrix:
path: ${{fromJson(needs.release-please.outputs.paths_released)}}

steps:
- uses: actions/checkout@v4
- name: Setup .NET
Expand All @@ -55,7 +55,7 @@ jobs:
- name: Build
working-directory: ${{ matrix.path }}
run: dotnet build -c Release

- name: Test
working-directory: ${{ matrix.path }}
run: dotnet test -c Release --no-build
Expand All @@ -72,9 +72,15 @@ jobs:
if-no-files-found: error

- name: Upload packages to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: artifacts/**/*.nupkg
tag: ${{ fromJSON(needs.release-please.outputs.full)[format('{0}--tag_name', matrix.path)] }}
file_glob: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FILES_GLOB: artifacts/**/*.nupkg
RELEASE_ID: ${{ fromJSON(needs.release-please.outputs.full)[format('{0}--id', matrix.path)] }}
run: deno run -A ./.github/scripts/upload-packages-to-release.mts
# - name: Upload packages to release
# uses: svenstaro/upload-release-action@v2
# with:
# repo_token: ${{ secrets.GITHUB_TOKEN }}
# file: artifacts/**/*.nupkg
# tag: ${{ fromJSON(needs.release-please.outputs.full)[format('{0}--tag_name', matrix.path)] }}
# file_glob: true
25 changes: 25 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"imports": {
"std/": "https://deno.land/[email protected]/",
"octokit": "https://esm.sh/v135/[email protected]"
},
"tasks": {
"esm:add": "deno run -A https://esm.sh/v135 add",
"esm:update": "deno run -A https://esm.sh/v135 update",
"esm:remove": "deno run -A https://esm.sh/v135 remove"
},
"scopes": {
"https://esm.sh/v135/": {
"@octokit/app": "https://esm.sh/v135/@octokit/[email protected]",
"@octokit/core": "https://esm.sh/v135/@octokit/[email protected]",
"@octokit/oauth-app": "https://esm.sh/v135/@octokit/[email protected]",
"@octokit/plugin-paginate-graphql": "https://esm.sh/v135/@octokit/[email protected]",
"@octokit/plugin-paginate-rest": "https://esm.sh/v135/@octokit/[email protected]",
"@octokit/plugin-rest-endpoint-methods": "https://esm.sh/v135/@octokit/[email protected]",
"@octokit/plugin-retry": "https://esm.sh/v135/@octokit/[email protected]",
"@octokit/plugin-throttling": "https://esm.sh/v135/@octokit/[email protected]",
"@octokit/request-error": "https://esm.sh/v135/@octokit/[email protected]",
"@octokit/types": "https://esm.sh/v135/@octokit/[email protected]"
}
}
}
Loading

0 comments on commit 153cd28

Please sign in to comment.