Skip to content

Commit

Permalink
Replaced deprecated Github Action for uploading release assets (#54)
Browse files Browse the repository at this point in the history
1. Fixes asset uploading by replacing deprecated GitHub Action
`actions/upload-release-asset@v1` with `softprops/action-gh-release@v2`,
via `.github/workflows/nexe-ci.yml`.
  • Loading branch information
code-ape committed Mar 5, 2025
1 parent b478ab0 commit 36b77ff
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 25 deletions.
50 changes: 27 additions & 23 deletions .github/workflows/nexe-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,49 +45,53 @@ jobs:
python-version: '3.10'

- name: Run nexe CD build
id: run_cd
run: |
echo "github.ref = ${{ github.ref }}"
./bin/run_cd
env:
NODE_VERSION: ${{ matrix.node_version }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CREATE_RELEASE: "${{ github.ref == 'refs/heads/main' && 'true' || 'false' }}"

- name: Get nexe build info
id: build_info
run: |
echo "github.ref = ${{ github.ref }}"
echo "Creating dist/ dir if it doesn't exist ..."
mkdir -p dist/
echo "Getting release_file and release_id ..."
echo "Getting release_file, release_tag, and release_id ..."
release_file="$(ls dist/ | head -n 1)"
release_name="$(cat ./NEXE_ASSET_NAME)"
release_id="$(cat ./RELEASE_ID)"
asset_name="$(cat ./NEXE_ASSET_NAME)"
release_tag="$(cat ./RELEASE_TAG || true)"
release_id="$(cat ./RELEASE_ID || true)"
echo "Getting build_occurred ..."
if [ "$release_file" != "" ]; then
build_occurred="true"
else
build_occurred="false"
fi
echo "Moving build artifact to asset name ($release_file -> ./$asset_name) ..."
mv "dist/$release_file" "./$asset_name"
echo "release_tag=$release_tag"
echo "release_id=$release_id"
echo "release_file=$release_file"
echo "release_name=$release_name"
echo "asset_name=$asset_name"
echo "build_occurred=$build_occurred"
echo "release_id=$release_id" >> $GITHUB_OUTPUT
echo "release_file=$release_file" >> $GITHUB_OUTPUT
echo "release_name=$release_name" >> $GITHUB_OUTPUT
echo "release_tag=$release_tag" >> $GITHUB_OUTPUT
echo "asset_name=$asset_name" >> $GITHUB_OUTPUT
echo "build_occurred=$build_occurred" >> $GITHUB_OUTPUT
env:
NODE_VERSION: ${{ matrix.node_version }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CREATE_RELEASE: "${{ github.ref == 'refs/heads/main' && 'true' || 'false' }}"
# Upload artifact & asset
- name: Upload build artifact
uses: actions/upload-artifact@v4
if: steps.run_cd.outputs.build_occurred == 'true'
if: steps.build_info.outputs.build_occurred == 'true'
with:
name: ${{ steps.run_cd.outputs.release_name }}
path: dist/${{ steps.run_cd.outputs.release_file }}
name: ${{ steps.build_info.outputs.asset_name }}
path: ./${{ steps.build_info.outputs.asset_name }}
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
if: steps.run_cd.outputs.build_occurred == 'true' && github.ref == 'refs/heads/main'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: softprops/action-gh-release@v2
if: steps.build_info.outputs.build_occurred == 'true' && github.ref == 'refs/heads/main'
with:
upload_url: https://uploads.github.com/repos/urbdyn/nexe_builds/releases/${{ steps.run_cd.outputs.release_id }}/assets{?name,label}
asset_name: ${{ steps.run_cd.outputs.release_name }}
asset_path: dist/${{ steps.run_cd.outputs.release_file }}
asset_content_type: application/octet-stream
fail_on_unmatched_files: true
tag_name: ${{ steps.build_info.outputs.release_tag }}
files: ./${{ steps.build_info.outputs.asset_name }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# From CI/CD process
/RELEASE_TAG
/RELEASE_ID
/NEXE_ASSET_NAME
/index.js
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ Enjoy 🚀
2. Environmental Variables:
1. `GITHUB_TOKEN`: Token to use for querying github and creating release if needed. [required]
3. Files created:
1. `$repo_base/NEXE_ASSET_NAME`: Name of the nexe asset to create. (integer)
2. `$repo_base/RELEASE_ID`: The ID of the Github Release to publish assets to. (`${targetOs}-${targetArch}-${targetNodeVersion}`)
1. `$repo_base/NEXE_ASSET_NAME`: Name of the nexe asset to create. (`${targetOs}-${targetArch}-${targetNodeVersion}`)
2. `$repo_base/RELEASE_TAG`: The tag of the Github Release to publish assets to. (sem-ver string)
3. `$repo_base/RELEASE_ID`: The ID of the Github Release to publish assets to. (integer)
4. Exit codes:
1. `0`: Build not needed
2. `1`: Error occurred
Expand Down
3 changes: 3 additions & 0 deletions bin/check_asset
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ async function main() {
console.log(`Writing existing release ID (${existingRelease.id}) to file: RELEASE_ID`);
const releaseIdPath = path.join(__dirname, '../RELEASE_ID');
fs.writeFileSync(releaseIdPath, `${existingRelease.id}`);
console.log(`Writing existing release tag (${existingRelease.tag_name}) to file: RELEASE_TAG`);
const releaseTagPath = path.join(__dirname, '../RELEASE_TAG');
fs.writeFileSync(releaseTagPath, `${existingRelease.tag_name}`);
const releaseAssetsNames = existingRelease.assets.map((x) => x.name);
console.log(`Existing assets for release ${packageData.version}:`, releaseAssetsNames);
const existingAsset = releaseAssetsNames.includes(nexeAssetName);
Expand Down

0 comments on commit 36b77ff

Please sign in to comment.