Skip to content

Commit

Permalink
Add the ability to specify the working directory
Browse files Browse the repository at this point in the history
  • Loading branch information
WyriHaximus committed Jan 28, 2024
1 parent 5e8388f commit 62e3fb7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,42 @@ on:
- 'master'
pull_request:
jobs:
get-previous-tag-with-working-directory:
name: Test Get Previous Tag on ${{ matrix.os }} with Working Directory
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Required due to the way Git works, without it this action won't be able to find any or the correct tags
- uses: actions/checkout@v4
with:
repository: github.com/WyriHaximus/php-fake-php-version
ref: master
path: tmp/some/other/path
fetch-depth: 0 # Required due to the way Git works, without it this action won't be able to find any or the correct tags
- name: 'Get Previous tag'
id: previoustag
uses: ./
with:
workingDirecvtory: tmp/some/other/path
- run: |
echo "Tag: ${{ steps.previoustag.outputs.tag }}"
echo "Timestamp: ${{ steps.previoustag.outputs.timestamp }}"
test -n "${{ steps.previoustag.outputs.tag }}"
test -n "${{ steps.previoustag.outputs.timestamp }}"
- name: Assert we got the tag
uses: therussiankid92/gat@v1
with:
assertion: should.equal
expected: v1
actual: ${{ steps.previoustag.outputs.tag }}
get-previous-tag:
name: Test Get Previous Tag on ${{ matrix.os }}
strategy:
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ inputs:
prefix:
description: 'Prefix to query the tag by'
required: false
workingDirectory:
description: The directory to run this workflow in
default: ""
required: false
outputs:
tag:
description: 'Latest tag'
Expand Down
5 changes: 3 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const { exec } = require('child_process');
const fs = require('fs');
const tagPrefix = `${process.env.INPUT_PREFIX || ''}*`;
const workingDirectory = process.env.INPUT_WORKINGDIRECTORY || null;

exec(`git for-each-ref --sort=-creatordate --count 1 --format="%(refname:short)" "refs/tags/${tagPrefix}"`, (err, tag, stderr) => {
exec(`git for-each-ref --sort=-creatordate --count 1 --format="%(refname:short)" "refs/tags/${tagPrefix}"`, {cwd: workingDirectory}, (err, tag, stderr) => {
tag = tag.trim();

if (err) {
Expand All @@ -19,7 +20,7 @@ exec(`git for-each-ref --sort=-creatordate --count 1 --format="%(refname:short)"
process.exit(0);
}

exec(`git log -1 --format=%at ${tag}`, (err, timestamp, stderr) => {
exec(`git log -1 --format=%at ${tag}`, {cwd: workingDirectory}, (err, timestamp, stderr) => {
if (err) {
console.log('\x1b[33m%s\x1b[0m', 'Could not find any timestamp because: ');
console.log('\x1b[31m%s\x1b[0m', stderr);
Expand Down

0 comments on commit 62e3fb7

Please sign in to comment.