Github Actionsで動的に変数を設定するには、下記のように$env:GITHUB_ENVに追加書き込みすることで実現できます。
【Windowsの場合】
name: Rust
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Get Environment
run: |
echo 'VERSION=1.0.0' >> $GITHUB_ENV
echo 'NAME=1.0.0' >> $GITHUB_ENV
- name: Display Environment
run: |
echo $env:VERSION
echo $env:NAME
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.VERSION }}
release_name: ${{ env.VERSION }}
draft: false
prerelease: false
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./target/release/${{ env.NAME }}.exe
asset_name: ${{ env.NAME }}.exe
asset_content_type: application/octet-stream
【Linuxの場合】
name: Rust
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Get Environment
run: |
echo 'VERSION=1.0.0' >> $GITHUB_ENV
echo 'NAME=hello' >> $GITHUB_ENV
- name: Display Environment
run: |
echo ${{ env.VERSION }}
echo ${{ env.NAME }}