-
Notifications
You must be signed in to change notification settings - Fork 0
93 lines (82 loc) · 3.2 KB
/
update_version.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
name: Update version
on:
workflow_dispatch:
schedule:
- cron: '30 */4 * * *'
jobs:
update-version:
name: Automatically get latest PHPArkitect version and commit
runs-on: ubuntu-latest
steps:
- name: "Checkout code"
uses: actions/checkout@v3
with:
ref: main
fetch-depth: '0'
- name: "Update Dockerfile and action.yml"
id: fetch_version
run: |
latest=$(curl -s https://packagist.org/packages/phparkitect/phparkitect.json|jq '[.package.versions[]|select(.version|test("^\\d+\\.\\d+\\.\\d+$"))|.version]|max_by(.|[splits("[.]")]|map(tonumber))')
latest=$(echo $latest | tr -d '"')
echo "Latest PHPArkitect version is $latest"
echo ::set-output name=latest::$latest
sed -i -re "s/ENV VERSION=.*/ENV VERSION=$latest/" Dockerfile
cat Dockerfile
sed -i -re "s/arkitect-github-actions:[0-9.]+/arkitect-github-actions:$latest/" action.yml
cat action.yml
- name: "Commit changes"
uses: stefanzweifel/git-auto-commit-action@v4
id: commit
with:
commit_author: "Alessandro Minoccheri <[email protected]>"
commit_message: "Enhancement: Upgrade to PHPArkitect ${{ steps.fetch_version.outputs.latest }}"
commit_user_email: "[email protected]"
commit_user_name: "Alessandro Minoccheri"
- name: "Tag version ${{ steps.fetch_version.outputs.latest }}"
uses: "anothrNick/[email protected]"
if: steps.commit.outputs.changes_detected == 'true'
id: tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CUSTOM_TAG: ${{ steps.fetch_version.outputs.latest }}
RELEASE_BRANCHES: main
- name: "Create release ${{ steps.fetch_version.outputs.latest }}"
uses: actions/create-release@v1
if: steps.commit.outputs.changes_detected == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.tag.outputs.new_tag }}
release_name: ${{ steps.tag.outputs.new_tag }}
commitish: main
body: "Upgrade PHPArkitect to ${{ steps.tag.outputs.new_tag }}"
publish_docker_images:
needs: [update-version]
runs-on: ubuntu-20.04
if: github.ref == 'refs/heads/main' || github.event_name == 'release'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Docker meta
id: meta
uses: crazy-max/ghaction-docker-meta@v2
with:
images: phparkitect/arkitect-github-actions
tags: |
type=raw,value=latest,enable=${{ endsWith(github.ref, 'main') }}
type=ref,event=tag
flavor: |
latest=false
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}