Skip to content

Commit

Permalink
Merge pull request #8 from dargmuesli/example_scheduled-releases
Browse files Browse the repository at this point in the history
docs(examples): "add scheduled release" example
  • Loading branch information
WyriHaximus committed Oct 11, 2020
2 parents 24cf9bd + d9b6753 commit db2c371
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 6 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ Github Action that gets the latest tag from git

## Output

This action has only one output, namely, `tag` for the latest tag this action finds. When no tag is found or another
error occurs it exits with code `1`.
This action has only one output, namely, `tag` for the latest tag this action finds.
When no tag is found or another error occurs it exits with code `1`.

## Example

The following example works together with the [`WyriHaximus/github-action-next-semvers`](https://github.com/marketplace/actions/next-semvers)
and [`WyriHaximus/github-action-create-milestone`](https://github.com/marketplace/actions/create-milestone) actions.
Where it provides the previous tag from that action so it can supply a set of versions for the next action, which
creates a new milestone. (This snippet has been taken from the automatic code generation of [`wyrihaximus/fake-php-version`](https://github.com/wyrihaximus/php-fake-php-version/).)
Find more examples in the [examples directory](./examples/).

The following example works together with the [`WyriHaximus/github-action-next-semvers`](https://github.com/marketplace/actions/next-semvers) and [`WyriHaximus/github-action-create-milestone`](https://github.com/marketplace/actions/create-milestone) actions.
Where it provides the previous tag from that action so it can supply a set of versions for the next action, which creates a new milestone.
(This snippet has been taken from the automatic code generation of [`wyrihaximus/fake-php-version`](https://github.com/wyrihaximus/php-fake-php-version/).)

```yaml
name: Generate
Expand Down
65 changes: 65 additions & 0 deletions examples/scheduled-release.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Scheduled Release

This example demonstrates how a release schedule can be limited to only occur if there have been no other releases in the past week.

```yaml
name: Scheduled Release

on:
schedule:
- cron: '0 0 * * 1' # Every Monday at 00:00 AM UTC on the default branch

jobs:
analyze-tags:
runs-on: ubuntu-latest
outputs:
previous-tag: ${{ steps.previoustag.outputs.tag }}
timestamp-diff: ${{ steps.diff.outputs.timestamp-diff }}
steps:
- uses: actions/checkout@v2.3.3
with:
fetch-depth: 0
#▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼#
- name: Get previous tag
id: previoustag
uses: "WyriHaximus/github-action-get-previous-tag@1.0.0"
#▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲#
- name: Get seconds from previous tag to now
id: diff
shell: bash
env:
TIMESTAMP_TAG: ${{ steps.previoustag.outputs.timestamp }}
run: |
echo "::set-output name=timestamp-diff::$(expr $(printf '%(%s)T') - $TIMESTAMP_TAG)"
schedule-release:
runs-on: ubuntu-latest
needs: analyze-tags
if: needs.analyze-tags.outputs.timestamp-diff > 604800 # 604800 equal one week.
steps:
- uses: actions/checkout@v2.3.3
with:
token: ${{ secrets.GH_TOKEN }}
- name: Get next minor version
id: semvers
uses: "WyriHaximus/github-action-next-semvers@v1.0"
with:
version: ${{ needs.analyze-tags.outputs.previous-tag }}

# Now schedule the release...

# In the example below, a file is changed
# (the scheduled tag is written to an arbitrary property within a package.json file).
# The following commit would then trigger a semantic release through a following workflow
# (https://github.com/semantic-release/semantic-release)

- name: manifest Version
uses: deef0000dragon1/json-edit-action/@v1
env:
KEY: scheduleVersion
VALUE: ${{ steps.semvers.outputs.patch }}
FILE: package.json
- uses: stefanzweifel/git-auto-commit-action@v4.5.1
with:
commit_message: 'fix(release): schedule release'
```

0 comments on commit db2c371

Please sign in to comment.