Last active
March 25, 2024 14:38
-
-
Save bbbradsmith/b3ee60bdbacdb879719fe54131e9dd1b to your computer and use it in GitHub Desktop.
Github Actions example workflow for building a batch file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Action name and trigger conditions. | |
# workflow_dispatch means: this can be manually re-triggered, and not just by push/pr. | |
name: Batch File Continuous Integration | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
workflow_dispatch: | |
# Can have multiple jobs, but this example is just one build job. | |
jobs: | |
build: | |
runs-on: windows-latest | |
steps: | |
# 1. Check out repository to current directory. | |
- name: Checkout Files | |
uses: actions/checkout@v3 | |
# 2. Use cmd shell to build the batch file, parameters may be passed to it, | |
# and if it exits with ERRORLEVEL != 0 it will halt. | |
# The text output from the batch file will be in the log. | |
- name: Build ROM | |
shell: cmd | |
run: build_rom.bat param | |
# 3. Set the build machine time zone to have consistent artifact timestamps. | |
- name: Select Time Zone | |
uses: szenius/[email protected] | |
with: | |
timezoneWindows: "Eastern Standard Time" | |
# 4. Use powershell to gather files for the artifact, and generate a filename. | |
# Note that the output of commands is not shown in the log unless it causes an error. | |
# The artifact copying could be done by the batch file, | |
# but I liked having an example of how to do it in powershell. | |
# If a file is optional, -ErrorAction Ignore can be used to keep going if it doesn't exist. | |
# 'git log -1' lists information about the last commit. | |
# It is used to get the 7-letter short SHA hash (%h), | |
# and a formatted date for the commit's authoring (%ad). | |
# The local time zone is selected (--date=format-local) | |
# rather than the comitter's time zone (--date=format). | |
# By appending "NAME=VALUE" to the special file $env:GITHUB_ENV, | |
# it sets an environment variable that we can use in later steps. | |
# This is apparently the best way to get a short SHA, | |
# because actions only have a long SHA built in, | |
# and YAML is not very good at string manipulation. | |
- name: Prepare Artifact | |
shell: pwsh | |
run: | | |
mkdir artifact | |
cp test3.txt artifact | |
cp build/bt.txt artifact | |
cp missing.txt artifact -ErrorAction Ignore | |
cp missing2.txt artifact | |
echo "BUILD_TAG=$(git log -1 --format="%h--%ad" --date=format-local:"%Y-%m-%d-%H%M%S")" >> $env:GITHUB_ENV | |
# 5. Attach the artifact to the job. | |
# Here we used the environment variable we created in the previous step. | |
- name: ROM Artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: name-${{ env.BUILD_TAG }} | |
path: artifact/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment