Skip to content

Commit

Permalink
chore(cd): attempt on upload artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
EstebanBorai committed Jun 6, 2024
1 parent a592854 commit 9674efa
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 11 deletions.
61 changes: 50 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ jobs:
name: "Runs cargo publish --dry-run"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Checkout code
uses: actions/checkout@v4

- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable

- name: publish crate
run: cargo publish --dry-run
Expand All @@ -38,14 +37,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
uses: dtolnay/rust-toolchain@stable

- name: Install `cargo-edit`
run: cargo install cargo-edit
Expand Down Expand Up @@ -84,3 +79,47 @@ jobs:
tag_name: "v${{ env.CRATE_VERSION }}",
generate_release_notes: true
});
artifacts:
needs: release
name: Upload Artifacts ${{ matrix.os }}
runs-on: ${{ matrix.os }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
strategy:
matrix:
name:
- linux
- macos
- windows
include:
- name: linux
os: ubuntu-latest
artifact_name: wait-on
asset_name: wait-on

- name: macos
os: macos-latest
artifact_name: wait-on
asset_name: wait-on

- name: windows
os: windows-latest
artifact_name: wait-on
asset_name: wait-on.exe
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Rust
uses: dtolnay/rust-toolchain@stable

- name: Upload release artifacts
uses: actions/github-script@v5
env:
ARTIFACT_NAME: ${{ matrix.artifact_name }}
ASSET_NAME: ${{ matrix.asset_name }}
with:
script: |
const script = require('./.github/workflows/scripts/upload-artifacts.js');
console.log(script({ github, context }));
32 changes: 32 additions & 0 deletions .github/workflows/scripts/upload-artifacts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const fs = require('fs').promises;
const { ARTIFACT_NAME, ASSET_NAME, GITHUB_REF } = process.env;

module.exports = async ({ github, context }) => {
const {
repo: {
owner,
repo,
},
} = context;
const tag = GITHUB_REF.replace('refs/tags/', '');

const release = await github.repos.getReleaseByTag({
owner,
repo,
tag,
});

const files = await fs.readdir('./target/release');

for (let file of files) {
if (file === ASSET_NAME) {
await github.repos.uploadReleaseAsset({
owner,
repo,
release_id: release.data.id,
name: ARTIFACT_NAME,
data: await fs.readFile(file),
});
}
}
}

0 comments on commit 9674efa

Please sign in to comment.