Skip to content

Commit

Permalink
Create node action project (#80)
Browse files Browse the repository at this point in the history
* Add action project

* Fix typo

* Add missing checkout

* Fix typo

* Use main action to build tag-track
  • Loading branch information
dloez committed Feb 6, 2024
1 parent cc29d91 commit 14909e2
Show file tree
Hide file tree
Showing 15 changed files with 34,275 additions and 219 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build_lint_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ on:
pull_request:
branches:
- main
- 'milestone/*'
- "milestone/*"
workflow_call:
push:
branches:
- 'milestone/*'
- "milestone/*"
defaults:
run:
shell: bash
Expand Down Expand Up @@ -38,7 +38,7 @@ jobs:
if: matrix.os-target.target == 'aarch64-unknown-linux-gnu'
- name: Run Tag Track
id: tag-track
uses: ./
uses: dloez/tag-track@main
with:
github-token: ${{ github.token }}
compile: true
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/test_workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Test workflow
on:
push:
jobs:
call-action:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./
with:
test-input: "test"
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
"editor.tabSize": 2
},

"[github-actions-workflow]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.tabSize": 2
},

"[rust]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "rust-lang.rust-analyzer"
Expand Down
221 changes: 5 additions & 216 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,220 +2,9 @@ name: Tag Track
description: Calculate semantic version bump based on conventional commits.
author: David Lopez <davidlopez.hellin@outlook.com>
inputs:
create-tag:
description: Create a new tag with bumped version. Defaults to `false`.
default: false
push-tag:
description: Push the new tag to the repository if `create-tag` is used. Defaults to `false`.
default: false
github-repo:
description: Github repository in the format owner/repo. Defaults to the repository that triggers the action.
required: false
github-api-url:
description: Github API URL. Defaults to the value of the environment variable `GITHUB_API_URL`.
required: false
github-token:
description: Github token to authorize requests to GitHub REST API. Can cause rate limit to be increased.
required: false
commit-sha:
description: Commit SHA from where the version bump will be calculated. Defaults to the commit SHA that triggers the action.
required: false
compile:
description: Instead of downloading the binary, compile it from source. Defaults to `false`.
default: false
use-cache:
description: Save binary in cache to avoid downloading or compiling it every time. Defaults to `false`.
default: false
git-author-name:
description: Name of the author for tags created by Tag Track. Defaults to `github-actions`.
default: github-actions
git-author-email:
description: Email of the author for tags created by Tag Track. Defaults to `github-actions@github.com`.
default: github-actions@github.com
outputs:
tag-created:
description: "`true` if at least a new tag was created"
value: ${{ steps.tag-track-runner.outputs.tag-created }}
new-tags:
description: JSON Array of new tag names created.
value: ${{ steps.tag-track-runner.outputs.new-tags }}
version-bumps:
description: List of version bumps.
value: ${{ steps.tag-track-runner.outputs.version-bumps }}
skipped-commits:
description: List of commits that were skipped because they don't match the commit pattern.
value: ${{ steps.tag-track-runner.outputs.skipped-commits }}
error:
description: Error message if something went wrong.
value: ${{ steps.tag-track-runner.outputs.error }}
test-input:
description: Test input.
required: true
runs:
using: composite
steps:
- name: Save and set git author information
id: git-author
shell: bash
if: ${{ inputs.create-tag == 'true' }}
run: |
echo "git-author-name=$(git config user.name)" >> $GITHUB_OUTPUT
echo "git-author-email=$(git config user.email)" >> $GITHUB_OUTPUT
git config user.name "${{ inputs.git-author-name }}"
git config user.email "${{ inputs.git-author-email }}"
echo "::debug::Git author name: ${{ inputs.git-author-name }}"
echo "::debug::Git author email: ${{ inputs.git-author-email }}"
- name: Checkout Tag Track
if: ${{ inputs.compile == 'true' }}
uses: actions/checkout@v4
with:
repository: dloez/tag-track
ref: ${{ env.ACTION_REF }}
path: tag-track-repo
env:
ACTION_REF: ${{ github.action_ref }}
- name: Generate compile cache key
if: ${{ inputs.compile == 'true' && inputs.use-cache == 'true' }}
id: gen-compile-cache-key
shell: bash
run: |
hash_string=${{ hashFiles('tag-track-repo/**/*.rs', 'tag-track-repo/.cargo/**', 'tag-track-repo/Cargo*') }}
echo "compile-cache-key=tag-track_compile_${RUNNER_OS}_${RUNNER_ARCH}_${hash_string:0:8}" >> $GITHUB_OUTPUT
- name: Restore compile cache
if: ${{ inputs.compile == 'true' && inputs.use-cache == 'true' }}
id: compile-cache-restore
uses: actions/cache/restore@v3
with:
path: tag-track-bin
key: ${{ steps.gen-compile-cache-key.outputs.compile-cache-key }}
- name: Setup rust
if: ${{ inputs.compile == 'true' && steps.compile-cache-restore.outputs.cache-hit != 'true' }}
uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.71.0
- name: Compile Tag Track
if: ${{ inputs.compile == 'true' && steps.compile-cache-restore.outputs.cache-hit != 'true' }}
shell: bash
run: |
cd tag-track-repo
cargo build --release
mkdir -p ../tag-track-bin
mv target/release/tag-track ../tag-track-bin/tag-track
rm -rf tag-track-repo
- name: Save cache
if: ${{ inputs.compile == 'true' && inputs.use-cache == 'true' && steps.compile-cache-restore.outputs.cache-hit != 'true' }}
uses: actions/cache/save@v3
with:
path: tag-track-bin
key: ${{ steps.gen-compile-cache-key.outputs.compile-cache-key }}
- name: Generate download cache key
if: ${{ inputs.compile == 'false' && inputs.use-cache == 'true' }}
id: gen-download-cache-key
shell: bash
run: echo "download-cache-key=tag-track_download_${RUNNER_OS}_${RUNNER_ARCH}_${ACTION_REF}" >> $GITHUB_OUTPUT
env:
ACTION_REF: ${{ github.action_ref }}
- name: Restore download cache
if: ${{ inputs.compile == 'false' && inputs.use-cache == 'true' }}
id: download-cache-restore
uses: actions/cache/restore@v3
with:
path: tag-track-bin
key: ${{ steps.gen-download-cache-key.outputs.download-cache-key }}
- name: Download Tag Track
if: ${{ runner.os != 'windows' && inputs.compile == 'false' && steps.download-cache-restore.outputs.cache-hit != 'true' }}
shell: bash
run: |
curl "https://raw.githubusercontent.com/${GITHUB_REPOSITORY}/${ACTION_REF}/install.sh" | sh -s ${ACTION_REF}
mkdir -p tag-track-bin
mv $HOME/.tag-track/bin/tag-track ./tag-track-bin/tag-track
env:
ACTION_REF: ${{ github.action_ref }}
- name: Download Tag Track - windows
if: ${{ runner.os == 'windows' && inputs.compile == 'false' && steps.download-cache-restore.outputs.cache-hit != 'true' }}
shell: powershell
run: |
$null = Invoke-WebRequest -Uri "https://raw.githubusercontent.com/$env:GITHUB_REPOSITORY/${{ env.ACTION_REF }}/install.ps1" -OutFile "install.ps1"; powershell -ExecutionPolicy Bypass -File "./install.ps1" "${{ env.ACTION_REF }}"; Remove-Item "install.ps1" -Force
New-Item -ItemType Directory -Force -Path tag-track-bin
mv $env:localappdata/tag-track/bin/tag-track.exe ./tag-track-bin/tag-track
- name: Save cache
if: ${{ inputs.compile == 'false' && inputs.use-cache == 'true' && steps.download-cache-restore.outputs.cache-hit != 'true' }}
uses: actions/cache/save@v3
with:
path: tag-track-bin
key: ${{ steps.gen-download-cache-key.outputs.download-cache-key }}
- name: Calculate version bump
id: tag-track-runner
shell: bash
run: |
command="./tag-track-bin/tag-track --output-format json"
if [ -n "${{ inputs.github-token }}" ]; then
command="$command --github-token ${{ inputs.github-token }}"
fi
if [ -n "${{ inputs.github-repo }}" ]; then
command="$command --github-repo ${{ inputs.github-repo }}"
else
command="$command --github-repo $GITHUB_REPOSITORY"
fi
if [ -n "${{ inputs.github-api-url }}" ]; then
command="$command --github-api-url ${{ inputs.github-api-url }}"
else
command="$command --github-api-url $GITHUB_API_URL"
fi
if [ -n "${{ inputs.commit-sha }}" ]; then
command="$command --commit-sha ${{ inputs.commit-sha }}"
fi
if [ "${{ inputs.create-tag }}" == "true" ]; then
command="$command --create-tag"
fi
set +e
echo "::debug::Running command $command"
tag_track_output="$(eval $command 2>&1)"
echo "exit-code=$?" >> $GITHUB_OUTPUT
echo "raw-output<<EOF" >> $GITHUB_OUTPUT
echo "$tag_track_output" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "tag-created=$(jq -r '.tag_created' <<< $tag_track_output)" >> $GITHUB_OUTPUT
echo "new-tags=$(jq -cr '.new_tags' <<< $tag_track_output )" >> $GITHUB_OUTPUT
echo "version-bumps=$(jq -cr '.version_bumps' <<< $tag_track_output)" >> $GITHUB_OUTPUT
echo "skipped-commits=$(jq -cr '.skipped_commits')" >> $GITHUB_OUTPUT
echo "error=$(jq -r '.error' <<< $tag_track_output)" >> $GITHUB_OUTPUT
- name: Print skipped commits
if: ${{ steps.tag-track-runner.outputs.skipped-commits }}
shell: bash
run: |
for element in $(echo '${{ steps.tag-track-runner.outputs.skipped-commits }}' | jq -r '.[]'); do
echo "::warning::Commit '$element' does not match the commit pattern"
done
- name: Check tag-track error
shell: bash
if: ${{ steps.tag-track-runner.outputs.error || steps.tag-track-runner.outputs.exit-code != 0 }}
run: |
if [ -n "${{ steps.tag-track-runner.outputs.error }}" ]; then
echo "::error::Tag Track error: ${{ steps.tag-track-runner.outputs.error }}"
exit 1
fi
echo "::error::Raw Tag Track output: ${{ steps.tag-track-runner.outputs.raw-output }}"
exit 1
- name: Print Tag Track information
shell: bash
run: |
for element in $(echo '${{ steps.tag-track-runner.outputs.version-bumps }}' | jq -c '.[]'); do
scope=$(echo $element | jq -r '.scope')
old_version=$(echo $element | jq -r '.old_version')
new_version=$(echo $element | jq -r '.new_version')
if [ "$scope" == "" ]; then
echo "::notice::Version bump: $old_version -> $new_version"
else
echo "::notice::Version bump for '$scope' scope: $old_version -> $new_version"
fi
done
- name: Push tag
shell: bash
if: ${{ steps.tag-track-runner.outputs.tag-created == 'true' && inputs.push-tag == 'true' }}
run: |
git push origin --tags
echo "::notice::New tag created and pushed: ${{ steps.tag-track-runner.outputs.new-tags }}"
- name: Reset git author config
shell: bash
if: ${{ inputs.create-tag == 'true' }}
run: |
git config user.name "${{ steps.git-author.outputs.git-author-name }}"
git config user.email "${{ steps.git-author.outputs.git-author-email }}"
using: node20
main: action/dist/index.js
Loading

0 comments on commit 14909e2

Please sign in to comment.